
-----------------------------------
compstudent
Sun Feb 06, 2011 4:39 pm

Tic Tac Toe Game Problem
-----------------------------------
I am making a simple two player tic tac toe game. I am having problems with having the the game draw a X and O when they are supposed to. The game is not done yet - I still need to add syntax to check if players won. Just need someone to point our what I am doing wrong.

Thanks





%TIC TAC TOE GAME

setscreen ("graphics:600;600")


procedure drawx (spotx, spoty : int)
    var x1 := spotx * 100
    var y1 := spoty * 100
    var x2 := (spotx * 100) + 100
    var y2 := (spoty * 100) + 100
    drawline (x1, y1, x2, y2, red)
    drawline (x1, y1 + 100, x2, y2 - 100, red)
end drawx

procedure drawo (midx, midy : int)
    var x1 := (midx * 100) + 50
    var y1 := (midy * 100) + 50
    var rad := 50

    drawoval (x1, y1, rad, rad, blue)
end drawo

procedure drawgrid
    drawline (100, 0, 100, 300, black)
    drawline (200, 0, 200, 300, black)
    drawline (0, 100, 300, 100, black)
    drawline (0, 200, 300, 200, black)
end drawgrid

procedure game
    var x, y, z : int
    var p1, p2 : int := 0
    loop
        mousewhere (x, y, z)
        if z = 1 and x < 100 and y < 100 then
            if p2 < p1 then
                drawo (0, 0)
                p2:=p2+1
            else
                drawx (0, 0)
                p1:=p1+1
            end if
        elsif z = 1 and x < 100 and y < 200 and y > 100 then
            if p2 < p1 then
                drawo (0, 1)
                p2:=p2+1
            else
                drawx (0, 1)
                p1:=p1+1
            end if
        elsif z = 1 and x < 100 and y < 300 and y > 200 then
            if p2 < p1 then
                drawo (0, 2)
                p2:=p2+1
            else
                drawx (0, 2)
                p1:=p1+1
            end if
        elsif z = 1 and x > 100 and x < 200 and y < 100 then
            if p2 < p1 then
                drawo (1, 0)
                p2:=p2+1
            else
                drawx (1, 0)
                p1:=p1+1
            end if
        elsif z = 1 and x > 100 and x < 200 and y > 100 and y < 200 then
            if p2 < p1 then
                drawo (1, 1)
                p2:=p2+1
            else
                drawx (1, 1)
                p1:=p1+1
            end if
        elsif z = 1 and x > 100 and x < 200 and y > 200 and y < 300 then
            if p2 < p1 then
                drawo (1, 2)
                p2:=p2+1
            else
                drawx (1, 2)
                p1:=p1+1
            end if
        elsif z = 1 and x > 200 and x < 300 and y < 100 then
            if p2 < p1 then
                drawo (2, 0)
                p2:=p2+1
            else
                drawx (2, 0)
                p1:=p1+1
            end if
        elsif z = 1 and x > 200 and x < 300 and y > 100 and y < 200 then
            if p2 < p1 then
                drawo (2, 1)
                p2:=p2+1
            else
                drawx (2, 1)
                p1:=p1+1
            end if
        elsif z = 1 and x > 200 and x < 300 and y > 200 and y < 300 then
            if p2 < p1 then
                drawo (2, 2)
                p2:=p2+1
            else
                drawx (2, 2)
                p1:=p1+1
            end if

        end if
        
        

    end loop



end game
drawgrid
game



-----------------------------------
huskiesgoaler34
Sun Feb 06, 2011 5:05 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
I am assuming that, after trying to play your game, you are trying to not draw both an x or an o each time the box is clicked. Right now, both are drawn on top of eachother. Am I right?

-----------------------------------
TokenHerbz
Sun Feb 06, 2011 5:13 pm

RE:Tic Tac Toe Game Problem
-----------------------------------
if you add a delay(60) in the loop you'll see that both arn't drawn the same time, however you need to make sure that the grid is "clear" before you can "draw" on it, so that you cant draw on it again...

you could use a boolean for that.

-----------------------------------
huskiesgoaler34
Sun Feb 06, 2011 5:15 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
What I would do is set an x or an o to each player. So player1 is an o and player 2 is an x. If player one clicks a box, it draws a o. If player two clicks a box, then an x is drawn.

-----------------------------------
huskiesgoaler34
Sun Feb 06, 2011 5:16 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Maybe stick to token's idea. His is easier.  :D

-----------------------------------
compstudent
Sun Feb 06, 2011 5:23 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
I'm not quite sure I completely understand tokens idea. I have put in the delay and noticed the difference. Now I just need to make sure that another symbol isn't drawn if the box is already taken. 

Thanks for the replies.

-----------------------------------
compstudent
Sun Feb 06, 2011 5:26 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Do you mean like a multi-dimensional array of boolean, and assign the variable true for the corresponding gird spot when it is drawn on.

-----------------------------------
compstudent
Sun Feb 06, 2011 6:05 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
I have changed it and added variables, just for two places on the board so far. Now for when the first player clicks a spot it draws the correct symbol then, when clicked again nothing happens which is good. However when you click the next box, both symbols show up. 

I'm not sure whats wrong. 


procedure game
    var turn : boolean := true
    var x, y, z : int
    var p1, p2 : int := 0
    var board : array 0 .. 2, 0 .. 2 of char
    var full : array 0 .. 2, 0 .. 2 of boolean := init (false, false, false, false, false, false, false, false, false)
    loop
        mousewhere (x, y, z)
        if z = 1 and x < 100 and y < 100 and full (0, 0) = false then
            if turn = false then
                drawo (0, 0)
              
                turn := true
                full (0, 0) := true
                board (0, 0) := "o"
            end if
            if turn = true then
                drawx (0, 0)
               
                turn := false
                full (0, 0) := true
                board (0, 0) := "x"
            end if
        elsif z = 1 and x < 100 and y < 200 and y > 100 and full (0, 1) = false then
            if turn = false then
                drawo (0, 1)
                turn := true
                full (0, 1) := true
                board (0, 1) := "o"
                end if
            if turn = true then
                drawx (0, 1)
                turn := false
                full (0, 1) := true
                board (0, 1) := "x"
            end if



-----------------------------------
huskiesgoaler34
Sun Feb 06, 2011 6:20 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
I have changed it and added variables, just for two places on the board so far. Now for when the first player clicks a spot it draws the correct symbol then, when clicked again nothing happens which is good. However when you click the next box, both symbols show up. 

I'm not sure whats wrong. 


procedure game
    var turn : boolean := true
    var x, y, z : int
    var p1, p2 : int := 0
    var board : array 0 .. 2, 0 .. 2 of char
    var full : array 0 .. 2, 0 .. 2 of boolean := init (false, false, false, false, false, false, false, false, false)
    loop
        mousewhere (x, y, z)
        if z = 1 and x < 100 and y < 100 and full (0, 0) = false then
            if turn = false then
                drawo (0, 0)
              
                turn := true
                full (0, 0) := true
                board (0, 0) := "o"
            end if
           % if turn = true then
              %  drawx (0, 0)
               
                %turn := false
                %full (0, 0) := true
                %board (0, 0) := "x"
            %end if
        elsif z = 1 and x < 100 and y < 200 and y > 100 and full (0, 1) = false then
            if turn = false then
                drawo (0, 1)
                turn := true
                full (0, 1) := true
                board (0, 1) := "o"
                end if
            if turn = true then
                drawx (0, 1)
                turn := false
                full (0, 1) := true
                board (0, 1) := "x"
            end if



I think I found the problem. The commented part was the problem. After you click one box, it drew the correct symbol but when you clicked another box, it draws both symbols.  Now, I made it so that when one of the boxes is clicked, the x appears. When you click another box, a circle appears. 

Note: It only works for the first two boxes on the first column.

-----------------------------------
compstudent
Sun Feb 06, 2011 6:27 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
I notice that after you click a box an x will first appear, then the next box an O. But if i click the lower left box an x will appear, then if i click the one directly above it, both appear.

-----------------------------------
compstudent
Sun Feb 06, 2011 7:00 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Nevermind - I have fixed that problem now. Just needed to add


and full(0,0)=false then


to each of the embedded if statements. Thanks for the help, I'll probably be back with more problems.

-----------------------------------
RandomLetters
Sun Feb 06, 2011 7:44 pm

RE:Tic Tac Toe Game Problem
-----------------------------------
I think it would help a lot if you looked into else and elsif statements for the inner conditional instead of adding more conditions.

(edit for clarity)

-----------------------------------
compstudent
Sun Feb 06, 2011 8:02 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
I have another problem. I have worked it out so that each symbol is drawn when it is supposed to be and so that there aren't two in the same square. Now my problem is that there seems to be a delay in drawing them. For example if I click on it will draw. Next one nothing. Next one I click both show up: the one before where I clicked and the new one. I noticed though, if I click pause after one doesn't show up, it suddenly appears.

I am not sure what is the problem.



%TIC TAC TOE GAME

setscreen ("graphics:300;310")
var turn : boolean := true
var x, y, z : int
var p1, p2 : int := 0
var board : array 0 .. 2, 0 .. 2 of char
var full : array 0 .. 2, 0 .. 2 of boolean := init (false, false, false, false, false, false, false, false, false)
var name1, name2 : string

procedure drawx (spotx, spoty : int)
    var x1 := spotx * 100
    var y1 := spoty * 100
    var x2 := (spotx * 100) + 100
    var y2 := (spoty * 100) + 100
    drawline (x1, y1, x2, y2, red)
    drawline (x1, y1 + 100, x2, y2 - 100, red)
end drawx

procedure start
    put "Enter player ones name"
    get name1
    put "Enter player twos name"
    get name2
    cls
    put name1, " is x."
    put name2, " is o."
    put name1, " starts."
    put "To play click on the square you want to put your symbol"
    locate (10, 10)
    put "The game starts in: "
    delay (3000)
    cls
    locate (10, 20)
    put "5"
    delay (1000)
    cls
    locate (10, 20)
    put "4"
    delay (1000)
    cls
    locate (10, 20)
    put "3"
    delay (1000)
    cls
    locate (10, 20)
    put "2"
    delay (1000)
    cls
    locate (10, 20)
    put "1"
    delay (1000)
    cls
    locate (10, 20)
    put "Go"
    delay (500)
    cls
end start


procedure drawo (midx, midy : int)
    var x1 := (midx * 100) + 50
    var y1 := (midy * 100) + 50
    var rad := 50

    drawoval (x1, y1, rad, rad, blue)
end drawo

procedure drawgrid
    drawline (100, 0, 100, 300, black)
    drawline (200, 0, 200, 300, black)
    drawline (0, 100, 300, 100, black)
    drawline (0, 200, 300, 200, black)
end drawgrid

procedure game

    loop
        mousewhere (x, y, z)
        if z = 1 and x < 100 and y < 100 and full (0, 0) = false then
            if turn = false and full (0, 0) = false then
                drawo (0, 0)

                turn := true
                full (0, 0) := true
                board (0, 0) := "o"
            end if
            if turn = true and full (0, 0) = false then
                drawx (0, 0)

                turn := false
                full (0, 0) := true
                board (0, 0) := "x"
            end if

        elsif z = 1 and x < 100 and y < 200 and y > 100 and full (0, 1) = false then
            if turn = false and full (0, 1) = false then
                drawo (0, 1)
                turn := true
                full (0, 1) := true
                board (0, 1) := "o"
            end if
            if turn = true and full (0, 1) = false then
                drawx (0, 1)
                turn := false
                full (0, 1) := true
                board (0, 1) := "x"
            end if
        elsif z = 1 and x < 100 and y < 300 and y > 200 and full (0, 2) = false then
            if turn = false and full (0, 2) = false then
                drawo (0, 2)
                turn := true
                full (0, 2) := true
                board (0, 2) := "o"
            end if
            if turn = true and full (0, 2) = false then
                drawx (0, 2)
                turn := false
                full (0, 2) := true
                board (0, 2) := "x"
            end if
        elsif z = 1 and x > 100 and x < 200 and y < 100 then
            if turn = false and full (1, 0) = false then
                drawo (1, 0)
                turn := true
                full (1, 0) := true
                board (1, 0) := "o"
            end if
            if turn = true and full (1, 0) = false then
                drawx (1, 0)
                turn := false
                full (1, 0) := true
                board (1, 0) := "x"
            end if
        elsif z = 1 and x > 100 and x < 200 and y > 100 and y < 200 then
            if turn = false and full (1, 1) = false then
                drawo (1, 1)
                turn := true
                full (1, 1) := true
                board (1, 1) := "o"
            end if
            if turn = true and full (1, 1) = false then
                drawx (1, 1)
                turn := false
                full (1, 1) := true
                board (1, 1) := "x"
            end if
        elsif z = 1 and x > 100 and x < 200 and y > 200 and y < 300 then
            if turn = false and full (1, 2) = false then
                drawo (1, 2)
                turn := true
                full (1, 2) := true
                board (1, 2) := "o"
            end if
            if turn = true and full (1, 2) = false then
                drawx (1, 2)
                turn := false
                full (1, 2) := true
                board (1, 2) := "x"
            end if
        elsif z = 1 and x > 200 and x < 300 and y < 100 then
            if turn = false and full (2, 0) = false then
                drawo (2, 0)
                turn := true
                full (2, 0) := true
                board (2, 0) := "o"
            end if
            if turn = true and full (2, 0) = false then
                drawx (2, 0)
                turn := false
                full (2, 0) := true
                board (2, 0) := "x"
            end if
        elsif z = 1 and x > 200 and x < 300 and y > 100 and y < 200 then
            if turn = false and full (2, 1) = false then
                drawo (2, 1)
                turn := true
                full (2, 1) := true
                board (2, 1) := "o"
            end if
            if turn = true and full (2, 1) = false then
                drawx (2, 1)
                turn := false
                full (2, 1) := true
                board (2, 1) := "x"
            end if
        elsif z = 1 and x > 200 and x < 300 and y > 200 and y < 300 then
            if turn = false and full (2, 2) = false then
                drawo (2, 2)
                turn := true
                full (2, 2) := true
                board (2, 2) := "o"
            end if
            if turn = true and full (2, 2) = false then
                drawx (2, 2)
                turn := false
                full (2, 2) := true
                board (2, 2) := "x"
            end if

        end if



    end loop



end game
drawgrid
game


Note: Not complete. Yet to add prompts and checking to see if a player won.

-----------------------------------
huskiesgoaler34
Sun Feb 06, 2011 8:20 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
It works perfectly for me. I don't see a problem. The correct symbol is drawn without any delays. No bugs. I have tested it out and it works fine.

-----------------------------------
compstudent
Sun Feb 06, 2011 8:32 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Thanks, I guess it is just my computer, since I just tried it on another and it worked fine.

-----------------------------------
huskiesgoaler34
Sun Feb 06, 2011 8:45 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Your welcome. Post the code when your done with determining the winner and ending the game.

-----------------------------------
TokenHerbz
Sun Feb 06, 2011 10:06 pm

RE:Tic Tac Toe Game Problem
-----------------------------------
you could use a 2D array for your "grid" to, and types are good at storing "multiple data" though i'd use a class myself.

-----------------------------------
compstudent
Mon Feb 07, 2011 7:15 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Here is the game now almost complete. The problems I am having now are that I need it to stop when a player one - you will notice it doesn't, and then to allow the players to play again. If I make a play again procedure i have to put it above the game procedure so that the game can recognize it, but then I cannot call the game procedure in the play again one.  


%TIC TAC TOE GAME

setscreen ("graphics:300;310")
var turn : boolean := true
var x, y, z : int
var p1, p2 : int := 0
var board : array 0 .. 2, 0 .. 2 of char
var full : array 0 .. 2, 0 .. 2 of boolean := init (false, false, false, false, false, false, false, false, false)
var name1, name2 : string
var timoe:int:=0
var again:string:="Yes"

procedure drawx (spotx, spoty : int)
    var x1 := spotx * 100
    var y1 := spoty * 100
    var x2 := (spotx * 100) + 100
    var y2 := (spoty * 100) + 100
    drawline (x1, y1, x2, y2, red)
    drawline (x1, y1 + 100, x2, y2 - 100, red)
end drawx

procedure start
    put "Enter player ones name"
    get name1
    put "Enter player twos name"
    get name2
    cls
    put name1, " is x."
    put name2, " is o."
    put name1, " starts."
    put "To play click on the square you want to put your symbol"
    locate (10, 10)
    put "The game starts in: "
    delay (3000)
    cls
    locate (10, 20)
    put "5"
    delay (1000)
    cls
    locate (10, 20)
    put "4"
    delay (1000)
    cls
    locate (10, 20)
    put "3"
    delay (1000)
    cls
    locate (10, 20)
    put "2"
    delay (1000)
    cls
    locate (10, 20)
    put "1"
    delay (1000)
    cls
    locate (10, 20)
    put "Go"
    delay (500)
    cls
end start


start


procedure drawo (midx, midy : int)
    var x1 := (midx * 100) + 50
    var y1 := (midy * 100) + 50
    var rad := 50

    drawoval (x1, y1, rad, rad, blue)
end drawo

procedure drawgrid
    drawline (100, 0, 100, 300, black)
    drawline (200, 0, 200, 300, black)
    drawline (0, 100, 300, 100, black)
    drawline (0, 200, 300, 200, black)
end drawgrid

