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

Username:   Password: 
 RegisterRegister   
 help with tic tac toe program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
littenburg




PostPosted: Tue Jan 22, 2008 6:20 pm   Post subject: help with tic tac toe program

hello, i have made a new tic tac toe program, and i need it to work, can someone please help finishing the program?

code:
var sq1 : int := -999
var sq2 : int := -999
var sq3 : int := -999
var sq4 : int := -999
var sq5 : int := -999
var sq6 : int := -999
var sq7 : int := -999
var sq8 : int := -999
var sq9 : int := -999
var u1 : int := -999
var u2 : int := -999
var u3 : int := -999
var u4 : int := -999
var u5 : int := -999
var c1 : int := -999
var c2 : int := -999
var c3 : int := -999
var c4 : int := -999
var c5 : int := -999

var justonce : int
var cpmr : int
var hm : int
var command : string

function taken (x : int) : boolean

    if x = c1 or x = c2 or x = c3 or x = c4 or x = c5 or x = u1 or x = u2 or x = u3 or x = u4 or x = u5 or
            x < 1 or x > 9 then
        result true
    else
        result false
    end if

end taken

procedure plot_move (player : string (1), move : int)


    cpmr := move
    if cpmr = 1     %2
            then
        sq1 := 2
        drawoval (52, 332, 40, 40, 3)
    else
        if cpmr = 2     %9
                then
            sq2 := 9
            drawoval (197, 326, 40, 40, 3)
        else
            if cpmr = 3     %4
                    then
                sq3 := 4
                drawoval (326, 326, 40, 40, 3)
            else
                if cpmr = 4     %7
                        then
                    sq4 := 7
                    drawoval (57, 196, 40, 40, 3)
                else
                    if cpmr = 5     %5
                            then
                        sq5 := 3
                        drawoval (197, 201, 40, 40, 3)
                    else
                        if cpmr = 6     %3
                                then
                            sq6 := 3
                            drawoval (329, 200, 40, 40, 3)
                        else
                            if cpmr = 7     %6
                                    then
                                sq7 := 6
                                drawoval (60, 63, 40, 40, 3)
                            else
                                if cpmr = 8     %1
                                        then
                                    sq8 := 1
                                    drawoval (198, 62, 40, 40, 3)
                                else
                                    if cpmr = 9     %8
                                            then
                                        sq9 := 8
                                        drawoval (327, 60, 40, 40, 3)
                                    end if
                                end if
                            end if
                        end if
                    end if
                end if
            end if
        end if
    end if



    if hm = 1     %2
            then
        sq1 := 2
        drawline (23, 375, 97, 293, 4)
        drawline (97, 369, 12, 302, 4)
    else
        if hm = 2     %9
                then
            sq2 := 9
            drawline (151, 380, 233, 300, 4)
            drawline (233, 375, 146, 291, 4)
        else
            hm := move
            if hm = 3     %4
                    then
                sq3 := 4
                drawline (284, 383, 373, 286, 4)
                drawline (376, 390, 284, 287, 4)
            else
                if hm = 4     %7
                        then
                    sq4 := 7
                    drawline (7, 256, 110, 158, 4)
                    drawline (111, 242, 8, 151, 4)
                else
                    if hm = 5     %5
                            then
                        sq5 := 5
                        drawline (154, 245, 241, 161, 4)
                        drawline (242, 246, 153, 156, 4)
                    else
                        if hm = 6     %3
                                then
                            sq6 := 3
                            drawline (289, 246, 373, 153, 4)
                            drawline (376, 251, 283, 153, 4)
                        else
                            if hm = 7     %6
                                    then
                                sq7 := 6
                                drawline (18, 104, 101, 23, 4)
                                drawline (106, 102, 6, 21, 4)
                            else
                                if hm = 8     %1
                                        then
                                    sq8 := 1
                                    drawline (151, 108, 241, 12, 4)
                                    drawline (223, 104, 155, 12, 4)
                                else
                                    if hm = 9     %8
                                            then
                                        sq9 := 8
                                        drawline (291, 104, 369, 22, 4)
                                        drawline (359, 103, 284, 22, 4)
                                    end if
                                end if
                            end if
                        end if
                    end if
                end if
            end if
        end if
    end if
end plot_move


procedure pc_move
    Text.Locate (2, 50)
    put "Computer's turn, please wait"
    delay (450)
    loop
        randint (cpmr, 1, 9)
        exit when not (taken (cpmr))
    end loop
    plot_move ("c", cpmr)

end pc_move

procedure user_move
    Text.Locate (2, 50)
    put "Your turn"
    get hm
    loop
        exit when not (taken (cpmr))
    end loop
    plot_move ("u", hm)
end user_move



%below, i made it so that the introduction appears in the centre of the screen
procedure CentreText (s : string, row : int)
    locate (row, (maxcol - length (s)) div 2)
    put s
    View.Update
end CentreText

