
-----------------------------------
Keerigan
Tue Jun 21, 2005 10:51 am

Tic-Tac-Toe(UNBEATABLE COMPUTER IF YOU WIN TELL ME!)
-----------------------------------
:arrow: For Images use your own pictures


setscreen ("graphics:905;605,position:center;center,nobuttonbar")
var u : array 1 .. 5 of int %the array that holds all of the players moves
var c : array 1 .. 5 of int %the array that holds all of the computers moves
var win : int := 0 %counter for how many wins the user obtains(but won't get any)
var lose : int := 0 %counter for how many loses the user obtains
var cat : int := 0 %counter for how many cat games were played

proc Draw_Screen
    %procedure that draws the Tic-Tac_Toe lines and
    %the counters
    cls
    drawbox (5, 5, 600, 600, green)
    drawline (205, 5, 205, 600, green)
    drawline (405, 5, 405, 600, green)
    drawline (5, 205, 600, 205, green)
    drawline (5, 405, 600, 405, green)
    locate (34, 77)
    put "WINS:"
    locate (34, 85)
    put win
    locate (35, 77)
    put "LOSES:"
    locate (35, 86)
    put lose
    locate (36, 77)
    put "CAT GAMES:"
    locate (36, 90)
    put cat
end Draw_Screen

proc Initialize
    %resets the global values to "0" and
    %used if another game will be played without closing the window
    for i : 1 .. 5
        u (i) := -999
        c (i) := -999
    end for
end Initialize

function User_Win : boolean
    %checks to see if 3 of the users moves equals 15
    %which will make the user win
    if u (1) + u (2) + u (3) = 15 then
        locate (1, 77)
        put "You Win!"
        win := win + 1 %adds to the win counter
        locate (34, 85)
        put win %puts the win counter
        result true
    elsif u (2) + u (3) + u (4) = 15 then
        locate (1, 77)
        put "You Win!"
        win := win + 1
        locate (34, 85)
        put win
        result true
    elsif u (3) + u (4) + u (5) = 15 then
        locate (1, 77)
        put "You Win!"
        win := win + 1
        locate (34, 85)
        put win
        result true
    elsif u (1) + u (3) + u (4) = 15 then
        locate (1, 77)
        put "You Win!"
        win := win + 1
        locate (34, 85)
        put win
        result true
    elsif u (1) + u (4) + u (5) = 15 then
        locate (1, 77)
        put "You Win!"
        win := win + 1
        locate (34, 85)
        put win
        result true
    elsif u (1) + u (2) + u (4) = 15 then
        locate (1, 77)
        put "You Win!"
        win := win + 1
        locate (34, 85)
        put win
        result true
    elsif u (1) + u (3) + u (5) = 15 then
        locate (1, 77)
        put "You Win!"
        win := win + 1
        locate (34, 85)
        put win
        result true
    elsif u (2) + u (4) + u (5) = 15 then
        locate (1, 77)
        put "You Win!"
        win := win + 1
        locate (34, 85)
        put win
        result true
    elsif u (2) + u (3) + u (5) = 15 then
        locate (1, 77)
        put "You Win!"
        win := win + 1
        locate (34, 85)
        put win
        result true
    end if
    result false
end User_Win

function Computer_Win : boolean
    %to check if 3 of the computers move will equal 15
    %which will make the computer win
    if c (1) + c (2) + c (3) = 15 then
        locate (1, 77)
        put "You Lose!"
        lose := lose + 1 %adds to the lose counter
        locate (35, 86)
        put lose %puts the lose counter
        result true
    elsif c (2) + c (3) + c (4) = 15 then
        locate (1, 77)
        put "You Lose!"
        lose := lose + 1
        locate (35, 86)
        put lose
        result true
    elsif c (3) + c (4) + c (5) = 15 then
        locate (1, 77)
        put "You Lose!"
        lose := lose + 1
        locate (35, 86)
        put lose
        result true
    elsif c (1) + c (3) + c (4) = 15 then
        locate (1, 77)
        put "You Lose!"
        lose := lose + 1
        locate (35, 86)
        put lose
        result true
    elsif c (1) + c (4) + c (5) = 15 then
        locate (1, 77)
        put "You Lose!"
        lose := lose + 1
        locate (35, 86)
        put lose
        result true
    elsif c (1) + c (2) + c (4) = 15 then
        locate (1, 77)
        put "You Lose!"
        lose := lose + 1
        locate (35, 86)
        put lose
        result true
    elsif c (1) + c (3) + c (5) = 15 then
        locate (1, 77)
        put "You Lose!"
        lose := lose + 1
        locate (35, 86)
        put lose
        result true
    elsif c (2) + c (4) + c (5) = 15 then
        locate (1, 77)
        put "You Lose!"
        lose := lose + 1
        locate (35, 86)
        put lose
        result true
    elsif c (2) + c (3) + c (5) = 15 then
        locate (1, 77)
        put "You Lose!"
        lose := lose + 1
        locate (35, 86)
        put lose
        result true
    end if
    result false
end Computer_Win

function taken (x : int) : boolean
    %checks to see if the move selected has already been taken
    %if true then another move will have to be made
    for i : 1 .. 5
        if x = u (i) or x = c (i) then
            result true
        end if
    end for
    result false
end taken


function Get_User_Move : int
    %gets the users move by clicking with the mouse in the
    %desired location
    var x, y, button : int
    loop
        Mouse.Where (x, y, button)
        if button = 1 then
            if x >= 5 and x < 205 and y >= 5 and y = 205 and x < 405 and y >= 205 and y = 405 and x < 600 and y >= 405 and y = 5 and x < 205 and y >= 205 and y = 5 and x < 205 and y >= 405 and y = 205 and x < 405 and y >= 5 and y = 205 and x < 405 and y >= 405 and y = 405 and x < 600 and y >= 5 and y = 405 and x < 600 and y >= 205 and y 