procedure check
%Checks veritcal
    if board (0, 0) = board (0, 1) and board (0, 1) = board (0, 2) and full(0,0) = true and full(0,1) = true and full(0,2) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
    end if
    if board (1, 0) = board (1, 1) and board (1, 1) = board (1, 2) and full(1,0) = true and full(1,1) = true and full(1,2) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
    end if
    if board (2, 0) = board (2, 1) and board (2, 1) = board (2, 2) and full(2,0) = true and full(2,1) = true and full(2,2) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
    end if
    %Checks Horizontal
    if board (0, 0) = board (1, 0) and board (1, 0) = board (2, 0) and full(0,0) = true and full(1,0) = true and full(2,0) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
    end if
    if board (0, 1) = board (1, 1) and board (1, 1) = board (2, 1) and full(0,1) = true and full(1,1) = true and full(2,1) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
    end if
    if board (0, 2) = board (1, 2) and board (1, 2) = board (2, 2) and full(0,2) = true and full(1,2) = true and full(2,2) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
    end if
    %checks diagonal
    if board(0,0) = board(1,1) and board(1,1) = board(2,2) and full(0,0) = true and full(1,1) = true and full(2,2) = true then
            if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
    end if
    if board(0,2) = board(1,1) and board(1,1) = board (2,0) and full(0,2) = true and full(1,1) = true and full(2,0) = true then 
            if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
    end if
end check

procedure game

    loop

        mousewhere (x, y, z)
        if z = 1 and x < 100 and y < 100 and full (0, 0) = false then
            if turn = false and full (0, 0) = false then
                drawo (0, 0)

                turn := true
                full (0, 0) := true
                board (0, 0) := "o"
                check
            end if
            if turn = true and full (0, 0) = false then
                drawx (0, 0)

                turn := false
                full (0, 0) := true
                board (0, 0) := "x"
                check
            end if

        elsif z = 1 and x < 100 and y < 200 and y > 100 and full (0, 1) = false then
            if turn = false and full (0, 1) = false then
                drawo (0, 1)
                turn := true
                full (0, 1) := true
                board (0, 1) := "o"
                check
            end if
            if turn = true and full (0, 1) = false then
                drawx (0, 1)
                turn := false
                full (0, 1) := true
                board (0, 1) := "x"
                check
            end if
        elsif z = 1 and x < 100 and y < 300 and y > 200 and full (0, 2) = false then
            if turn = false and full (0, 2) = false then
                drawo (0, 2)
                turn := true
                full (0, 2) := true
                board (0, 2) := "o"
                check
            end if
            if turn = true and full (0, 2) = false then
                drawx (0, 2)
                turn := false
                full (0, 2) := true
                board (0, 2) := "x"
                check
            end if
        elsif z = 1 and x > 100 and x < 200 and y < 100 then
            if turn = false and full (1, 0) = false then
                drawo (1, 0)
                turn := true
                full (1, 0) := true
                board (1, 0) := "o"
                check
            end if
            if turn = true and full (1, 0) = false then
                drawx (1, 0)
                turn := false
                full (1, 0) := true
                board (1, 0) := "x"
                check
            end if
        elsif z = 1 and x > 100 and x < 200 and y > 100 and y < 200 then
            if turn = false and full (1, 1) = false then
                drawo (1, 1)
                turn := true
                full (1, 1) := true
                board (1, 1) := "o"
                check
            end if
            if turn = true and full (1, 1) = false then
                drawx (1, 1)
                turn := false
                full (1, 1) := true
                board (1, 1) := "x"
                check
            end if
        elsif z = 1 and x > 100 and x < 200 and y > 200 and y < 300 then
            if turn = false and full (1, 2) = false then
                drawo (1, 2)
                turn := true
                full (1, 2) := true
                board (1, 2) := "o"
                check
            end if
            if turn = true and full (1, 2) = false then
                drawx (1, 2)
                turn := false
                full (1, 2) := true
                board (1, 2) := "x"
                check
            end if
        elsif z = 1 and x > 200 and x < 300 and y < 100 then
            if turn = false and full (2, 0) = false then
                drawo (2, 0)
                turn := true
                full (2, 0) := true
                board (2, 0) := "o"
                check
            end if
            if turn = true and full (2, 0) = false then
                drawx (2, 0)
                turn := false
                full (2, 0) := true
                board (2, 0) := "x"
                check
            end if
        elsif z = 1 and x > 200 and x < 300 and y > 100 and y < 200 then
            if turn = false and full (2, 1) = false then
                drawo (2, 1)
                turn := true
                full (2, 1) := true
                board (2, 1) := "o"
                check
            end if
            if turn = true and full (2, 1) = false then
                drawx (2, 1)
                turn := false
                full (2, 1) := true
                board (2, 1) := "x"
                check
            end if
        elsif z = 1 and x > 200 and x < 300 and y > 200 and y < 300 then
            if turn = false and full (2, 2) = false then
                drawo (2, 2)
                turn := true
                full (2, 2) := true
                board (2, 2) := "o"
                check
            end if
            if turn = true and full (2, 2) = false then
                drawx (2, 2)
                turn := false
                full (2, 2) := true
                board (2, 2) := "x"
                check
            end if

        end if



    end loop



end game
drawgrid 
game 


-----------------------------------
ProgrammingFun
Mon Feb 07, 2011 9:47 pm

RE:Tic Tac Toe Game Problem
-----------------------------------
Have you heard of forward procedure?
It enables you to do the following:


forward procedure B

proc A
     put "Hello"
     %Call Procedure B
end A

proc B
    put "Bye"
end B


It was something like the above...I do not completely remember...

-----------------------------------
DemonWasp
Tue Feb 08, 2011 8:08 am

RE:Tic Tac Toe Game Problem
-----------------------------------
Even if you do resolve the circular reference as ProgrammingFun says, you'll eventually run into stack overflow problems that way. Better to have a replay loop that exits if the user doesn't want to replay the game, and loops if they do.

-----------------------------------
TokenHerbz
Tue Feb 08, 2011 10:08 am

RE:Tic Tac Toe Game Problem
-----------------------------------
I Think the Best way for you (least work) to fix this problem would be to add a boolean Value to check for when the game is won.

So in your procedure Check ( I would rework this so its not so repetitive, And make this into a function.  If a player has won it turns this and use that in your game loop to exit the look when this occurs.. 

After if you want, you could even reset your variables after the loop still inside the game loop.

Create another loop to cycle threw your two procedures to keep the game going.

-----------------------------------
TokenHerbz
Tue Feb 08, 2011 10:39 am

RE:Tic Tac Toe Game Problem
-----------------------------------
I went ahead and Did some re-working of your code to give you an example of some things your doing wrong.  This is to help you better understand what to look for and how to problem solve things for the rest of your game and/or other programs your making.

your OLD CODE:

procedure check 
%Checks veritcal 
    if board (0, 0) = board (0, 1) and board (0, 1) = board (0, 2) and full(0,0) = true and full(0,1) = true and full(0,2) = true then 
        if turn = false then 
            put "Congradulations", name1, "you won!" 
        elsif turn = true then 
            put "Congradulations", name2, "you won!" 
        end if 
    end if 
    if board (1, 0) = board (1, 1) and board (1, 1) = board (1, 2) and full(1,0) = true and full(1,1) = true and full(1,2) = true then 
        if turn = false then 
            put "Congradulations", name1, "you won!" 
        elsif turn = true then 
            put "Congradulations", name2, "you won!" 
        end if 
    end if 
    if board (2, 0) = board (2, 1) and board (2, 1) = board (2, 2) and full(2,0) = true and full(2,1) = true and full(2,2) = true then 
        if turn = false then 
            put "Congradulations", name1, "you won!" 
        elsif turn = true then 
            put "Congradulations", name2, "you won!" 
        end if 
    end if 
    %Checks Horizontal 
    if board (0, 0) = board (1, 0) and board (1, 0) = board (2, 0) and full(0,0) = true and full(1,0) = true and full(2,0) = true then 
        if turn = false then 
            put "Congradulations", name1, "you won!" 
        elsif turn = true then 
            put "Congradulations", name2, "you won!" 
        end if 
    end if 
    if board (0, 1) = board (1, 1) and board (1, 1) = board (2, 1) and full(0,1) = true and full(1,1) = true and full(2,1) = true then 
        if turn = false then 
            put "Congradulations", name1, "you won!" 
        elsif turn = true then 
            put "Congradulations", name2, "you won!" 
        end if 
    end if 
    if board (0, 2) = board (1, 2) and board (1, 2) = board (2, 2) and full(0,2) = true and full(1,2) = true and full(2,2) = true then 
        if turn = false then 
            put "Congradulations", name1, "you won!" 
        elsif turn = true then 
            put "Congradulations", name2, "you won!" 
        end if 
    end if 
    %checks diagonal 
    if board(0,0) = board(1,1) and board(1,1) = board(2,2) and full(0,0) = true and full(1,1) = true and full(2,2) = true then 
            if turn = false then 
            put "Congradulations", name1, "you won!" 
        elsif turn = true then 
            put "Congradulations", name2, "you won!" 
        end if 
    end if 
    if board(0,2) = board(1,1) and board(1,1) = board (2,0) and full(0,2) = true and full(1,1) = true and full(2,0) = true then 
            if turn = false then 
            put "Congradulations", name1, "you won!" 
        elsif turn = true then 
            put "Congradulations", name2, "you won!" 
        end if 
    end if 
end check 


The purpose of this check is obviously to see if the player has won the game.  It's called like 16 times or so in the main loop, Which is absolutely not required.  As you can see in your game loop we go to a first "if" statement.  This goes step by step down the list until the end.  You have "check" in every sub if statement inside that main one.  All that is required is the check is in before the end if on the main if statement, Hell It doesn't even need to be inside this if statement at all.  But if you wanted it inside there, it would have a correct place.

The thing about programming is even you retype a ton of your code, and the game still seems to function correctly, It's Bad to do it for several reasons, the main being it's hard to change around, and/or fix bugs. Very time consuming.

So First example to solving your question, Is how do we make this "check" work?  Well I went ahead and redid that procedure into a Function, (which returns a value) and renamed this "Win_Game".  Here is the source:


fcn Game_Won : boolean
    if board (0, 0) = board (0, 1) and board (0, 1) = board (0, 2) and full (0, 0) = true and full (0, 1) = true and full (0, 2) = true or %%Vertical check
            board (1, 0) = board (1, 1) and board (1, 1) = board (1, 2) and full (1, 0) = true and full (1, 1) = true and full (1, 2) = true or
            board (2, 0) = board (2, 1) and board (2, 1) = board (2, 2) and full (2, 0) = true and full (2, 1) = true and full (2, 2) = true or
            board (0, 0) = board (1, 0) and board (1, 0) = board (2, 0) and full (0, 0) = true and full (1, 0) = true and full (2, 0) = true or %%Horizontal check
            board (0, 1) = board (1, 1) and board (1, 1) = board (2, 1) and full (0, 1) = true and full (1, 1) = true and full (2, 1) = true or
            board (0, 2) = board (1, 2) and board (1, 2) = board (2, 2) and full (0, 2) = true and full (1, 2) = true and full (2, 2) = true or
            board (0, 0) = board (1, 1) and board (1, 1) = board (2, 2) and full (0, 0) = true and full (1, 1) = true and full (2, 2) = true or %%Diagnal check
            board (0, 2) = board (1, 1) and board (1, 1) = board (2, 0) and full (0, 2) = true and full (1, 1) = true and full (2, 0) = true then
        if turn = false then
            put "Congradulations ", name1, " you won!"
        elsif turn = true then
            put "Congradulations ", name2, " you won!"
        end if
        Input.Pause %%to show the players who won
        result true
    end if
    result false
end Game_Won


How I used this is just as important, I don't call this more then "ONCE" in the main loop, Here lets take a look and understand it!

exit when Game_Won = true %%exit the game loop

So what i did was create a function that returns a true/false depending on circumstances, this case being if a player has won or not.  I put this check right at the very end of the game procedure so how it goes is "start game -> player moves -> check if win -> if win exit else continue -> other player moves -> rinse and repeat.

Now when the Player does win, and we exit the game proc loop We are still in the procedure, so why not reset variables and clear the screen so we may play again!! 

 %%Reset variables here if you want to
    for r : 0 .. 2
        for c : 0 .. 2
            board (r, c) := ""
            full (r, c) := false
        end for
    end for
    cls %%Clear the screen


I should also mention i've changed your Bored array to string, init values of blank ""x9 times.

var board : array 0 .. 2, 0 .. 2 of string := init ("","","","","","","","","")


Now what have we fixed?  We made it possible to check if the game has won or not, and leave the game according to that (FIXED function). We reset variables and clear the screen so may play again!! Awesome!!!  Now for the final thing, we loop our procs!! and we are ready for endless tic tac toe!


loop
    drawgrid
    game
end loop


*********************
*********************
So Now that you have your game working, YOUR not DONE yet... Oh noes, no no no!!

I show'd you something in your check proc, how to minimize all this "re-do-re-write codes"...

What you need to do now, Is re-write your proc game to minimize all that repeat codes.  Just check how its supposed to work and when you fix/clean that up, post it here for some BITS!

Good luck !!! PS: After you touch your code up, you can add more features to your game very easily.  Cheers!

-----------------------------------
compstudent
Tue Feb 08, 2011 1:53 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Thank you very much for you lengthy reply. It was VERY helpful. 
Here is the game and i think it is finished. 


%TIC TAC TOE GAME


setscreen ("graphics:300;310")
var turn : boolean := true
var x, y, z : int
var p1, p2 : int := 0
var board : array 0 .. 2, 0 .. 2 of char
var full : array 0 .. 2, 0 .. 2 of boolean := init (false, false, false, false, false, false, false, false, false)
var name1, name2 : string
var timoe : int := 0
var again : string := "Yes"
var done : boolean := false


procedure drawx (spotx, spoty : int)
    var x1 := spotx * 100
    var y1 := spoty * 100
    var x2 := (spotx * 100) + 100
    var y2 := (spoty * 100) + 100
    drawline (x1, y1, x2, y2, red)
    drawline (x1, y1 + 100, x2, y2 - 100, red)
end drawx

procedure start
    put "Enter player ones name"
    get name1
    put "Enter player twos name"
    get name2
    cls
    put name1, " is x."
    put name2, " is o."
    put name1, " starts."
    put "To play click on the square you want to put your symbol"
    locate (10, 10)
    put "The game starts in: "
    delay (3000)
    cls
    locate (10, 20)
    put "5"
    delay (1000)
    cls
    locate (10, 20)
    put "4"
    delay (1000)
    cls
    locate (10, 20)
    put "3"
    delay (1000)
    cls
    locate (10, 20)
    put "2"
    delay (1000)
    cls
    locate (10, 20)
    put "1"
    delay (1000)
    cls
    locate (10, 20)
    put "Go"
    delay (500)
    cls
end start


procedure drawo (midx, midy : int)
    var x1 := (midx * 100) + 50
    var y1 := (midy * 100) + 50
    var rad := 50

    drawoval (x1, y1, rad, rad, blue)
end drawo

procedure drawgrid
    drawline (100, 0, 100, 300, black)
    drawline (200, 0, 200, 300, black)
    drawline (0, 100, 300, 100, black)
    drawline (0, 200, 300, 200, black)
end drawgrid

procedure check
    %Checks veritcal
    if board (0, 0) = board (0, 1) and board (0, 1) = board (0, 2) and full (0, 0) = true and full (0, 1) = true and full (0, 2) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
        done := true

    end if
    if board (1, 0) = board (1, 1) and board (1, 1) = board (1, 2) and full (1, 0) = true and full (1, 1) = true and full (1, 2) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
        done := true
    end if
    if board (2, 0) = board (2, 1) and board (2, 1) = board (2, 2) and full (2, 0) = true and full (2, 1) = true and full (2, 2) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
        done := true
    end if
    %Checks Horizontal
    if board (0, 0) = board (1, 0) and board (1, 0) = board (2, 0) and full (0, 0) = true and full (1, 0) = true and full (2, 0) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
        done := true
    end if
    if board (0, 1) = board (1, 1) and board (1, 1) = board (2, 1) and full (0, 1) = true and full (1, 1) = true and full (2, 1) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
        done := true
    end if

    if board (0, 2) = board (1, 2) and board (1, 2) = board (2, 2) and full (0, 2) = true and full (1, 2) = true and full (2, 2) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
        done := true
    end if

    %checks diagonal
    if board (0, 0) = board (1, 1) and board (1, 1) = board (2, 2) and full (0, 0) = true and full (1, 1) = true and full (2, 2) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
        done := true
    end if

    if board (0, 2) = board (1, 1) and board (1, 1) = board (2, 0) and full (0, 2) = true and full (1, 1) = true and full (2, 0) = true then
        if turn = false then
            put "Congradulations", name1, "you won!"
        elsif turn = true then
            put "Congradulations", name2, "you won!"
        end if
        done := true
    end if

end check

fcn Game_Draw : boolean
    if full (0, 0) = full (0, 1) and full (0, 1) = full (0, 2) and full (0, 2) = full (1, 0) and full (1, 0) = full (1, 1) and full (1, 1) = full (1, 2) and full (1, 2) = full (2, 0) and
            full (2, 0) = full (2, 1) and full (2, 1) = full (2, 2) and full (2, 2) = true then
        put "The Game is a Draw!"
        result true

    else
        result false
    end if
end Game_Draw


fcn Game_Won : boolean
    if board (0, 0) = board (0, 1) and board (0, 1) = board (0, 2) and full (0, 0) = true and full (0, 1) = true and full (0, 2) = true or %%Vertical check
            board (1, 0) = board (1, 1) and board (1, 1) = board (1, 2) and full (1, 0) = true and full (1, 1) = true and full (1, 2) = true or
            board (2, 0) = board (2, 1) and board (2, 1) = board (2, 2) and full (2, 0) = true and full (2, 1) = true and full (2, 2) = true or
            board (0, 0) = board (1, 0) and board (1, 0) = board (2, 0) and full (0, 0) = true and full (1, 0) = true and full (2, 0) = true or %%Horizontal check
            board (0, 1) = board (1, 1) and board (1, 1) = board (2, 1) and full (0, 1) = true and full (1, 1) = true and full (2, 1) = true or
            board (0, 2) = board (1, 2) and board (1, 2) = board (2, 2) and full (0, 2) = true and full (1, 2) = true and full (2, 2) = true or
            board (0, 0) = board (1, 1) and board (1, 1) = board (2, 2) and full (0, 0) = true and full (1, 1) = true and full (2, 2) = true or %%Diagnal check
            board (0, 2) = board (1, 1) and board (1, 1) = board (2, 0) and full (0, 2) = true and full (1, 1) = true and full (2, 0) = true then
        if turn = false then
            put "Congradulations ", name1, " you won!"
        elsif turn = true then
            put "Congradulations ", name2, " you won!"
        end if
        Input.Pause %%to show the players who won
        result true
    end if
    result false
end Game_Won


procedure game

    loop

        mousewhere (x, y, z)
        if z = 1 and x < 100 and y < 100 and full (0, 0) = false then
            if turn = false and full (0, 0) = false then
                drawo (0, 0)

                turn := true
                full (0, 0) := true
                board (0, 0) := "o"

            end if
            if turn = true and full (0, 0) = false then
                drawx (0, 0)

                turn := false
                full (0, 0) := true
                board (0, 0) := "x"

            end if

        elsif z = 1 and x < 100 and y < 200 and y > 100 and full (0, 1) = false then
            if turn = false and full (0, 1) = false then
                drawo (0, 1)
                turn := true
                full (0, 1) := true
                board (0, 1) := "o"

            end if
            if turn = true and full (0, 1) = false then
                drawx (0, 1)
                turn := false
                full (0, 1) := true
                board (0, 1) := "x"

            end if
        elsif z = 1 and x < 100 and y < 300 and y > 200 and full (0, 2) = false then
            if turn = false and full (0, 2) = false then
                drawo (0, 2)
                turn := true
                full (0, 2) := true
                board (0, 2) := "o"

            end if
            if turn = true and full (0, 2) = false then
                drawx (0, 2)
                turn := false
                full (0, 2) := true
                board (0, 2) := "x"

            end if
        elsif z = 1 and x > 100 and x < 200 and y < 100 then
            if turn = false and full (1, 0) = false then
                drawo (1, 0)
                turn := true
                full (1, 0) := true
                board (1, 0) := "o"

            end if
            if turn = true and full (1, 0) = false then
                drawx (1, 0)
                turn := false
                full (1, 0) := true
                board (1, 0) := "x"

            end if
        elsif z = 1 and x > 100 and x < 200 and y > 100 and y < 200 then
            if turn = false and full (1, 1) = false then
                drawo (1, 1)
                turn := true
                full (1, 1) := true
                board (1, 1) := "o"

            end if
            if turn = true and full (1, 1) = false then
                drawx (1, 1)
                turn := false
                full (1, 1) := true
                board (1, 1) := "x"

            end if
        elsif z = 1 and x > 100 and x < 200 and y > 200 and y < 300 then
            if turn = false and full (1, 2) = false then
                drawo (1, 2)
                turn := true
                full (1, 2) := true
                board (1, 2) := "o"

            end if
            if turn = true and full (1, 2) = false then
                drawx (1, 2)
                turn := false
                full (1, 2) := true
                board (1, 2) := "x"

            end if
        elsif z = 1 and x > 200 and x < 300 and y < 100 then
            if turn = false and full (2, 0) = false then
                drawo (2, 0)
                turn := true
                full (2, 0) := true
                board (2, 0) := "o"

            end if
            if turn = true and full (2, 0) = false then
                drawx (2, 0)
                turn := false
                full (2, 0) := true
                board (2, 0) := "x"

            end if
        elsif z = 1 and x > 200 and x < 300 and y > 100 and y < 200 then
            if turn = false and full (2, 1) = false then
                drawo (2, 1)
                turn := true
                full (2, 1) := true
                board (2, 1) := "o"

            end if
            if turn = true and full (2, 1) = false then
                drawx (2, 1)
                turn := false
                full (2, 1) := true
                board (2, 1) := "x"

            end if
        elsif z = 1 and x > 200 and x < 300 and y > 200 and y < 300 then
            if turn = false and full (2, 2) = false then
                drawo (2, 2)
                turn := true
                full (2, 2) := true
                board (2, 2) := "o"

            end if
            if turn = true and full (2, 2) = false then
                drawx (2, 2)
                turn := false
                full (2, 2) := true
                board (2, 2) := "x"

            end if


        end if

        exit when Game_Won = true or Game_Draw = true

    end loop



end game
loop
    start
    drawgrid
    game
    cls
    if Game_Won = true or Game_Draw = true then
        for a : 0 .. 2
            for b : 0 .. 2
                full (a, b) := false
                board (a, b) := " "
            end for
        end for
    end if
    put "Would you like to play again? Yes or No"
    get again
    exit when again not= "Yes"
end loop

I am now looking into adding an AI. 


Thanks Again!

-----------------------------------
TokenHerbz
Tue Feb 08, 2011 3:59 pm

RE:Tic Tac Toe Game Problem
-----------------------------------
No no no!! All wrong!! lol...

Please Re-read my post and try to understand what Iv'e done and try to fix your code to respond the knowledge in that post!

If you don't even try I won't be of assistance anymore!!  Read it carefully!

-----------------------------------
TerranceN
Tue Feb 08, 2011 5:49 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
@TokenHerbz: What did he do wrong? He is no longer using the check procedure (even though it is still in his code), and he can restart his game, the two main points of your post.

Anyway, I would recommend breaking that large if statement into smaller functions such as HorizontalCheck, VerticalCheck, DiagonalCheck, to make that complex boolean statement MUCH easier to read and understand.

The section of code where you handle the mouse clicking on a grid square could be refactored a lot. Instead of having the code to check the turn and whether the grid square is full in each block of code for each grid square, find the coordinates of the grid square clicked on and save them in variables, which you can use to check if the grid square is full in, like this


var clickedTileX, clickedTileY : int := -1

% figure out what tiles were clicked and store them in the variables above, then

if (full(clickedTileX, clickedTileY)) then
    full(clickedTileX, clickedTileY) := true
	
    if (turn) then
        drawx(clickedTileX, clickedTileY)
        board(clickedTileX, clickedTileY) := "x"
    else
        drawo(clickedTileX, clickedTileY)
        board(clickedTileX, clickedTileY) := "o"
    end if
    turn := ~turn
end if


Also, the method you use to find the clicked tile could be improved. The way you are currently doing it is what I would call the "Button" method. You treat everything as a button, with defined bounds you check when you click. This will work of course, but it will mean a more complicated way of managing all those buttons, or a lot of typing. Fortunately, since this is a grid with no spaces in between grid squares, we can just use integer division (the 'div' command in Turing) to divide the x-value of some point by the x-size of the grid squares, to find the x index of the tile that contains the point. The same thing can be done with Y values. Here is an example:


type GridPoint:
    record
        x : int
        y : int
    end record
%

const gridTilesX := 3
const gridTilesY := 3

var selectedTile : GridPoint
selectedTile.x := -1
selectedTile.y := -1

var gridTileSizeX, gridTileSizeY := 100
var grid : array 0..gridTilesX-1 of array 0..gridTilesY-1 of int
var mouseX, mouseY, mouseButton : int := 0

fcn GetTileContainingPoint(pointX : int, pointY : int) : GridPoint
    var selected : GridPoint

    if ((pointX > 0 and pointX < maxx)
    and (pointY > 0 and pointY < maxy)) then
        selected.x := pointX div gridTileSizeX
        selected.y := pointY div gridTileSizeY
    else
        selected.x := -1
        selected.y := -1
    end if
    
    result selected
end GetTileContainingPoint

var winID : int := Window.Open(
    "graphics:"
    + intstr(gridTilesX * gridTileSizeX)
    + ";"
    + intstr(gridTilesY * gridTileSizeY)
    +",offscreenonly")

loop
    Mouse.Where(mouseX, mouseY, mouseButton)
    
    if (mouseButton > 0) then
        exit
    end if

    selectedTile := GetTileContainingPoint(mouseX, mouseY)

    cls
    
    for i : 0..gridTilesX-1
        for j : 0..gridTilesY-1
            var topLeftX : int := i * gridTileSizeX
            var topLeftY : int := j * gridTileSizeY
            
            if (i = selectedTile.x and j = selectedTile.y) then
                Draw.FillBox(
                    topLeftX,
                    topLeftY,
                    topLeftX + gridTileSizeX,
                    topLeftY + gridTileSizeY,
                    yellow)
            else
                Draw.FillBox(
                    topLeftX,
                    topLeftY,
                    topLeftX + gridTileSizeX,
                    topLeftY + gridTileSizeY,
                    black)
            end if
        end for
    end for
    
    Window.Update(winID)
    
    Time.DelaySinceLast(33)
end loop

Window.Close(winID)


Hope that helps.

-----------------------------------
compstudent
Tue Feb 08, 2011 6:15 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Token, I understand that I should recode my game procedure to make it much shorter, faster and simpler. I would if I had the time, but at the moment I am happy that it works. I also copied the wrong version - new one had taken the check out. 

Thank you for the reply Terrence - good to know for other projects (although will thankfully get to use Java from now on). 

As for making an AI - from what I have seen people have just made long if statements for all the possible situations. Is that the best way to go or is there a simpler way. 

Thanks

-----------------------------------
TokenHerbz
Tue Feb 08, 2011 6:42 pm

RE:Tic Tac Toe Game Problem
-----------------------------------
you could make 2 kinds of AI.

A very basic one that chooses randomly of the left over locations which may or may not "block" your win.

Or you could code a lengthier one, which will be impossible to beat, however you could add chance percent of hitting that spot or not etc.  

Lots you could do with that. :)

