Author Topic: Tic-Tac-Toe  (Read 5894 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #15 on: January 30, 2021, 06:52:52 pm »
The only way I know how to do that is if to re-draw the grid on every computer move. Hmm, I'll give it a try.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #16 on: January 30, 2021, 07:05:48 pm »
Cool I figured it out! It redraws the grid over each time the computer moves, except for the bottom row so the O's on the bottom can still overlap the grid there. Check out the photo. Here's the update to the game. Thanks for the help!

Code: QB64: [Select]
  1. 'I've wanted to make this game for decades and finally am able to!
  2. 'This game was made on August 14, 2019 by SierraKen.
  3. 'This is Freeware.
  4. 'Jan. 28, 2021 update: Choose at random who goes first.
  5. 'Jan. 29, 2021 update: Random colored grid, better looking X's, faster welcome screen, centered welcome screen better, made the ability to click to play a new game and another game,
  6. 'and added text colors.
  7. 'Jan. 30, 2021 update: Added background blue shades. Also added a score in the Title Bar. Turned the game into 3D - Thanks to B+ for the idea!
  8.  
  9.  
  10. DIM a(10), b(10)
  11. _TITLE "Tic-Tac-Toe     by SierraKen"
  12. SCREEN _NEWIMAGE(600, 480, 32)
  13. LOCATE 10, 34: PRINT "-"
  14. LOCATE 10, 40: PRINT "-"
  15. FOR tic = 1 TO 10
  16.     LOCATE tic, 30: PRINT "TIC"
  17.     _DELAY .1
  18.     LOCATE tic, 30: PRINT "   "
  19. NEXT tic
  20. LOCATE 10, 30: PRINT "TIC"
  21. FOR tac = 20 TO 10 STEP -1
  22.     LOCATE tac, 36: PRINT "TAC"
  23.     _DELAY .1
  24.     LOCATE tac, 36: PRINT "   "
  25. NEXT tac
  26. LOCATE 10, 36: PRINT "TAC"
  27. FOR toe = 1 TO 10
  28.     LOCATE toe, 42: PRINT "TOE"
  29.     _DELAY .1
  30.     LOCATE toe, 42: PRINT "   "
  31. NEXT toe
  32. LOCATE 10, 42: PRINT "TOE"
  33. computer = 0
  34. you = 0
  35.  
  36. PRINT "                              By  SierraKen"
  37. PRINT "       Play against the computer in this classic game of Tic-Tac-Toe."
  38. PRINT "                      Whoever gets 3 in a row wins."
  39. PRINT "                    Choose a sqace by using your mouse."
  40. PRINT "                     Computer chooses who goes first."
  41.  
  42. COLOR _RGB32(255, 255, 255), _CLEARCOLOR
  43. _PRINTSTRING (220, 430), "Click Here To Start"
  44. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  45.  
  46.     _LIMIT 60
  47.     mouseWheel = 0
  48.         mouseX = _MOUSEX
  49.         mouseY = _MOUSEY
  50.         mouseLeftButton = _MOUSEBUTTON(1)
  51.         mouseRightButton = _MOUSEBUTTON(2)
  52.         mouseMiddleButton = _MOUSEBUTTON(3)
  53.         mouseWheel = mouseWheel + _MOUSEWHEEL
  54.     LOOP
  55.     ag$ = INKEY$
  56.     IF ag$ = CHR$(27) THEN END
  57.     IF ag$ = " " THEN CLS: GOTO start:
  58.     IF mouseLeftButton = -1 AND mouseX > 220 AND mouseX < 370 AND mouseY > 430 AND mouseY < 446 THEN CLS: GOTO start:
  59.  
  60. start:
  61. ag$ = ""
  62. t = 0
  63. turn = 0
  64. comp = 0
  65.  
  66. FOR cc = 0 TO 480
  67.     cl = cl + .5
  68.     LINE (0, cc)-(640, cc), _RGB32(0, 0, cl)
  69. NEXT cc
  70. cl = 0
  71. c1 = INT(RND * 155) + 100
  72. c2 = INT(RND * 155) + 100
  73. c3 = INT(RND * 155) + 100
  74.  
  75. GOSUB grid:
  76.  
  77. whosfirst:
  78. first = INT(RND * 2) + 1
  79. IF first = 1 THEN GOTO computerchoice:
  80.  
  81. Go:
  82. a$ = INKEY$
  83. IF a$ = CHR$(27) THEN END
  84. mouseWheel = 0
  85.     mouseX = _MOUSEX
  86.     mouseY = _MOUSEY
  87.     mouseLeftButton = _MOUSEBUTTON(1)
  88.     mouseRightButton = _MOUSEBUTTON(2)
  89.     mouseMiddleButton = _MOUSEBUTTON(3)
  90.     mouseWheel = mouseWheel + _MOUSEWHEEL
  91.  
  92. IF mouseLeftButton = -1 THEN
  93.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 93 AND mouseY < 182 AND b(1) = 0 AND a(1) = 0 AND t = 0 THEN GOSUB space1:
  94.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 93 AND mouseY < 182 AND b(2) = 0 AND a(2) = 0 AND t = 0 THEN GOSUB space2:
  95.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 93 AND mouseY < 182 AND b(3) = 0 AND a(3) = 0 AND t = 0 THEN GOSUB space3:
  96.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 205 AND mouseY < 302 AND b(4) = 0 AND a(4) = 0 AND t = 0 THEN GOSUB space4:
  97.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 205 AND mouseY < 302 AND b(5) = 0 AND a(5) = 0 AND t = 0 THEN GOSUB space5:
  98.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 205 AND mouseY < 302 AND b(6) = 0 AND a(6) = 0 AND t = 0 THEN GOSUB space6:
  99.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 326 AND mouseY < 410 AND b(7) = 0 AND a(7) = 0 AND t = 0 THEN GOSUB space7:
  100.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 326 AND mouseY < 410 AND b(8) = 0 AND a(8) = 0 AND t = 0 THEN GOSUB space8:
  101.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 326 AND mouseY < 410 AND b(9) = 0 AND a(9) = 0 AND t = 0 THEN GOSUB space9:
  102.  
  103. IF mouseLeftButton = -1 AND ending = 1 THEN GOTO start:
  104. IF mouseRightButton = -1 AND ending = 1 THEN END
  105.  
  106. IF t = 1 THEN GOSUB computer:
  107.  
  108. GOTO Go:
  109.  
  110. checkwin:
  111. 'Check to see if you won.
  112. IF a(1) = 1 AND a(2) = 1 AND a(3) = 1 THEN GOTO won:
  113. IF a(4) = 1 AND a(5) = 1 AND a(6) = 1 THEN GOTO won:
  114. IF a(7) = 1 AND a(8) = 1 AND a(9) = 1 THEN GOTO won
  115. IF a(1) = 1 AND a(4) = 1 AND a(7) = 1 THEN GOTO won:
  116. IF a(2) = 1 AND a(5) = 1 AND a(8) = 1 THEN GOTO won:
  117. IF a(3) = 1 AND a(6) = 1 AND a(9) = 1 THEN GOTO won:
  118. IF a(1) = 1 AND a(5) = 1 AND a(9) = 1 THEN GOTO won:
  119. IF a(3) = 1 AND a(5) = 1 AND a(7) = 1 THEN GOTO won:
  120. turn = turn + 1
  121. SOUND 100, .25
  122. IF turn = 9 THEN GOTO catsgame:
  123. GOTO Go:
  124. won:
  125. FOR snd = 300 TO 900 STEP 50
  126.     SOUND snd, .5
  127. NEXT snd
  128. FOR tt = 1 TO 9
  129.     a(tt) = 0
  130.     b(tt) = 0
  131. NEXT tt
  132. you = you + 1
  133. you$ = STR$(you)
  134. computer$ = STR$(computer)
  135. _TITLE "You: " + you$ + "   Computer: " + comp$
  136. t = 0
  137. LOCATE 2, 32: PRINT "Y O U   W I N ! !"
  138. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  139. GOTO playagain:
  140.  
  141. computer:
  142.  
  143. 'Check to win.
  144. 'Last space gone.
  145. IF b(1) = 1 AND b(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  146. IF b(4) = 1 AND b(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  147. IF b(7) = 1 AND b(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  148. IF b(1) = 1 AND b(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  149. IF b(2) = 1 AND b(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  150. IF b(3) = 1 AND b(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  151. IF b(1) = 1 AND b(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  152. IF b(3) = 1 AND b(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  153. 'First space gone.
  154. IF b(2) = 1 AND b(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  155. IF b(5) = 1 AND b(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  156. IF b(8) = 1 AND b(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  157. IF b(4) = 1 AND b(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  158. IF b(5) = 1 AND b(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  159. IF b(6) = 1 AND b(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  160. IF b(5) = 1 AND b(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  161. IF b(7) = 1 AND b(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  162. 'Middle space gone.
  163. IF b(1) = 1 AND b(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  164. IF b(4) = 1 AND b(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  165. IF b(7) = 1 AND b(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  166. IF b(1) = 1 AND b(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  167. IF b(2) = 1 AND b(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  168. IF b(3) = 1 AND b(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  169. IF b(1) = 1 AND b(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  170. IF b(3) = 1 AND b(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  171.  
  172. 'Check to block.
  173. 'Last space gone.
  174. IF a(1) = 1 AND a(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  175. IF a(4) = 1 AND a(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  176. IF a(7) = 1 AND a(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  177. IF a(1) = 1 AND a(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  178. IF a(2) = 1 AND a(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  179. IF a(3) = 1 AND a(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  180. IF a(1) = 1 AND a(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  181. IF a(3) = 1 AND a(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  182. 'First space gone.
  183. IF a(2) = 1 AND a(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  184. IF a(5) = 1 AND a(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  185. IF a(8) = 1 AND a(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  186. IF a(4) = 1 AND a(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  187. IF a(5) = 1 AND a(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  188. IF a(6) = 1 AND a(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  189. IF a(5) = 1 AND a(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  190. IF a(7) = 1 AND a(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  191. 'Middle space gone.
  192. IF a(1) = 1 AND a(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  193. IF a(4) = 1 AND a(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  194. IF a(7) = 1 AND a(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  195. IF a(1) = 1 AND a(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  196. IF a(2) = 1 AND a(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  197. IF a(3) = 1 AND a(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  198. IF a(1) = 1 AND a(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  199. IF a(3) = 1 AND a(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  200.  
  201. 'Computer decides a random space.
  202. computerchoice:
  203. comp = INT(RND * 9) + 1
  204. IF b(comp) = 1 THEN GOTO computerchoice:
  205. IF a(comp) = 1 THEN GOTO computerchoice:
  206. IF comp = 1 THEN GOTO compspace1:
  207. IF comp = 2 THEN GOTO compspace2:
  208. IF comp = 3 THEN GOTO compspace3:
  209. IF comp = 4 THEN GOTO compspace4:
  210. IF comp = 5 THEN GOTO compspace5:
  211. IF comp = 6 THEN GOTO compspace6:
  212. IF comp = 7 THEN GOTO compspace7:
  213. IF comp = 8 THEN GOTO compspace8:
  214. IF comp = 9 THEN GOTO compspace9:
  215.  
  216. 'Cat's Game
  217. catsgame:
  218. FOR snd = 400 TO 300 STEP -25
  219.     SOUND snd, .5
  220. NEXT snd
  221. FOR tt = 1 TO 9
  222.     a(tt) = 0
  223.     b(tt) = 0
  224. NEXT tt
  225. t = 0
  226. COLOR _RGB32(255, 0, 255), _CLEARCOLOR
  227. LOCATE 2, 29: PRINT "Cat's Game - No Winners"
  228. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  229. GOTO playagain:
  230.  
  231. 'Check to see if the computer won.
  232. check:
  233. IF b(1) = 1 AND b(2) = 1 AND b(3) = 1 THEN GOTO compwon:
  234. IF b(4) = 1 AND b(5) = 1 AND b(6) = 1 THEN GOTO compwon:
  235. IF b(7) = 1 AND b(8) = 1 AND b(9) = 1 THEN GOTO compwon
  236. IF b(1) = 1 AND b(4) = 1 AND b(7) = 1 THEN GOTO compwon:
  237. IF b(2) = 1 AND b(5) = 1 AND b(8) = 1 THEN GOTO compwon:
  238. IF b(3) = 1 AND b(6) = 1 AND b(9) = 1 THEN GOTO compwon:
  239. IF b(1) = 1 AND b(5) = 1 AND b(9) = 1 THEN GOTO compwon:
  240. IF b(3) = 1 AND b(5) = 1 AND b(7) = 1 THEN GOTO compwon:
  241. turn = turn + 1
  242. IF turn = 9 THEN GOTO catsgame:
  243. t = 0
  244. GOTO Go:
  245.  
  246. compwon:
  247. FOR snd = 900 TO 300 STEP -50
  248.     SOUND snd, .5
  249. NEXT snd
  250. FOR tt = 1 TO 9
  251.     a(tt) = 0
  252.     b(tt) = 0
  253. NEXT tt
  254. t = 0
  255. computer = computer + 1
  256. you$ = STR$(you)
  257. comp$ = STR$(computer)
  258. _TITLE "You: " + you$ + "   Computer: " + comp$
  259. COLOR _RGB32(128, 255, 255), _CLEARCOLOR
  260. LOCATE 2, 33: PRINT "Computer  Wins"
  261. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  262. GOTO playagain:
  263.  
  264. 'This part draws the computer's circle.
  265. compspace1:
  266. t = 0
  267. b(1) = 1
  268. FOR xx = .1 TO 10 STEP .1
  269.     FOR s = .25 TO 10 STEP .25
  270.         CIRCLE (160 - xx, 140 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  271.     NEXT s
  272. NEXT xx
  273. GOSUB grid:
  274. GOTO check:
  275. compspace2:
  276. t = 0
  277. b(2) = 1
  278. FOR xx = .1 TO 10 STEP .1
  279.     FOR s = .25 TO 10 STEP .25
  280.         CIRCLE (300 - xx, 140 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  281.     NEXT s
  282. NEXT xx
  283. GOSUB grid:
  284. GOTO check:
  285. compspace3:
  286. t = 0
  287. b(3) = 1
  288. FOR xx = .1 TO 10 STEP .1
  289.     FOR s = .25 TO 10 STEP .25
  290.         CIRCLE (440 - xx, 140 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  291.     NEXT s
  292. NEXT xx
  293. GOSUB grid:
  294. GOTO check:
  295. compspace4:
  296. t = 0
  297. b(4) = 1
  298. FOR xx = .1 TO 10 STEP .1
  299.     FOR s = .25 TO 10 STEP .25
  300.         CIRCLE (160 - xx, 260 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  301.     NEXT s
  302. NEXT xx
  303. GOSUB grid:
  304. GOTO check:
  305. compspace5:
  306. t = 0
  307. b(5) = 1
  308. FOR xx = .1 TO 10 STEP .1
  309.     FOR s = .25 TO 10 STEP .25
  310.         CIRCLE (300 - xx, 260 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  311.     NEXT s
  312. NEXT xx
  313. GOSUB grid:
  314. GOTO check:
  315. compspace6:
  316. t = 0
  317. b(6) = 1
  318. FOR xx = .1 TO 10 STEP .1
  319.     FOR s = .25 TO 10 STEP .25
  320.         CIRCLE (440 - xx, 260 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  321.     NEXT s
  322. NEXT xx
  323. GOSUB grid:
  324. GOTO check:
  325. compspace7:
  326. t = 0
  327. b(7) = 1
  328. FOR xx = .1 TO 10 STEP .1
  329.     FOR s = .25 TO 10 STEP .25
  330.         CIRCLE (160 - xx, 375 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  331.     NEXT s
  332. NEXT xx
  333. GOTO check:
  334. compspace8:
  335. t = 0
  336. b(8) = 1
  337. FOR xx = .1 TO 10 STEP .1
  338.     FOR s = .25 TO 10 STEP .25
  339.         CIRCLE (300 - xx, 375 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  340.     NEXT s
  341. NEXT xx
  342. GOTO check:
  343. compspace9:
  344. t = 0
  345. b(9) = 1
  346. FOR xx = .1 TO 10 STEP .1
  347.     FOR s = .25 TO 10 STEP .25
  348.         CIRCLE (440 - xx, 375 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  349.     NEXT s
  350. NEXT xx
  351. GOTO check:
  352. 'This last part draws your X.
  353. space1:
  354. a(1) = 1
  355. FOR xx = .1 TO 10 STEP .1
  356.     FOR s = .25 TO 10 STEP .25
  357.         LINE (115 + s - xx, 104 - xx)-(195 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  358.         LINE (195 + s - xx, 104 - xx)-(115 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  359.     NEXT s
  360. NEXT xx
  361. t = 1
  362. GOTO checkwin:
  363. space2:
  364. a(2) = 1
  365. FOR xx = .1 TO 10 STEP .1
  366.     FOR s = .25 TO 10 STEP .25
  367.         LINE (255 + s - xx, 104 - xx)-(335 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  368.         LINE (335 + s - xx, 104 - xx)-(255 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  369.     NEXT s
  370. NEXT xx
  371. t = 1
  372. GOTO checkwin:
  373. space3:
  374. a(3) = 1
  375. FOR xx = .1 TO 10 STEP .1
  376.     FOR s = .25 TO 10 STEP .25
  377.         LINE (395 + s - xx, 104 - xx)-(475 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  378.         LINE (475 + s - xx, 104 - xx)-(395 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  379.     NEXT s
  380. NEXT xx
  381. t = 1
  382. GOTO checkwin:
  383. space4:
  384. a(4) = 1
  385. FOR xx = .1 TO 10 STEP .1
  386.     FOR s = .25 TO 10 STEP .25
  387.         LINE (110 + s - xx, 224 - xx)-(190 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  388.         LINE (190 + s - xx, 224 - xx)-(110 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  389.     NEXT s
  390. NEXT xx
  391. t = 1
  392. GOTO checkwin:
  393. space5:
  394. a(5) = 1
  395. FOR xx = .1 TO 10 STEP .1
  396.     FOR s = .25 TO 10 STEP .25
  397.         LINE (255 + s - xx, 224 - xx)-(335 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  398.         LINE (335 + s - xx, 224 - xx)-(255 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  399.     NEXT s
  400. NEXT xx
  401. t = 1
  402. GOTO checkwin:
  403. space6:
  404. a(6) = 1
  405. FOR xx = .1 TO 10 STEP .1
  406.     FOR s = .25 TO 10 STEP .25
  407.         LINE (395 + s - xx, 224 - xx)-(475 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  408.         LINE (475 + s - xx, 224 - xx)-(395 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  409.     NEXT s
  410. NEXT xx
  411. t = 1
  412. GOTO checkwin:
  413. space7:
  414. a(7) = 1
  415. FOR xx = .1 TO 10 STEP .1
  416.     FOR s = .25 TO 10 STEP .25
  417.         LINE (110 + s - xx, 339 - xx)-(190 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  418.         LINE (190 + s - xx, 339 - xx)-(110 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  419.     NEXT s
  420. NEXT xx
  421. t = 1
  422. GOTO checkwin:
  423. space8:
  424. a(8) = 1
  425. FOR xx = .1 TO 10 STEP .1
  426.     FOR s = .25 TO 10 STEP .25
  427.         LINE (255 + s - xx, 339 - xx)-(335 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  428.         LINE (335 + s - xx, 339 - xx)-(255 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  429.     NEXT s
  430. NEXT xx
  431. t = 1
  432. GOTO checkwin:
  433. space9:
  434. a(9) = 1
  435. FOR xx = .1 TO 10 STEP .1
  436.     FOR s = .25 TO 10 STEP .25
  437.         LINE (395 + s - xx, 339 - xx)-(475 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  438.         LINE (475 + s - xx, 339 - xx)-(395 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  439.     NEXT s
  440. NEXT xx
  441. t = 1
  442. GOTO checkwin:
  443.  
  444. playagain:
  445. _PRINTSTRING (220, 55), "Click Here To Play Again"
  446. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  447.  
  448.     _LIMIT 60
  449.     mouseWheel = 0
  450.         mouseX = _MOUSEX
  451.         mouseY = _MOUSEY
  452.         mouseLeftButton = _MOUSEBUTTON(1)
  453.         mouseRightButton = _MOUSEBUTTON(2)
  454.         mouseMiddleButton = _MOUSEBUTTON(3)
  455.         mouseWheel = mouseWheel + _MOUSEWHEEL
  456.     LOOP
  457.     ag$ = INKEY$
  458.     IF ag$ = CHR$(27) THEN END
  459.     IF ag$ = " " THEN CLS: GOTO start:
  460.     IF mouseLeftButton = -1 AND mouseX > 220 AND mouseX < 412 AND mouseY > 55 AND mouseY < 69 THEN CLS: GOTO start:
  461.  
  462. grid:
  463. 'Draw Grid
  464. 'Vertical Lines
  465. FOR xx = .1 TO 15 STEP .1
  466.     LINE (220 - xx, 100 - xx)-(240 - xx, 410 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
  467.     LINE (360 - xx, 100 - xx)-(380 - xx, 410 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
  468. NEXT xx
  469. FOR xx = .1 TO 15 STEP .1
  470.     'Horizontal Lines
  471.     LINE (90 - xx, 185 - xx)-(510 - xx, 205 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
  472.     LINE (90 - xx, 305 - xx)-(510 - xx, 325 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
  473. NEXT xx
  474.  
TicTacToe.jpg
* TicTacToe.jpg (Filesize: 75.73 KB, Dimensions: 599x503, Views: 130)

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Tic-Tac-Toe
« Reply #17 on: January 30, 2021, 07:36:55 pm »
@SMcNeill

Quote
Starting out, one of the corner pieces gives you the best chance to win.  Unless your opponent takes the middle with their first move, you win.

Will try that.  Starting at corner or center ,  same chance of a win?
« Last Edit: January 30, 2021, 07:56:45 pm by NOVARSEG »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Tic-Tac-Toe
« Reply #18 on: January 30, 2021, 08:07:14 pm »
@SMcNeill

Will try that.  Starting at corner or center ,  same chance of a win?

If you start in the center, you’re only guaranteed a win if the second player takes a middle.

Tic-Tac-Toe isn’t really a game you can “win” at.  All you can do is screw up and lose.  There’s no perfect game, perfect move, or perfect position that guarantees you a win.  As long as neither player screws up, EVERY game will be a draw.

You don’t really win at it; the other guy just loses.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #19 on: January 30, 2021, 08:15:56 pm »
Actually, you do win when you have 2 ways you can go to win, and the other guy has to move once. Therefore you win by random chance and the fact you knew how to make it so you have 2 ways to win.
« Last Edit: January 30, 2021, 08:18:18 pm by SierraKen »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Tic-Tac-Toe
« Reply #20 on: January 30, 2021, 08:22:06 pm »
Actually, you do win when you have 2 ways you can go to win, and the other guy has to move once. Therefore you win by random chance and the fact you knew how to make it so you have 2 ways to win.

But you didn’t make it that way.  The other guy just screwed up and failed to make the  proper block.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #21 on: January 30, 2021, 08:30:20 pm »
With my head injury problems, my short term memory problems does simple programming.
« Last Edit: January 30, 2021, 08:40:08 pm by SierraKen »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Tic-Tac-Toe
« Reply #22 on: January 30, 2021, 09:09:16 pm »
From https://www.rd.com/article/how-to-win-tic-tac-toe/

Quote
How to win tic tac toe when you go second
If you’re the second to go, it may be harder to win the game. If your opponent takes the center space, counteract that by placing your letter in a corner. If your opponent takes a corner space, take the middle space. This will force a draw in both cases. Winning is almost impossible unless a major mistake is made by your opponent.

But, if your opponent starts on an edge that is not a corner, you can win. There is an exact science on how to win tic tac toe if this is the case: Put your first letter in the center. You can only claim victory if your opponent puts their letter on the other edge. If not, you will have to settle for a draw.


Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: Tic-Tac-Toe
« Reply #23 on: January 31, 2021, 10:24:59 am »
Tic-Tac-Toe Russian Real-Time Strategy

 
xox11.gif
   
xox22.gif


 
xoxrts.PNG


picture is milli size
« Last Edit: January 31, 2021, 10:26:06 am by DANILIN »
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Tic-Tac-Toe
« Reply #24 on: January 31, 2021, 05:23:51 pm »
Tic Tac Toe is not one of those games I gravitate toward, and I don't really know the AI behind it, but your presentation looks amazing and it runs me to a draw every time. Well executed.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #25 on: January 31, 2021, 07:46:09 pm »
Thanks OldMoses! Yeah the computer usually beats me or a tie. Sometimes I beat the computer though. It's more of a random chance game but you still have to make the right move to win by making it impossible to lose by having 2 ways to win on one move. It can't happen when the computer has the middle area I think because the 2 ways to win are usually by diagonal or vertical. But you are right when you said you don't gravitate toward this game, because I usually don't either. But thanks for the compliments. Maybe I can make the look of this game just as good as the look of a more interesting game in the future. :)