# Tic Tac Toe in 1kb (uncompressed)

Sep 8th, 2020
1,966
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. assert(term.isColor(), "Color Needed.") local clr,cp,st,sb,p,d,win,board,combos,sprites,a,x,y=term.clear,term.setCursorPos,term.setTextColor,term.setBackgroundColor,print,0,3,"000000000","123456789147258369159357",{"x","o"}
2. st(colors.white)sb(colors.black)clr()
4. local function draw() a=1 for i=1,3 do for j=1,3 do cp(j,i) p(sprites[id(board,a)]or"-") a=a+1 end end end
5. local function cw() for i=1, 2 do for ii=1, 8 do if id(board,id(combos,ii*3-2))==i and id(board,id(combos,ii*3-1))==i and id(board,id(combos,ii*3)) == i then win=i end end end end
6. draw()
7. while win>2 and d<5 do
8.     repeat _,_,x,y=os.pullEvent("mouse_click") until x<4 and y<4 and id(board,(y-1)*3+x)<1
9.     board=board:sub(1,((y-1)*3+x)-1).."1"..board:sub(((y-1)*3+x)+1)cw()
10.     if d~=4 and win>2 then repeat a=math.random(1,9)until id(board,a)<1 board=board:sub(1, a-1).."2"..board:sub(a+1) end
11.     cw()draw()d=d+1
12. end
13. if win>0 then p(({"Win","Lost"})[win]or"Tie") end
RAW Paste Data