-----------------------------------
compstudent
Tue Feb 08, 2011 11:14 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Could you please elaborate on how to go about making a lengthier one. How I am currently thinking about it would be to loop through to find any two in a row or column or diagonal and block that.

-----------------------------------
compstudent
Wed Feb 09, 2011 5:35 pm

Re: Tic Tac Toe Game Problem
-----------------------------------
Hi,

I am close to finished (I think). I have made an AI that just blocks the win. I am now having problems with the one player game play. 


procedure game1player

    turn := false
    loop

        if turn = false then
            mousewhere (x, y, z)
            if z = 1 and x < 100 and y < 100 and full (0, 0) = false then

                drawx (0, 0)
                turn := true
                full (0, 0) := true
                board (0, 0) := "x"



            elsif z = 1 and x < 100 and y < 200 and y > 100 and full (0, 1) = false then

                drawx (0, 1)
                turn := true
                full (0, 1) := true
                board (0, 1) := "x"

            elsif z = 1 and x < 100 and y < 300 and y > 200 and full (0, 2) = false then

                drawx (0, 2)
                turn := true
                full (0, 2) := true
                board (0, 2) := "x"

            elsif z = 1 and x > 100 and x < 200 and y < 100 then

                drawx (1, 0)
                turn := true
                full (1, 0) := true
                board (1, 0) := "x"


            elsif z = 1 and x > 100 and x < 200 and y > 100 and y < 200 then

                drawx (1, 1)
                turn := true
                full (1, 1) := true
                board (1, 1) := "x"


            elsif z = 1 and x > 100 and x < 200 and y > 200 and y < 300 then

                drawx (1, 2)
                turn := true
                full (1, 2) := true
                board (1, 2) := "x"


            elsif z = 1 and x > 200 and x < 300 and y < 100 then

                drawx (2, 0)
                turn := true
                full (2, 0) := true
                board (2, 0) := "x"


            elsif z = 1 and x > 200 and x < 300 and y > 100 and y < 200 then

                drawx (2, 1)
                turn := true
                full (2, 1) := true
                board (2, 1) := "x"


            elsif z = 1 and x > 200 and x < 300 and y > 200 and y < 300 then

                drawx (2, 2)
                turn := true
                full (2, 2) := true
                board (2, 2) := "x"




            end if
        end if

        if turn = true then
            AI
            drawo (x, y)
            turn := false
        end if

        exit when Game_Won = true or Game_Draw = true

    end loop



end game1player


I am not sure what is wrong, however after x goes, it will not draw an o.
