'started by me ron77 on 6-15-2019 saturday night...
'one boring lonley weekend night i started to feel sad with no one to talk to...
'so i started this on my own so i won't feel lonely and sad all night
'by morning i got it right as a begining of a it was a white-night coding thing
'5-6-7 cups of coffee and a few cigarettes and relaxing music was all that it took
'by sun rise i felt better
'7 AM - add possiblemoves function
'10:30 AM - added a counter named turns to count turns and stop after 9 moves in case there is a tie and nobody wins
'9 PM - had a lesson with my teacher and we added a human vs. computer play with basic AI :) we also made some design modification
'6-17-2019 - more design modification to the board and to the code - added Bplus GetKey$ function and now no need for INPUT command to get user input added another loop to keep playing after first finished
'me and my teacher are working on a second harder AI alogarithem to beat in HUMAN VS. COMPUTER called INVICTUS MODE which will hopefully be very hard to beat next lesson on WED this week...
'6-18-2019 - in the meanwhile i am posting this short version 1 of tic tac toe in QB64 FORUM without level 2 INVICTUS MODE AI alogarithem: ENJOY! :)
'6-19-2019 - final version! thanks to all how helped!
'6-19-2019 - Bplus makeover reduce to less than 200 lines
opening
FOR i
= 0 TO 8: game
(i
) = " ":
NEXT 'clear last board turns = 0 'reset count
greetings = "TWO PLAYERS X AND O"
player "X"
IF code$
= "tie" THEN scoreX
= scoreX
+ 5: scoreO
= scoreO
+ 5:
EXIT DO player "O"
IF code$
= "tie" THEN scoreX
= scoreX
+ 5: scoreO
= scoreO
+ 5:
EXIT DO greetings = "HUMAN PLAYER AS X VS. COMPUTER AS O"
player "X"
IF code$
= "tie" THEN scoreX
= scoreX
+ 5: scoreComp
= scoreComp
+ 5:
EXIT DO board
cp 19, "O is winner."
scoreComp = scoreComp + 10
turns = turns + 1
cp 21, "play again y/n?"
again$
= UCASE$(GetKey$
("yn"))ending
SUB player
(sign$
) 'replace 3 repeated code blocks with this code$ = ""
board
cp 19, "Where to mark " + sign$ + "? press 0-8 or ESC to stop:"
k$
= GetKey$
(CHR$(27) + "012345678") game(inpt) = sign$
board
code$ = "win": cp 19, sign$ + " wins!"
turns = turns + 1
code$ = "tie": cp 19, "Tie nobody wins!"
board
cp 19, "The square is occupied choose another."
player sign$ ' recursive do this again!
cp 7, "G O O D - N I G H T !"
cp 9, " AND SWEET DREAMS!"
cp
11, "HUMAN PLAYER X HAS" + STR$(scoreX
) + " points" cp
13, "HUMAN PLAYER O HAS" + STR$(scoreO
) + " points" cp
15, "COMPUTER PLAYER O HAS" + STR$(scoreComp
) + " points"
cp 1, "Welcome to MIDNIGHT TIC TAC TOE GAME!"
cp 3, greetings
cp 5, "ÚÄÄÄÂÄÄÄÂÄÄÄ¿"
cp 6, "³ ³ ³ ³"
cp 7, "³ " + game(0) + " ³ " + game(1) + " ³ " + game(2) + " ³"
cp 8, "³(0)³(1)³(2)³"
cp 9, "ÃÄÄÄÅÄÄÄÅÄÄÄ´"
cp 10, "³ ³ ³ ³"
cp 11, "³ " + game(3) + " ³ " + game(4) + " ³ " + game(5) + " ³"
cp 12, "³(3)³(4)³(5)³"
cp 13, "ÃÄÄÄÅÄÄÄÅÄÄÄ´"
cp 14, "³ ³ ³ ³"
cp 15, "³ " + game(6) + " ³ " + game(7) + " ³ " + game(8) + " ³"
cp 16, "³(6)³(7)³(8)³"
cp 17, "ÀÄÄÄÁÄÄÄÁÄÄÄÙ"
cp 5, "WELCOME FRIEND TO:"
cp 7, "MIDNIGHT TIC TAC TOE GAME!"
cp 9, "WINS = 10 POINTS: TIES = 5 POINTS EACH"
cp 11, "A SMALL GAME TO PLAY BEFORE BED-TIME"
cp 13, "BY RON77, ITAY and BPLUS"
cp 18, "PRESS ENTER TO CONTINUE OR ESC TO QUIT"
cp 20, "Press 1 for One Player or 2 for Two Players?"
numPlayer
= VAL(GetKey$
("12")) cp 22, "PLAY IN FULL SCREEN MODE? - y/n"
k$ = GetKey$("yn")
SUB cp
(row
, s$
) 'print text centered on screen row
GetKey$ = k$
FOR i
= 0 TO 8 'computer seeks win game(i) = "O"
game(i) = " "
FOR i
= 0 TO 8 'computer seeks spoiler game(i) = "X"
game(i) = " "
rndNumber
= INT(RND * 9) 'computers picks random open space WHILE game
(rndNumber
) <> " " game(rndNumber) = "O"
IF game
(0) = game
(1) AND game
(1) = game
(2) AND game
(0) <> " " THEN Winner$ = game(0)
Winner$ = game(3)
Winner$ = game(6)
Winner$ = game(0)
Winner$ = game(1)
Winner$ = game(2)
Winner$ = game(0)
Winner$ = game(6)
Winner$ = ""