I have it a complete, playable program. It uses some of your base code, but I have it using Matrices and it has an AI that does "good-move". It plays randomly until it can either complete a tictac or stop you from playing a tictac. The user is 0, and goes first, the AI makes the second move. Here is the code!

**Code:** ```
:DCS6
```

:DSS6

"0810081008100810FFFF081008500B100D500B500810FFFF0810081008100810"

SetUpEditor

AxesOff

0->O

0->N

Lbl 0

ClrHome

{3,3->dim([A]

Fill(0,[A]

Menu("Tic-Tac-Toe AI","Play",1,"Quit",2

Lbl 1

ClrDraw

~33->Xmin

61->Ymax

~1->Ymin

61->Xmax

For(A,0,60,20

Line(A,0,A,60

Line(0,A,60,A

End

Text(20,0,"GAMES WON"

Text(26,0,"O: ",O

Text(32,0,"X: ",N

1->P

2->A

2->B

0->W

0->Q

Repeat W or theta=45

If B>3

3->B

Text(0,0,"O'S TURN"

Pt-On(20B-10,20B-10

Repeat theta

getKey->theta

End

Pt-Off(20A-10,20B-10

A+(theta=26 and A<3)-(theta=24 and A>1->A

B+(theta=25 and B<3)-(theta=34 and B>1->B

Pt-On(20A-10,20B-10

If theta=105 and not([A](A,B)

Then

Q+1->Q

Pt-Off(20A-10,20B-10

Circle(20A-10,20B-10,7

1->[A](A,B

//"Win-detection start"

0->D

0->E

0->W

For(C,1,3

[A](1,C)+[A](2,C)+[A](3,C->D

[A](C,1)+[A](C,2)+[A](C,3->E

If D=3 or E=3

1->W

If D=12 or E=12

2->W

End

[A](1,1)+[A](2,2)+[A](3,3->D

[A](3,1)+[A](2,2)+[A](1,3->E

If D=3 or E=3

1->W

If D=12 or E=12

2->W

//"Win-detection end"

If Q<9 and not(W

Then

//"AI start"

Text(0,0,"X'S TURN"

Q+1->Q

ClrList L1

ClrList L2

0->T

4->U

For(S,1,3

If [A](S,1)=[A](S,2) and [A](S,1)not([A](S,3

Then

S->L1(1+dim(L1

3->L2(1+dim(L2

If [A](S,2)=U

dim(L1->T

End

If [A](S,1)=[A](S,3) and [A](S,1)not([A](S,2

Then

S->L1(1+dim(L1

2->L2(1+dim(L2

If [A](S,3)=U

dim(L1->T

End

If [A](S,2)=[A](S,3) and [A](S,2)not([A](S,1

Then

S->L1(1+dim(L1

1->L2(1+dim(L2

If [A](S,3)=U

dim(L1->T

End

If [A](1,S)=[A](2,S) and [A](1,S)not([A](3,S

Then

3->L1(1+dim(L1

S->L2(1+dim(L2

If [A](2,S)=U

dim(L1->T

End

If [A](1,S)=[A](3,S) and [A](1,S)not([A](2,S

Then

2->L1(1+dim(L1

S->L2(1+dim(L2

If [A](3,S)=U

dim(L1->T

End

If [A](2,S)=[A](3,S) and [A](2,S)not([A](1,S

Then

1->L1(1+dim(L1

S->L2(1+dim(L2

If [A](3,S)=U

dim(L1->T

End

End

If [A](1,1)=[A](2,2) and [A](1,1)not([A](3,3

Then

3->L1(1+dim(L1

3->L2(1+dim(L2

If [A](2,2)=U

dim(L1->T

End

If [A](1,1)=[A](3,3) and [A](1,1)not([A](2,2

Then

2->L1(1+dim(L1

2->L2(1+dim(L2

If [A](3,3)=U

dim(L1->T

End

If [A](3,3)=[A](2,2) and [A](3,3)not([A](1,1

Then

1->L1(1+dim(L1

1->L2(1+dim(L2

If [A](2,2)=U

dim(L1->T

End

If [A](3,1)=[A](2,2) and [A](3,1)not([A](1,3

Then

1->L1(1+dim(L1

3->L2(1+dim(L2

If [A](2,2)=U

dim(L1->T

End

If [A](3,1)=[A](1,3) and [A](3,1)not([A](2,2

Then

2->L1(1+dim(L1

2->L2(1+dim(L2

If [A](1,3)=U

dim(L1->T

End

If [A](1,3)=[A](2,2) and [A](1,3)not([A](3,1

Then

3->L1(1+dim(L1

1->L2(1+dim(L2

If [A](2,2)=U

dim(L1->T

End

If dim(L1

Then

randInt(1,dim(L1->theta

L1(theta->I

L2(theta->J

If T

Then

L1(T->I

L2(T->J

End

Else

Repeat not([A](I,J

randInt(1,3->I

randInt(1,3->J

End

End

//"AI end"

4->[A](I,J

Line(20I-3,20J-3,20I-17,20J-17

Line(20I-3,20J-17,20I-17,20J-3

Pt-Off(20I-10,20J-10

End

End

//"Win-detection start"

0->D

0->E

0->W

For(C,1,3

[A](1,C)+[A](2,C)+[A](3,C->D

[A](C,1)+[A](C,2)+[A](C,3->E

If D=3 or E=3

1->W

If D=12 or E=12

2->W

End

[A](1,1)+[A](2,2)+[A](3,3->D

[A](3,1)+[A](2,2)+[A](1,3->E

If D=3 or E=3

1->W

If D=12 or E=12

2->W

//"Win-detection end"

If Q=9 and not(W

45->theta

End

If W

Then

O+(W=1->O

N+(W=2->N

Text(0,0,sub("OX",W,1)," WINS! "

Text(26,7,O

Text(32,7,N

Pause

Else

Text(0,0,"TIE! "

Pause

End

Goto 0

Lbl 2

ClrHome

Stop

It can more than likely be optimized in speed and size, it probably deserves work on program flow and memory management. But it's there and I works.