procedure first_screen
    colourback (black)
    cls
    colour (white)
    delay (650)
    CentreText ("IT'S THE TIC TAC TOE GAME!!!", maxrow div 2 - 7)
    CentreText ("Created by Isaac K-S", maxrow div 2 - 5)
    delay (700)
    CentreText ("~Now Loading Game~", maxrow div 2 - 3)
    delay (500)
    CentreText (". . .           ", maxrow div 2 - 1) %all this is just for fun, i wanted it to look cool, and make it look like it was actually loading somthing.
    delay (500)
    CentreText ("           . . .", maxrow div 2 - 1)
    delay (500)
    CentreText (". . .           ", maxrow div 2 - 1)
    delay (500)
    CentreText ("           . . .", maxrow div 2 - 1)
    delay (500)
    CentreText (". . .           ", maxrow div 2 - 1)
    delay (500)
    CentreText ("           . . .", maxrow div 2 - 1)
    delay (500)
    CentreText (". . .           ", maxrow div 2 - 1)
    delay (500)
    CentreText ("           . . .", maxrow div 2 - 1)
    delay (501)
    CentreText ("READY!", maxrow div 2 - 1)
    delay (650)
    CentreText ("YAY", maxrow div 2 - 0)
end first_screen

procedure draw_screen
    delay (500)
    cls
    colourback (10)
    drawfillbox (135, 0, 131, maxy, 4)
    drawfillbox (265, 0, 269, maxy, 4)
    drawfillbox (385, 135, 0, 131, 4)
    drawfillbox (385, 265, 0, 269, 4)
    colour (black)
end draw_screen






%first_screen
draw_screen

plot_move
Sponsor
Sponsor
Sponsor
sponsor
Nick




PostPosted: Tue Jan 22, 2008 6:22 pm   Post subject: RE:help with tic tac toe program

if you took the time to color it green you couldn't just have [[/]code] and [[i]/code] or [syntax="turing"]and[/syntax]?
littenburg




PostPosted: Tue Jan 22, 2008 6:24 pm   Post subject: RE:help with tic tac toe program

yeah, i probably could have, but im asking for help, not some random coments like that
Nick




PostPosted: Tue Jan 22, 2008 6:26 pm   Post subject: RE:help with tic tac toe program

I am helping see if I didn't wanna take the time to look at it because no code tags how many other people will?

also can a mod edit my post fixing the [i]
littenburg




PostPosted: Tue Jan 22, 2008 6:28 pm   Post subject: RE:help with tic tac toe program

well, thank you for the help, im sorry i dont understand, and what about this [i]?
Clayton




PostPosted: Tue Jan 22, 2008 6:32 pm   Post subject: RE:help with tic tac toe program

The first thing I'm seeing here is a random initialization of all of your variables to -999. I must ask... why? Also, look into arrays in the Turing Walkthrough, as they will make your code much more readable, and help you in the long run dramatically. Also... never, ever, ever, make some wait through a loading screen that's doing absolutely nothing. In your case, you're making the user wait 6 1/2 seconds of nothing. This is bad. Instead, the better thing to do would be to have some sort of escape key for the user to press once they are ready to move on.

As a side note. We (the mods) appreciate other people trying to enlighten others to the rules, however, let's just stop for now okay? The mods are perfectly able to let others know of the rules. This is directed toward everyone, and should in no way be taken as a direct comment to someone.
littenburg




PostPosted: Tue Jan 22, 2008 8:02 pm   Post subject: RE:help with tic tac toe program

thankyou for your help, i appreciate it, i put the loading thing there, because the teacher was give 10% out for making the program look exciting and interesting, that just made it look cool...and for the arrays, the teacher said we could use arrays, but it would make it more confusing in the future, so i didnt even bother, but thankyou for your help, i appreciate it, anymore tips?
Myst




PostPosted: Tue Jan 22, 2008 9:49 pm   Post subject: RE:help with tic tac toe program

man your tic tack toe game is pretty good ^_^ i didn't make mine go against a computer -_-" just a 2 player game. Still pretty good i suppose. I'll show it to you once i hand it in to my teacher.

be warned 700 + lines of coding XD
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Tue Jan 22, 2008 10:28 pm   Post subject: RE:help with tic tac toe program

Umm...

littenburg wrote:
the teacher said we could use arrays, but it would make it more confusing in the future, so i didnt even bother


Your teacher told you this? If so... I've lost all faith in the educational system. They will make your program infinitely easier to read and understand. This effect becomes more apparent as you write longer, more complex programs.
Gooie




PostPosted: Tue Jan 22, 2008 11:37 pm   Post subject: Re: RE:help with tic tac toe program

Clayton @ January 22nd, 10:28 pm wrote:
Umm...

littenburg wrote:
the teacher said we could use arrays, but it would make it more confusing in the future, so i didnt even bother


Your teacher told you this? If so... I've lost all faith in the educational system. They will make your program infinitely easier to read and understand. This effect becomes more apparent as you write longer, more complex programs.


My teacher said the same thing at the beginning of the semester... It is sad isn't it. The problem is that they teach to the lowest common denominator.
ericfourfour




PostPosted: Tue Jan 22, 2008 11:46 pm   Post subject: RE:help with tic tac toe program

I doubt that is what the teacher meant Clayton. I don't think a school board would hire a retard. littenburg was probably exaggerating. I notice a lot of people claim to be better at programming than their teachers.
Sean




PostPosted: Wed Jan 23, 2008 8:21 am   Post subject: Re: help with tic tac toe program

Our teacher Gooie, did not say not to use Arrays, just that we were behind in class and would not have the chance to get to arrays. She recommened them for a lot of program ideas that I had, and we would of learned how to properly utilize them if we had the time and commitment that we gave from everyone else.
littenburg




PostPosted: Wed Jan 23, 2008 2:33 pm   Post subject: RE:help with tic tac toe program

he did say that they would make it harder, in this project, sorry, i should have made it more clear
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  [ 13 Posts ]
Jump to:   


Style:  
Search: