If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

This Thread is about everything to do with TIC-TAC-TOE,because it's such an interesting Topic :)

Many people have attemted to solve the problem with the shortest possible solution,whether it's a Computer program or an article published,
everything is interesting to those interested in Game theory and A.I etc.
So please add your own example Programs and any info you may have found on the subject,and maybe just maybe we will find an absolute Best Solution :)

Below is some History on the Topic...

https://en.wikipedia.org/wiki/Tic-tac-toe

An online Program to play against...

https://playtictactoe.org

And below is what I am now starting to believe is the Answer to the problem ? maybe it's also the Best solution ?? ...

Minimax for Tic Tac Toe
Minimax is a artificial intelligence applied in two player games, such as tic-tac-toe, checkers, chess and go.
This games are known as zero-sum games, because in a mathematical representation: one player wins (+1) and other player loses (-1) or both of anyone not to win (0).

Tic Tac Toe - Creating Unbeatable AI

https://gsurma.medium.com/tic-tac-toe-c ... f9e52c1e7d

Tic-tac-toe - Implementing Minimax Tree Search

https://thesharperdev.com/implementing- ... ree-search

Coding A Perfect Tic-Tac-Toe Bot!

https://thesharperdev.com/coding-the-pe ... ac-toe-bot

How many Tic-Tac-Toe (noughts and crosses) games are possible?

http://www.se16.info/hgb/tictactoe.htm

Winning Tic-tac-toe Strategies

https://www.instructables.com/Winning-t ... trategies/

Tic Tac Toe - John von Neumann's minimax algorithm.

https://www.half-real.net/tictactoe

REM ...................................................................................................................................................................

Rowan Gilmore, studied at University of Cambridge

There are 255168 possible game of Tic-tac-toe excluding symmetry. The first player wins 131184 of these, the second player wins 77904 games and the remaining 46080 are drawn.

As has been pointed out, with best play all games should result in a draw. Hence although there are 209088 winning games, many of these would almost never occur in practice.

For those interested, the python code I used to simulate this is given below:

Code: Select all

``````nWinO, nWinX, nDraw = 0, 0, 0

def recurse(board, toMove):
global nWinO, nWinX, nDraw

def win(board, player):
return (any(all(board[i][j] == player for j in range(3)) for i in range(3)) or
any(all(board[i][j] == player for i in range(3)) for j in range(3)) or
all(board[i][i] == player for i in range(3)) or
all(board[i][2-i] == player for i in range(3)))

def draw(board): return all(board[i][j] != '' for i in range(3) for j in range(3))

if win(board, 'O'): nWinO += 1
elif win(board, 'X'): nWinX += 1
elif draw(board): nDraw += 1
else:
for i in range(3):
for j in range(3):
if board[i][j] == '':
board[i][j] = toMove
recurse(board, 'X' if toMove == 'O' else 'O')
board[i][j] = ''

recurse([['','',''],['','',''],['','','']], 'O')

print("There are %d possible games (excluding symmetry), of which O wins %d, X wins %d and %d are drawn." % (nWinO+nWinX+nDraw,nWinO,nWinX,nDraw))
``````

REM ..................................................................................................................................................................

Below a simple Tic Tac Toe Program in C

Code: Select all

``````#include <stdio.h>
#include <conio.h>

