Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Tic Tac Toe! (Different then what you think)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Flikerator




PostPosted: Sat Mar 05, 2005 2:25 am   Post subject: Tic Tac Toe! (Different then what you think)

Alright I almost have this working 100% (Its for practise) but its not quite right. Here is the question;

http://www.ecoo.org/ecoocs/boardwide/scar1995p1.html

and here is the code I wrote;

its 427 lines long... I don't have any room really left to add things, so I have to put it here sry about that... I also have the text doc it loads from.

There is probably some usuless code but relize im very tired and all my energy comes from chips/pop so im not thinking straight...

I can't figure out why the first one doesnt work..I don't get it. If I look at my whatdotcolour for it it doesnt make any sense...

code:

(85, 315)   (200, 315)   (315,315)
(85, 200)   (200, 200)   (315,200)
(85, 85)    (85, 85)     (85,315)


code:

%Data11.txt
var window1, window2, window3 : int
window1 := Window.Open ("position:center,center,graphics:400,400")
colourback (black)
cls
colour (white)
Draw.Box (25, 25, maxx - 25, maxy - 25, grey)
Draw.Box (25, 140, maxx - 25, maxy - 25, grey)
Draw.Box (25, 260, maxx - 25, maxy - 25, grey)
Draw.Box (140, 25, maxx - 25, maxy - 25, grey)
Draw.Box (260, 25, maxx - 25, maxy - 25, grey)

var file : int
var game : array 1 .. 9 of int
var turn : string := "blue"
var value : array 1 .. 9 of int
var ch : string (1)
var winning : int := 0

proc redwin
    var redwindow : int
    redwindow := Window.Open ("position:center,center,graphics:300,200")
    put "RED WINS!"
    getch (ch)
    Window.Close (redwindow)
end redwin

proc bluewin
    var bluewindow : int
    bluewindow := Window.Open ("position:center,center,graphics:300,200")
    put "BLUE WINS!"
    getch (ch)
    Window.Close (bluewindow)
end bluewin

proc win
    %Checks if three are found in a row
    if whatdotcolour (85, 85) = red then
        if whatdotcolour (85, 200) = red and whatdotcolour (85, 315) = red then
            winning := 1
        elsif whatdotcolour (200, 85) = red and whatdotcolour (200, 315) = red then
            winning := 1
        elsif whatdotcolour (200, 200) = red and whatdotcolour (315, 315) = red then
            winning := 1
        end if
    elsif whatdotcolour (200, 85) = red and whatdotcolour (200, 200) = red whatdotcolour (200, 315) = red then
        winning := 1
    elsif whatdotcolour (315, 85) = red then
        if whatdotcolour (200, 200) = red and whatdotcolour (85, 315) = red then
            winning := 1
        elsif whatdotcolour (315, 200) = red and whatdotcolour (315, 315) = red then
            winning := 1
        end if
    elsif whatdotcolour (85, 200) = red and whatdotcolour (200, 200) = red and whatdotcolour (315, 200) = red then
        winning := 1
    elsif whatdotcolour (85, 315) = red and whatdotcolour (200, 315) = red and whatdotcolour (315, 315) = red then
        winning := 1
    end if

    if whatdotcolour (85, 85) = brightblue then
        if whatdotcolour (85, 200) = brightblue and whatdotcolour (85, 315) = brightblue then
            winning := 2
        elsif whatdotcolour (200, 85) = brightblue and whatdotcolour (200, 315) = brightblue then
            winning := 2
        elsif whatdotcolour (200, 200) = brightblue and whatdotcolour (315, 315) = brightblue then
            winning := 2
        end if
    elsif whatdotcolour (200, 85) = brightblue and whatdotcolour (200, 200) = brightblue and whatdotcolour (200, 315) = brightblue then
        winning := 2
    elsif whatdotcolour (315, 85) = brightblue then
        if whatdotcolour (200, 200) = brightblue and whatdotcolour (85, 315) = brightblue then
            winning := 2
        elsif whatdotcolour (315, 200) = brightblue and whatdotcolour (315, 315) = brightblue then
            winning := 2
        end if
    elsif whatdotcolour (85, 200) = brightblue and whatdotcolour (200, 200) = brightblue and whatdotcolour (315, 200) = brightblue then
        winning := 2
    elsif whatdotcolour (85, 315) = brightblue and whatdotcolour (200, 315) = brightblue and whatdotcolour (315, 315) = brightblue then
        winning := 2
    end if
end win

for i : 1 .. upper (value)
    value (i) := 0
end for

open : file, "DATA11.txt", get

for i : 1 .. 9
    get : file, game (i)
end for

for i : 1 .. 9
    if turn = "blue" then
        if game (i) > 9 then
            turn := "red"
        elsif game (i) = 1 and value (i) = 0 then
            Draw.FillOval (85, 85, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 2 and value (i) = 0 then
            Draw.FillOval (200, 85, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 3 and value (i) = 0 then
            Draw.FillOval (315, 85, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 4 and value (i) = 0 then
            Draw.FillOval (85, 200, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 5 and value (i) = 0 then
            Draw.FillOval (200, 200, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 6 and value (i) = 0 then
            Draw.FillOval (315, 200, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 7 and value (i) = 0 then
            Draw.FillOval (85, 315, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 8 and value (i) = 0 then
            Draw.FillOval (200, 315, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 9 and value (i) = 0 then
            Draw.FillOval (315, 315, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        else
            turn := "red"
        end if
    elsif turn = "red" then
        if game (i) > 9 and value (i) = 0 then
            turn := "blue"
            value (i) := 1
        elsif game (i) = 1 and value (i) = 0 then
            Draw.FillOval (85, 85, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 2 and value (i) = 0 then
            Draw.FillOval (200, 85, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 3 and value (i) = 0 then
            Draw.FillOval (315, 85, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 4 and value (i) = 0 then
            Draw.FillOval (85, 200, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 5 and value (i) = 0 then
            Draw.FillOval (200, 200, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 6 and value (i) = 0 then
            Draw.FillOval (315, 200, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 7 and value (i) = 0 then
            Draw.FillOval (85, 315, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 8 and value (i) = 0 then
            Draw.FillOval (200, 315, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 9 and value (i) = 0 then
            Draw.FillOval (315, 315, 40, 40, brightred)
            turn := "blue"
        else
            turn := "blue"
        end if
    end if
    win
    exit when winning > 0
    getch (ch)
end for

if winning = 1 then
    redwin
elsif winning = 2 then
    bluewin
end if

getch (ch)
Window.Close (window1)
winning := 0
window2 := Window.Open ("position:center,center,graphics:400,400")
colourback (black)
cls
colour (white)
Draw.Box (25, 25, maxx - 25, maxy - 25, grey)
Draw.Box (25, 140, maxx - 25, maxy - 25, grey)
Draw.Box (25, 260, maxx - 25, maxy - 25, grey)
Draw.Box (140, 25, maxx - 25, maxy - 25, grey)
Draw.Box (260, 25, maxx - 25, maxy - 25, grey)

turn := "blue"

for i : 1 .. upper (value)
    value (i) := 0
end for

for i : 1 .. 9
    get : file, game (i)
end for

for i : 1 .. 9
    if turn = "blue" then
        if game (i) > 9 then
            turn := "red"
        elsif game (i) = 1 and value (i) = 0 then
            Draw.FillOval (85, 85, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 2 and value (i) = 0 then
            Draw.FillOval (200, 85, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 3 and value (i) = 0 then
            Draw.FillOval (315, 85, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 4 and value (i) = 0 then
            Draw.FillOval (85, 200, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 5 and value (i) = 0 then
            Draw.FillOval (200, 200, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 6 and value (i) = 0 then
            Draw.FillOval (315, 200, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 7 and value (i) = 0 then
            Draw.FillOval (85, 315, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 8 and value (i) = 0 then
            Draw.FillOval (200, 315, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 9 and value (i) = 0 then
            Draw.FillOval (315, 315, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        else
            turn := "red"
        end if
    elsif turn = "red" then
        if game (i) > 9 and value (i) = 0 then
            turn := "blue"
            value (i) := 1
        elsif game (i) = 1 and value (i) = 0 then
            Draw.FillOval (85, 85, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 2 and value (i) = 0 then
            Draw.FillOval (200, 85, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 3 and value (i) = 0 then
            Draw.FillOval (315, 85, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 4 and value (i) = 0 then
            Draw.FillOval (85, 200, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 5 and value (i) = 0 then
            Draw.FillOval (200, 200, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 6 and value (i) = 0 then
            Draw.FillOval (315, 200, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 7 and value (i) = 0 then
            Draw.FillOval (85, 315, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 8 and value (i) = 0 then
            Draw.FillOval (200, 315, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 9 and value (i) = 0 then
            Draw.FillOval (315, 315, 40, 40, brightred)
            turn := "blue"
        else
            turn := "blue"
        end if
    end if
    win
    exit when winning > 0
    getch (ch)
end for

if winning = 1 then
    redwin
elsif winning = 2 then
    bluewin
end if

getch (ch)
Window.Close (window1)
winning := 0
window3 := Window.Open ("position:center,center,graphics:400,400")
colourback (black)
cls
colour (white)
Draw.Box (25, 25, maxx - 25, maxy - 25, grey)
Draw.Box (25, 140, maxx - 25, maxy - 25, grey)
Draw.Box (25, 260, maxx - 25, maxy - 25, grey)
Draw.Box (140, 25, maxx - 25, maxy - 25, grey)
Draw.Box (260, 25, maxx - 25, maxy - 25, grey)

turn := "blue"

for i : 1 .. upper (value)
    value (i) := 0
end for

for i : 1 .. 9
    get : file, game (i)
end for

for i : 1 .. 9
    if turn = "blue" then
        if game (i) > 9 then
            turn := "red"
        elsif game (i) = 1 and value (i) = 0 then
            Draw.FillOval (85, 85, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 2 and value (i) = 0 then
            Draw.FillOval (200, 85, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 3 and value (i) = 0 then
            Draw.FillOval (315, 85, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 4 and value (i) = 0 then
            Draw.FillOval (85, 200, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 5 and value (i) = 0 then
            Draw.FillOval (200, 200, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 6 and value (i) = 0 then
            Draw.FillOval (315, 200, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 7 and value (i) = 0 then
            Draw.FillOval (85, 315, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 8 and value (i) = 0 then
            Draw.FillOval (200, 315, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        elsif game (i) = 9 and value (i) = 0 then
            Draw.FillOval (315, 315, 40, 40, brightblue)
            turn := "red"
            value (i) := 1
        else
            turn := "red"
        end if
    elsif turn = "red" then
        if game (i) > 9 and value (i) = 0 then
            turn := "blue"
            value (i) := 1
        elsif game (i) = 1 and value (i) = 0 then
            Draw.FillOval (85, 85, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 2 and value (i) = 0 then
            Draw.FillOval (200, 85, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 3 and value (i) = 0 then
            Draw.FillOval (315, 85, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 4 and value (i) = 0 then
            Draw.FillOval (85, 200, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 5 and value (i) = 0 then
            Draw.FillOval (200, 200, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 6 and value (i) = 0 then
            Draw.FillOval (315, 200, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 7 and value (i) = 0 then
            Draw.FillOval (85, 315, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 8 and value (i) = 0 then
            Draw.FillOval (200, 315, 40, 40, brightred)
            turn := "blue"
            value (i) := 1
        elsif game (i) = 9 and value (i) = 0 then
            Draw.FillOval (315, 315, 40, 40, brightred)
            turn := "blue"
        else
            turn := "blue"
        end if
    end if
    win
    exit when winning > 0
    getch (ch)
end for
if winning = 1 then
    redwin
elsif winning = 2 then
    bluewin
end if
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: