
-----------------------------------
Ennsy_908
Mon Jun 04, 2007 7:54 am

Only Half My Check Works
-----------------------------------
I don't know why/how to fix my check so it will work for all directions (horizontal, vertical, diagonal), for all spots in Tic Tac Toe.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                         Tic Tac Toe                                         %
%                                    Created by: Chris Enns                                   %
%                                          ICS 3M1                                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

var Check : array 1 .. 3, 1 .. 3 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0)
var x, y, b : int

% Instructions
put "                                        TicTacToe"
put "The object of the game is to get a row of X's or a row of O's before your"
put "opponent. These rows can be vertical, horizontal, or diagonal. Click Where"
put "                          you want to place an X or an O"
put ""
put "********************************************************************************"
put ""
put " IMPORTANT: DO NOT CLICK WHHERE AN X OR O HAS ALREADY BEEN DRAWN. THIS WILL"
put "           CAUSE AN OVERLAP AND YOU WILL NOT BE ABLE TO FINISH THE GAME"
put ""
put "********************************************************************************"
put ""
put " Click anywhere to play"
loop
    Mouse.Where (x, y, b)
    if b = 1 then
        cls
        exit when b = 1
    end if
end loop
proc GameBoard     %Draws Game Board
    Draw.ThickLine (325, 150, 580, 150, 5, 16)     % Bottom Horizontal Line
    Draw.ThickLine (410, 65, 410, 320, 5, 16)     % Left Vertical Line
    Draw.ThickLine (495, 65, 495, 320, 5, 16)     % Right Vertical Line
    Draw.ThickLine (325, 235, 580, 235, 5, 16)     % Top Horizontal Line
end GameBoard

proc XBL     % Draws X in bottom left spot
    Draw.ThickLine (335, 140, 400, 70, 3, 12)
    Draw.ThickLine (335, 70, 400, 140, 3, 12)
end XBL

proc XBM     % Draws X in bottom middle spot
    Draw.ThickLine (420, 140, 485, 70, 3, 12)
    Draw.ThickLine (420, 70, 485, 140, 3, 12)
end XBM

proc XBR     % Draws X in bottom right spot
    Draw.ThickLine (505, 140, 570, 70, 3, 12)
    Draw.ThickLine (505, 70, 570, 140, 3, 12)
end XBR

proc XML     % Draws X in middle left spot
    Draw.ThickLine (335, 225, 400, 160, 3, 12)
    Draw.ThickLine (335, 160, 400, 225, 3, 12)
end XML

proc XM     % Draws X in middle spot
    Draw.ThickLine (420, 225, 485, 160, 3, 12)
    Draw.ThickLine (420, 160, 485, 225, 3, 12)
end XM

proc XMR     % Draws X in middle right spot
    Draw.ThickLine (505, 225, 580, 160, 3, 12)
    Draw.ThickLine (505, 160, 580, 225, 3, 12)
end XMR

proc XTL     % Draws X in top left spot
    Draw.ThickLine (335, 315, 400, 245, 3, 12)
    Draw.ThickLine (335, 246, 400, 315, 3, 12)
end XTL

proc XTM     % Draws X in top middle spot
    Draw.ThickLine (420, 315, 485, 245, 3, 12)
    Draw.ThickLine (420, 245, 485, 315, 3, 12)
end XTM

proc XTR     % Draws X in top right spot
    Draw.ThickLine (505, 315, 580, 245, 3, 12)
    Draw.ThickLine (505, 245, 580, 315, 3, 12)
end XTR

proc OBL     % Draw O in bottom left spot
    Draw.Oval (367, 107, 30, 30, blue)
    Draw.Oval (367, 107, 37, 37, blue)
    Draw.Fill (367, 140, blue, blue)
end OBL

proc OBM     % Draws O in bottom middle spot
    Draw.Oval (452, 107, 30, 30, blue)
    Draw.Oval (452, 107, 37, 37, blue)
    Draw.Fill (452, 140, blue, blue)
end OBM

proc OBR     % Draws O in bottom right spot
    Draw.Oval (537, 107, 30, 30, blue)
    Draw.Oval (537, 107, 37, 37, blue)
    Draw.Fill (537, 140, blue, blue)
end OBR

proc OML     % Draws O in middle left spot
    Draw.Oval (367, 192, 30, 30, blue)
    Draw.Oval (367, 192, 37, 37, blue)
    Draw.Fill (367, 223, blue, blue)
end OML

proc OM     % Draws O in middle spot
    Draw.Oval (452, 192, 30, 30, blue)
    Draw.Oval (452, 192, 37, 37, blue)
    Draw.Fill (452, 223, blue, blue)
end OM

proc OMR     % Draws O in middle right spot
    Draw.Oval (537, 192, 30, 30, blue)
    Draw.Oval (537, 192, 37, 37, blue)
    Draw.Fill (537, 223, blue, blue)
end OMR

proc OTL     % Draws O in top left spot
    Draw.Oval (367, 277, 30, 30, blue)
    Draw.Oval (367, 277, 37, 37, blue)
    Draw.Fill (367, 310, blue, blue)
end OTL

proc OTM     % Draws O in top middle spot
    Draw.Oval (452, 277, 30, 30, blue)
    Draw.Oval (452, 277, 37, 37, blue)
    Draw.Fill (452, 310, blue, blue)
end OTM

proc OTR     % Draws O in top right spot
    Draw.Oval (537, 277, 30, 30, blue)
    Draw.Oval (537, 277, 37, 37, blue)
    Draw.Fill (537, 310, blue, blue)
end OTR

proc DrawX     % Draws x in place selected

    loop
        Mouse.Where (x, y, b)

        if b = 1 and x > 325 and x < 410
                and y > 65 and y < 150 then
            XBL
            Check (1, 1) := 1
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 65 and y < 150 then
            XBM
            Check (1, 2) := 1
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 65 and y < 150 then
            XBR
            Check (1, 3) := 1
            exit when b = 1
        elsif b = 1 and x > 325 and x < 410
                and y > 150 and y < 235 then
            XML
            Check (2, 1) := 1
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 150 and y < 235 then
            XM
            Check (2, 2) := 1
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 150 and y < 235 then
            XMR
            Check (2, 3) := 1
            exit when b = 1
        elsif b = 1 and x > 325 and x < 410
                and y > 235 and y < 320 then
            XTL
            Check (3, 1) := 1
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 235 and y < 320 then
            XTM
            Check (3, 2) := 1
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 235 and y < 320 then
            XTR
            Check (3, 3) := 1
            exit when b = 1
        end if
    end loop
end DrawX

proc DrawO     % Draws O in place selected
    var x, y, b : int
    loop
        Mouse.Where (x, y, b)

        if b = 1 and x > 325 and x < 410
                and y > 65 and y < 150 then
            OBL
            Check (1, 1) := 2
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 65 and y < 150 then
            OBM
            Check (1, 2) := 2
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 65 and y < 150 then
            OBR
            Check (1, 3) := 2
            exit when b = 1
        elsif b = 1 and x > 325 and x < 410
                and y > 150 and y < 235 then
            OML
            Check (2, 1) := 2
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 150 and y < 235 then
            OM
            Check (2, 2) := 2
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 150 and y < 235 then
            OMR
            Check (2, 3) := 2
            exit when b = 1
        elsif b = 1 and x > 325 and x < 410
                and y > 235 and y < 320 then
            OTL
            Check (3, 1) := 2
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 235 and y < 320 then
            OTM
            Check (3, 2) := 2
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 235 and y < 320 then
            OTR
            Check (3, 3) := 2
            exit when b = 1
        end if
    end loop
end DrawO




function Win : boolean
    for i : 1 .. 3

        if Check (i, 1) not= 0 and Check (i, 1) = Check (i, 2)
                and Check (i, 1) = Check (i, 3) then
            result true
        end if

        if Check (1, i) not= 0 and Check (1, i) = Check (2, i)
                and Check (1, i) = Check (3, i) then
            result true
        end if
        if Check (2, 2) not= 0 and Check (1, 1) = Check (2, 2)
                and Check (2, 2) = Check (3, 3) then
            result true

        elsif Check (2, 2) not= 0 and Check (1, 3) = Check (2, 2)
                and Check (2, 2) = Check (3, 1) then
            result true
        end if
        result false
    end for
end Win

GameBoard
DrawX
delay (500)
DrawO
delay (500)
DrawX
delay (500)
DrawO
delay (500)
DrawX
delay (500)
if Win then
    put " winner"
end if
DrawO
delay (500)
if Win then
    put " winner"
end if
put Win
DrawX
delay (500)
if Win then
    put " winner"
end if
DrawO
delay (500)
if Win then
    put " winner"
end if
DrawX
delay (500)
if Win then
    put " winner"
end if



If anyone could tell me what is wrong that would be awsome.

-----------------------------------
Ennsy_908
Fri Jun 08, 2007 8:19 am

Re: Only Half My Check Works
-----------------------------------
I also can't get it to stop outputing false when there isn't a win.

-----------------------------------
bapb10
Fri Jun 08, 2007 8:27 am

RE:Only Half My Check Works
-----------------------------------
make each row equal 15 then check if any row is equal to that
it should work but u probly wont get it done by monday