char square[10] = { 'o', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

int checkwin();
void board();

int main()
{
int player = 1, i, choice;

char mark;
do
{
board();
player = (player % 2) ? 1 : 2;

printf("Player %d, enter a number:  ", player);
scanf("%d", &choice);

mark = (player == 1) ? 'X' : 'O';

if (choice == 1 && square[1] == '1')
square[1] = mark;

else if (choice == 2 && square[2] == '2')
square[2] = mark;

else if (choice == 3 && square[3] == '3')
square[3] = mark;

else if (choice == 4 && square[4] == '4')
square[4] = mark;

else if (choice == 5 && square[5] == '5')
square[5] = mark;

else if (choice == 6 && square[6] == '6')
square[6] = mark;

else if (choice == 7 && square[7] == '7')
square[7] = mark;

else if (choice == 8 && square[8] == '8')
square[8] = mark;

else if (choice == 9 && square[9] == '9')
square[9] = mark;

else
{
printf("Invalid move ");

player--;
getch();
}
i = checkwin();

player++;
}while (i ==  - 1);

board();

if (i == 1)
printf("==>\aPlayer %d win ", --player);
else
printf("==>\aGame draw");

getch();

return 0;
}

/*********************************************

FUNCTION TO RETURN GAME STATUS
1 FOR GAME IS OVER WITH RESULT
-1 FOR GAME IS IN PROGRESS
O GAME IS OVER AND NO RESULT
**********************************************/

int checkwin()
{
if (square[1] == square[2] && square[2] == square[3])
return 1;

else if (square[4] == square[5] && square[5] == square[6])
return 1;

else if (square[7] == square[8] && square[8] == square[9])
return 1;

else if (square[1] == square[4] && square[4] == square[7])
return 1;

else if (square[2] == square[5] && square[5] == square[8])
return 1;

else if (square[3] == square[6] && square[6] == square[9])
return 1;

else if (square[1] == square[5] && square[5] == square[9])
return 1;

else if (square[3] == square[5] && square[5] == square[7])
return 1;

else if (square[1] != '1' && square[2] != '2' && square[3] != '3' &&
square[4] != '4' && square[5] != '5' && square[6] != '6' && square[7]
!= '7' && square[8] != '8' && square[9] != '9')

return 0;
else
return  - 1;
}

/*******************************************************************
FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
********************************************************************/

void board()
{
system("cls");
printf("\n\n\tTic Tac Toe\n\n");

printf("Player 1 (X)  -  Player 2 (O)\n\n\n");

printf("     |     |     \n");
printf("  %c  |  %c  |  %c \n", square[1], square[2], square[3]);

printf("_____|_____|_____\n");
printf("     |     |     \n");

printf("  %c  |  %c  |  %c \n", square[4], square[5], square[6]);

printf("_____|_____|_____\n");
printf("     |     |     \n");

printf("  %c  |  %c  |  %c \n", square[7], square[8], square[9]);

printf("     |     |     \n\n");
}

/*******************************************************************
END OF PROJECT
********************************************************************/
``````
REM ..................................................................................................................................................................

Below a simple Tic Tac Toe Program in Python

Code: Select all

``````square = [0,1,2,3,4,5,6,7,8,9]

def main():
player = 1
status = -1

while status== -1:
board()

if player%2 == 1:
player = 1
else:
player = 2

print('\nPlayer', player)
choice = int(input('Enter a number:'))

if player == 1:
mark = 'X'
else:
mark = 'O'

if choice == 1 and square[1] == 1:
square[1] = mark
elif choice == 2 and square[2] == 2:
square[2] = mark
elif choice == 3 and square[3] == 3:
square[3] = mark
elif choice == 4 and square[4] == 4:
square[4] = mark
elif choice == 5 and square[5] == 5:
square[5] = mark
elif choice == 6 and square[6] == 6:
square[6] = mark
elif choice == 7 and square[7] == 7:
square[7] = mark
elif choice == 8 and square[8] == 8:
square[8] = mark
elif choice == 9 and square[9] == 9:
square[9] = mark
else:
print('Invalid move ')
player -= 1

status = game_status()
player += 1

print('RESULT')
if status == 1:
print('Player',player-1,'win')
else:
print('Game draw')

###############################################
#    FUNCTION TO RETURN GAME STATUS
#    1 FOR GAME IS OVER WITH RESULT
#    -1 FOR GAME IS IN PROGRESS
#    O GAME IS OVER AND NO RESULT
###############################################

def game_status():
if square[1] == square[2] and square[2] == square[3]:
return 1
elif square[4] == square[5] and square[5] == square[6]:
return 1
elif square[7] == square[8] and square[8] == square[9]:
return 1
elif square[1] == square[4] and square[4] == square[7]:
return 1
elif square[2] == square[5] and square[5] == square[8]:
return 1
elif square[3] == square[6] and square[6] == square[9]:
return 1
elif square[1] == square[5] and square[5] == square[9]:
return 1
elif square[3] == square[5] and square[5] == square[7]:
return 1
elif square[1] != 1 and square[2] != 2 and square[3] != 3 and square[4] != 4 and square[5] != 5 and square[6] != 6 and square[7] != 7 and square[8] != 8 and square[9] != 9:
return 0
else:
return -1

###############################################
#    FUNCTION TO DRAW BOARD
#    OF TIC TAC TOE WITH PLAYERS MARK
###############################################

def board():
print('\n\n\tTic Tac Toe\n\n')

print('Player 1 (X)  -  Player 2 (O)' )
print()

print('     |     |     ' )
print(' ' ,square[1] ,' | ' ,square[2] ,' |  ' ,square[3] )

print('_____|_____|_____' )
print('     |     |     ' )

print(' ' ,square[4] ,' | ' ,square[5] ,' |  ' ,square[6] )

print('_____|_____|_____' )
print('     |     |     ' )

print(' ' ,square[7] ,' | ' ,square[8] ,' |  ' ,square[9] )

print('     |     |     ' )

main()

``````

Anthony.R.Brown
Last edited by Anthony.R.Brown on Sun May 23, 2021 7:53 am, edited 5 times in total.
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

Below and Attached is a Great example by Paul Meyer 2007 ...

Code: Select all

``````
DECLARE FUNCTION XWIN% (B1 AS INTEGER, B2 AS INTEGER, B3 AS INTEGER, L AS INTEGER)
DECLARE FUNCTION OWIN% (B1 AS INTEGER, B2 AS INTEGER, B3 AS INTEGER, L AS INTEGER)
DECLARE SUB WINNER (LINEUP AS INTEGER)
DECLARE SUB SHOWWIN (B1 AS INTEGER, B2 AS INTEGER, B3 AS INTEGER)
DECLARE SUB GETUSERSIGNAL ()
DECLARE SUB ENABLEMOUSE (C%)
DECLARE SUB DRAWSCREEN ()
DECLARE SUB XO (ROW%, COL%, SYMBOL%)

DIM SHARED FALSE AS INTEGER, TRUE AS INTEGER: TRUE = NOT FALSE
DIM SHARED SYMBOLBOX(6000) AS INTEGER '<---NOTE

DIM SHARED CH AS INTEGER: 'CURSOR POSITION HORIZONTAL
DIM SHARED CV AS INTEGER: 'CURSOR POSITION VERTICAL
DIM SHARED CLICK AS INTEGER: ' 0=NO CLICK, 1=LEFT CLICK, 2=RIGHT
' ENABLEMOUSE 1 = TURN CURSOR ON, RETURN COORDINATES
' ENABLEMOUSE 0 = TURN CURSOR OFF IN ORDER TO DRAW STUFF, ETC.
DIM SHARED CC AS STRING: 'USER PRESSED KEY
' GETUSERSIGNAL WILL SET RETURN CC OR WILL RETURN CLICK

DIM I AS INTEGER, J AS INTEGER, K AS INTEGER
DIM WHOWON AS INTEGER

' ----------------------------------------------------------
'                TITLE SCREEN (MAIN PROGRAM)
' -----------------------------------------------------------
SCREEN 12
RANDOMIZE TIMER
DIM COMMAND AS INTEGER, HARD AS INTEGER
GOSUB INITIALIZESCREEN
DO
DO: GETUSERSIGNAL: LOOP UNTIL CLICK = 1
GOSUB FINDCLICKEDCOMMAND
SELECT CASE COMMAND
CASE 1:
HARD = FALSE
WHOWON = 0
GOSUB PLAYGAME
GOSUB SHOWWHOWON
GOSUB INITIALIZESCREEN
CASE 2:
HARD = TRUE
WHOWON = 0
GOSUB PLAYGAME
GOSUB SHOWWHOWON
GOSUB INITIALIZESCREEN
CASE 3:
GOSUB DOHELP
GOSUB INITIALIZESCREEN
CASE 4:
EXIT DO
END SELECT
LOOP
COLOR 7: CLS
SYSTEM

' ----------------------------------------------------------
'                GAME SCREEN
' -----------------------------------------------------------
DIM SHARED ZX(9) AS INTEGER: ' WHERE ALL X'S ARE PLACED
DIM SHARED ZO(9) AS INTEGER: ' WHERE ALL O'S ARE PLACED
DIM SHARED ZE(9) AS INTEGER: ' WHERE EMPTY SQUARES ARE
DIM THEROW AS INTEGER, THECOLUMN AS INTEGER, THEBOX AS INTEGER

FINDCLICKEDPOSITION:
CONST DELTA = 4
THEROW = 0: THECOLUMN = 0: THEBOX = 0
SELECT CASE CH
CASE IS < 170 + DELTA: RETURN
CASE IS < 269 - DELTA: THECOLUMN = 1
CASE IS < 269 + DELTA: RETURN
CASE IS < 368 - DELTA: THECOLUMN = 2
CASE IS < 368 + DELTA: RETURN
CASE IS < 467 - DELTA: THECOLUMN = 3
CASE ELSE: RETURN
END SELECT
SELECT CASE CV
CASE IS < 91 + DELTA: RETURN
CASE IS < 190 - DELTA: THEROW = 1
CASE IS < 190 + DELTA: RETURN
CASE IS < 289 - DELTA: THEROW = 2
CASE IS < 289 + DELTA: RETURN
CASE IS < 388 - DELTA: THEROW = 3
CASE ELSE: RETURN
END SELECT
THEBOX = (3 * (THEROW - 1)) + THECOLUMN
RETURN

' ----------------------------------------------------------
'                PLAY GAME
' -----------------------------------------------------------
PLAYGAME:
DRAWSCREEN 'DRAW THE SCREEN AND CREATE X AND O SYMBOLS.
FOR I = 1 TO 9: ZO(I) = FALSE: ZX(I) = FALSE: ZE(I) = TRUE: NEXT I
DO
GETUSERSIGNAL
IF CLICK THEN
GOSUB MAKEX
WHOWON = 1: GOSUB COMPUTEWIN: IF WHOWON = 1 THEN RETURN
T% = 0
FOR I = 1 TO 9: T% = T% + ZX(I): NEXT I
IF T% = -5 THEN WHOWON = 0: RETURN
GOSUB MAKEO
WHOWON = 2: GOSUB COMPUTEWIN: IF WHOWON = 2 THEN RETURN
END IF
END IF
IF CC = "D" OR CC = CHR\$(27) THEN WHOWON = 3
IF WHOWON > 0 THEN RETURN
LOOP

MAKEX:
GOSUB FINDCLICKEDPOSITION
IF THEBOX = 0 THEN RETURN
IF NOT ZE(THEBOX) THEN RETURN
XO THEROW, THECOLUMN, 1: ' PLACES AN X
ZX(THEBOX) = TRUE: ZE(THEBOX) = FALSE
RETURN

MAKEO:
GOSUB FINDPLACEFORO
SLEEP 1: WHILE INKEY\$ <> "": WEND
XO THEROW, THECOLUMN, 0: 'PLACES AN O
ZO(THEBOX) = TRUE: ZE(THEBOX) = FALSE
RETURN

COMPUTEWIN:
IF WHOWON = 1 THEN
IF XWIN(1, 2, 3, 1) THEN RETURN
IF XWIN(4, 5, 6, 2) THEN RETURN
IF XWIN(7, 8, 9, 3) THEN RETURN
IF XWIN(1, 4, 7, 4) THEN RETURN
IF XWIN(2, 5, 8, 5) THEN RETURN
IF XWIN(3, 6, 9, 6) THEN RETURN
IF XWIN(1, 5, 9, 7) THEN RETURN
IF XWIN(3, 5, 7, 8) THEN RETURN
ELSE
IF OWIN(1, 2, 3, 1) THEN RETURN
IF OWIN(4, 5, 6, 2) THEN RETURN
IF OWIN(7, 8, 9, 3) THEN RETURN
IF OWIN(1, 4, 7, 4) THEN RETURN
IF OWIN(2, 5, 8, 5) THEN RETURN
IF OWIN(3, 6, 9, 6) THEN RETURN
IF OWIN(1, 5, 9, 7) THEN RETURN
IF OWIN(3, 5, 7, 8) THEN RETURN
END IF
WHOWON = 0
RETURN

FINDPLACEFORO:
' SEE IF THERE IS A WIN FOR O. IF SO, TAKE IT.
' SEE IF THERE IS A THREAT OF A WIN FOR X. IF SO, BLOCK IT.
FOR TESTTYPE% = 1 TO 2
THEBOX = 0
FOR THEROW = 1 TO 3: FOR THECOLUMN = 1 TO 3
THEBOX = THEBOX + 1
IF ZE(THEBOX) THEN
TK\$ = ""
SELECT CASE THEBOX
CASE 1: TK\$ = "234759"
CASE 2: TK\$ = "1358"
CASE 3: TK\$ = "126957"
CASE 4: TK\$ = "1756"
CASE 5: TK\$ = "19283746"
CASE 6: TK\$ = "4539"
CASE 7: TK\$ = "148935"
CASE 8: TK\$ = "2579"
CASE 9: TK\$ = "153678"
END SELECT
FOR I = 1 TO LEN(TK\$) STEP 2
J = VAL(MID\$(TK\$, I, 1))
K = VAL(MID\$(TK\$, I + 1, 1))
IF TESTTYPE% = 1 THEN
IF ZO(J) + ZO(K) < -1 THEN RETURN
ELSE
IF ZX(J) + ZX(K) < -1 THEN RETURN
END IF
NEXT I
END IF
NEXT THECOLUMN: NEXT THEROW
NEXT TESTTYPE%
' NO MOVE SELECTED ABOVE TO WIN OR BLOCK WIN, SO
IF HARD THEN
IF ZE(5) THEN
THEROW = 2: THECOLUMN = 2: THEBOX = 5
ELSE
IF RND > .5 THEN THEROW = 1 ELSE THEROW = 3
IF RND > .5 THEN THECOLUMN = 1 ELSE THECOLUMN = 3
THEBOX = (3 * (THEROW - 1)) + THECOLUMN
END IF
RETURN
IF ZX(5) THEN
TK\$ = ""
IF ZO(1) AND ZX(9) THEN
TK\$ = "37"
ELSEIF ZO(3) AND ZX(7) THEN
TK\$ = "19"
ELSEIF ZO(7) AND ZX(3) THEN
TK\$ = "19"
ELSEIF ZO(9) AND ZX(1) THEN
TK\$ = "37"
END IF
IF TK\$ <> "" THEN
IF RND > .5 THEN
THEBOX = VAL(LEFT\$(TK\$, 1))
ELSE
THEBOX = VAL(LEFT\$(TK\$, 1))
END IF
THEROW = (THEBOX + 2) \ 3
THECOLUMN = THEBOX - (3 * (THEROW - 1))
RETURN
END IF
ELSE
DO
DO: THEBOX = 2 * INT(1 + (RND * 4)): LOOP WHILE NOT ZE(THEBOX)
SELECT CASE THEBOX
CASE 2: IF NOT ZX(8) THEN EXIT DO
CASE 4: IF NOT ZX(6) THEN EXIT DO
CASE 6: IF NOT ZX(4) THEN EXIT DO
CASE 8: IF NOT ZX(2) THEN EXIT DO
END SELECT
LOOP
THEROW = (THEBOX + 2) \ 3
THECOLUMN = THEBOX - (3 * (THEROW - 1))
RETURN
END IF
END IF
END IF
' OK, NO GOOD MOVE WAS FOUND. MAKE A RANDOM ONE
DO: THEBOX = 1 + INT(RND * 9): LOOP WHILE NOT ZE(THEBOX)
THEROW = (THEBOX + 2) \ 3
THECOLUMN = THEBOX - (3 * (THEROW - 1))
RETURN

SHUFFLE:
DO WHILE LEN(W1\$) < 4
R% = 1 + INT(RND * 4)
IF MID\$(W2\$, R%, 1) <> "X" THEN
W1\$ = W1\$ + MID\$(W2\$, R%, 1)
MID\$(W2\$, R%, 1) = "X"
END IF
LOOP
RETURN

SHOWWHOWON:
SELECT CASE WHOWON
CASE 0: C\$ = "TIE! "
CASE 1: C\$ = "YOU WIN! "
CASE 2: C\$ = "YOU LOSE! "
CASE 3: C\$ = "YOU RESIGNED?"
END SELECT
IF WHOWON < 3 THEN SLEEP 2: WHILE INKEY\$ <> "": WEND
CLS
FOR I = 1 TO 30
COLOR 1 + INT(RND * 15)
LOCATE I, I + 20
PRINT C\$;
NEXT I
SLEEP 3: WHILE INKEY\$ <> "": WEND
RETURN

INITIALIZESCREEN:
CLS
COLOR 15
LOCATE 4, 23: PRINT "TIC TAC TOE BY PAUL MEYER & THEBOB"
LOCATE 6, 27: PRINT "(C) 2004 - 2007 DOS-ID GAMES"
COLOR 3
DS% = 131: DD% = 97: DZ% = 75
LINE (DS%, 343)-(DS% + DZ%, 380), , BF
LINE (DS% + (1 * DD%), 343)-(DS% + (1 * DD%) + DZ%, 380), , BF
LINE (DS% + (2 * DD%), 343)-(DS% + (2 * DD%) + DZ%, 380), , BF
LINE (DS% + (3 * DD%), 343)-(DS% + (3 * DD%) + DZ%, 380), , BF
LOCATE 23, 19: PRINT " EASY ";
LOCATE , 31: PRINT " HARD ";
LOCATE , 43: PRINT " INFO ";
LOCATE , 55: PRINT " QUIT "
RETURN

FINDCLICKEDCOMMAND:
COMMAND = 0
SELECT CASE CV
CASE IS < 343: RETURN
CASE IS > 380: RETURN
END SELECT
SELECT CASE CH
CASE IS < 130: RETURN
CASE IS < 205: COMMAND = 1
CASE IS < 227: RETURN
CASE IS < 303: COMMAND = 2
CASE IS < 325: RETURN
CASE IS < 400: COMMAND = 3
CASE IS < 421: RETURN
CASE IS < 497: COMMAND = 4
END SELECT
RETURN

DOHELP:
CLS
COLOR 2
LOCATE 3, 1
PRINT "CREDITS"
PRINT "-------"
PRINT "THIS GAME WAS CREATED BY PAUL MEYER IN THE YEAR 2007."
PRINT: PRINT "GRAPHICS BY THEBOB"
PRINT: PRINT "IMPROVED MOUSE DRIVER, MODULARITY, MACHINE PLAY-TO-WIN";
PRINT " BY QBASIC MAC"
PRINT: PRINT "HISTORY:"
PRINT "HTTP://WWW.NETWORK54.COM/FORUM/190883/MESSAGE/1175106480"
PRINT
PRINT "THIS IS FREEWARE, YOU MAY CHANGE THIS AS MUCH AS YOU WANT"
PRINT "AS LONG AS YOU DON'T CLAIM IT AS YOURS."
PRINT
PRINT
PRINT "-----"
PRINT "THIS IS JUST A SIMPLE TIC TAC TOE GAME WITH MOUSE DRIVERS."
PRINT "THIS GAME WAS CREATED IN QUICKBASIC."
CALL GETUSERSIGNAL
CLS
RETURN

SUB DRAWSCREEN
DIM X AS INTEGER, Y AS INTEGER
STATIC FINISHED AS INTEGER
CLS
OUT &H3C8, 0: OUT &H3C9, 0: OUT &H3C9, 0: OUT &H3C9, 18
OUT &H3C8, 4: OUT &H3C9, 63: OUT &H3C9, 0: OUT &H3C9, 0
OUT &H3C8, 9: OUT &H3C9, 0: OUT &H3C9, 12: OUT &H3C9, 48
OUT &H3C8, 11: OUT &H3C9, 0: OUT &H3C9, 18: OUT &H3C9, 54
COLOR 7: LOCATE 3, 31: PRINT "T I C - T A C - T O E"
LINE (170, 90)-(490, 410), 0, BF
LINE (160, 81)-(479, 399), 1, BF
LINE (155, 76)-(483, 404), 8, B
LINE (152, 73)-(487, 407), 8, B
LINE (160, 81)-(160, 399), 9
LINE (160, 81)-(479, 81), 9
LINE (371, 92)-(372, 393), 0, B
LINE (271, 92)-(272, 392), 0, B
LINE (171, 191)-(472, 192), 0, B
LINE (171, 291)-(472, 292), 0, B
LINE (369, 90)-(370, 390), 13, B
LINE (269, 90)-(270, 390), 13, B
LINE (169, 189)-(470, 190), 13, B
LINE (169, 289)-(470, 290), 13, B
LINE (5, 5)-(634, 474), 8, B
LINE (10, 10)-(629, 469), 8, B
IF FINISHED THEN EXIT SUB
FINISHED = TRUE
FOR X = 194 TO 500
FOR Y = 32 TO 46
IF POINT(X, Y) = 8 THEN PSET (X, Y), 7
NEXT Y
NEXT X
PSET (188, 108), 0
DRAW "E3 F30 E30 F6 G30 F30 G6 H30 G30 H6 E30 H30 E3 BF2 P0,0"
PSET (186, 106), 10
DRAW "E3 F30 E30 F6 G30 F30 G6 H30 G30 H6 E30 H30 E3 BF2 P10,10"
CIRCLE (322, 141), 31, 0
CIRCLE (322, 141), 37, 0
PAINT STEP(0, 35), 0
PSET STEP(0, -35), 0
CIRCLE (320, 139), 31, 4
CIRCLE (320, 139), 37, 4
PAINT STEP(0, 35), 4
PSET STEP(0, -35), 1
GET STEP(-40, -40)-STEP(81, 81), SYMBOLBOX()
GET (179, 98)-(260, 178), SYMBOLBOX(3000)
XO 1, 1, 2: XO 1, 2, 2
END SUB

SUB ENABLEMOUSE (C%)
STATIC STATUS AS INTEGER
IF STATUS = 0 AND C% = 0 THEN EXIT SUB
STATIC MX AS STRING
IF MX = "" THEN
M\$ = "58E85080585080585080850815510C358508058508085080850815C00"
N\$ = "595BECB70BEAB70BE8BFBE6B7B8E7D33BEC978BEA97BE89FBE697DA80"
MX = SPACE\$(57)
FOR I% = 1 TO 57
H\$ = CHR\$(VAL("&H" + MID\$(M\$, I%, 1) + MID\$(N\$, I%, 1)))
MID\$(MX, I%, 1) = H\$
NEXT I%
END IF
IF C% = 0 THEN
CALL ABSOLUTE(2, CLICK, CH, CV, SADD(MX))
STATUS = 0
EXIT SUB
END IF
IF STATUS = 0 THEN CALL ABSOLUTE(1, CLICK, CH, CV, SADD(MX))
STATUS = 1
CALL ABSOLUTE(3, CLICK, CH, CV, SADD(MX))
END SUB

SUB GETUSERSIGNAL
DO
IF 0 THEN ' SET TO 1 FOR DEBUGGING PRINTOUT, OTHERWISE 0
LOCATE 2, 1
PRINT CLICK; "<CLICK"
PRINT CH; "CH (HORIZONTAL)"
PRINT CV; "CV (VERTICLE)"
END IF
ENABLEMOUSE 1
IF CLICK > 0 THEN
K% = CLICK
WHILE CLICK <> 0: ENABLEMOUSE 1: WEND
CLICK = K%
EXIT DO
END IF
CC = INKEY\$
LOOP WHILE CC = ""
ENABLEMOUSE 0
END SUB

FUNCTION OWIN% (B1 AS INTEGER, B2 AS INTEGER, B3 AS INTEGER, L AS INTEGER)
IF ZO(B1) = 0 OR ZO(B2) = 0 OR ZO(B3) = 0 THEN EXIT FUNCTION
WINNER L
OWIN% = -1
END FUNCTION

SUB WINNER (LINEUP AS INTEGER)
SELECT CASE LINEUP
CASE 1: LINE (200, 140)-(440, 142), 14, BF: LINE (200, 143)-(440, 144), 0, B
CASE 2: LINE (200, 240)-(440, 242), 14, BF: LINE (200, 243)-(440, 244), 0, B
CASE 3: LINE (200, 340)-(440, 342), 14, BF: LINE (200, 343)-(440, 344), 0, B
CASE 4: LINE (220, 120)-(222, 360), 14, BF: LINE (223, 120)-(223, 360), 0
CASE 5: LINE (320, 120)-(322, 360), 14, BF: LINE (323, 120)-(323, 360), 0
CASE 6: LINE (420, 120)-(422, 360), 14, BF: LINE (423, 120)-(423, 360), 0
CASE 7: PSET (200, 120), 14: DRAW "F240 D H240 D F240 D H240 D C0 F240 D H240"
CASE 8: PSET (440, 120), 14: DRAW "G240 D E240 D G240 D E240 D C0 G240 D E240"
END SELECT
END SUB

SUB XO (ROW AS INTEGER, COL AS INTEGER, SYMBOL AS INTEGER)
DIM INDEX AS INTEGER, X AS INTEGER, Y AS INTEGER
X = (COL - 1) * 100 + 180
Y = (ROW - 1) * 100 + 100
INDEX = SYMBOL * 3000
IF INDEX < 6000 THEN
PUT (X, Y), SYMBOLBOX(INDEX), PSET
ELSE
LINE (X, Y)-(X + 80, Y + 80), 1, BF
END IF
END SUB

FUNCTION XWIN% (B1 AS INTEGER, B2 AS INTEGER, B3 AS INTEGER, L AS INTEGER)
IF ZX(B1) = 0 OR ZX(B2) = 0 OR ZX(B3) = 0 THEN EXIT FUNCTION
WINNER L
XWIN% = -1
END FUNCTION

``````
Attachments
TICTACTOE-PAUL MEYER-2007.BAS.zip
Last edited by Anthony.R.Brown on Sun Feb 07, 2021 2:13 pm, edited 1 time in total.
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

Check below for my latest OXAUTOLN Program...

It is a Program I have been working on and off since 23/02/2002 (that long!) :(

Anthony.R.Brown
Last edited by Anthony.R.Brown on Sun May 23, 2021 7:54 am, edited 2 times in total.
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

I have a Perfect version now if I can finish the last bit ?
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

Look below!

A.R.B
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

Check out my latest OXAUTOLN3X3GENIUS Final version! below ...

A.R.B
Last edited by Anthony.R.Brown on Sun May 23, 2021 8:15 am, edited 1 time in total.
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

The Original OXAUTOLN1 23/02/2002 is now with the OXAUTOLN3X3GENIUS in a special all in one version OXAUTOLN3X3ORIGVSGENIUS below...

A.R.B
Last edited by Anthony.R.Brown on Tue Jun 01, 2021 3:38 am, edited 2 times in total.
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

Below attached is the Final OXAUTOLN3X3GENIUSPLUS

It contains the OXAUTOLN3X3GENIUS which is the Original OXAUTOLN1 taken to another level!

And a Special OXAUTOLN3X3ORIGVSGENIUS which pit's the Original OXAUTOLN1 against the GENIUS version!

For Testing there is the TICTACTOE-PAUL MEYER-2007 program to show just how good my programs are!

And a very interesting article "Tic Tac Toe - Implementing Minimax Tree Search" which shows a way to Solve Tic-Tac-Toe and lots of info.

All the programs are in their own folders! which is the best and recommended way to keep the learning seperate!

Enjoy! as it will be the last from me! it's Solved!!!

Anthony.R.Brown

OXAUTOLN3X3GENIUSPLUS.zip
Last edited by Anthony.R.Brown on Mon May 31, 2021 2:22 pm, edited 4 times in total.
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

Below attached are some Screen shots of my OXAUTOLN3X3GENIUS
Attachments
1.png (128.24 KiB) Viewed 12805 times
2.png (48.27 KiB) Viewed 12806 times
3.png (32.08 KiB) Viewed 12806 times
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

And another...

For some reason I can only post 3 copies of this one image ? even though I deleted the other 2

What a Joke! trying to post images on this site!!!
ff.png (339.84 KiB) Viewed 12294 times
Attachments
ff.png (339.84 KiB) Viewed 12294 times
ff.png (339.84 KiB) Viewed 12294 times
Last edited by Anthony.R.Brown on Tue Jun 01, 2021 11:26 am, edited 32 times in total.
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

And even more because you cannot post more than 3 images at once!!!
Attachments
7.png (48.27 KiB) Viewed 12801 times
8.png (32.08 KiB) Viewed 12802 times
9.png (37.19 KiB) Viewed 12802 times
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm

The last few... and showing the program playing itself to a Classic Draw!
10.png (497.24 KiB) Viewed 12421 times
11.png (119.73 KiB) Viewed 12421 times
Anthony.R.Brown
Veteran
Posts: 157
Joined: Thu Mar 27, 2014 1:03 pm