Computer Science Canada Need help with my tic tac toe |
Author: | SZ94 [ Thu Jun 17, 2010 7:16 pm ] |
Post subject: | Need help with my tic tac toe |
i need help with the cats game issue in which they tie. For our projects we have to make the program until the game is unwinable and i need some help currently i am just doing all the combos and thats taking forever and i need help stat on this i attached and here: %%Tick Tack Toe setscreen ("Graphics:500;500") put "press enter" %variables var turnplayer : boolean %the turns var TL, TM, TR : boolean := false %lines in the top var ML, MM, MR : boolean := false %lines in the middle var BL, BM, BR : boolean := false %lines in the bottom var player : int %random number provider var playgame : boolean := true %to play the game var endgame : boolean := false %to end the game var ans : string %who ever has possesion of the box var xtl, xtm, xtr, xml, xmm, xmr, xbl, xbm, xbr : boolean %true will be player ones and player twos is false %random picks either player one or two to go first player := 1 if player = 1 then put "Player one goes 1st" turnplayer := true %explains that player one is false else %Player 2's 1st put "Player two goes 1st" turnplayer := false %explains player two is true end if Input.Pause cls %draws the board Draw.ThickLine (100, 300, 100, 0, 10, brightred) Draw.ThickLine (200, 0, 200, 300, 10, brightred) Draw.ThickLine (0, 200, 300, 200, 10, brightred) Draw.ThickLine (0, 100, 300, 100, 10, brightred) proc TopLeft if TL = false then %hasn't been used if turnplayer = true then %this is for player one drawfillmapleleaf (0, 200, 100, 300, black) % top left square turnplayer := false %player 2 turn xtl := true %%player 1 possesion else %%its player 2 drawfillstar (0, 200, 100, 300, black) % top left turnplayer := true %%player 1 turn xtl := false %%player 2 has it end if TL := true end if end TopLeft proc TopMid if TM = false then %%empty space if turnplayer = true then %%1st player drawfillmapleleaf (100, 200, 200, 300, black) %top middle turnplayer := false %player 2 turn xtm := true %player 1's possesion else %%its player 2 drawfillstar (100, 200, 200, 300, black) %top middle turnplayer := true %player 1 turn xtm := false %player 2's possesion end if TM := true end if end TopMid proc TopRight if TR = false then %empty if turnplayer = true then %%1st player drawfillmapleleaf (200, 200, 300, 300, black) %top right turnplayer := false %player 2 turn xtr := true %player 1's possesion else %%its player 2 drawfillstar (200, 200, 300, 300, black) %top right turnplayer := true %player 1 turn xtr := false %player 2's possesion end if TR := true end if end TopRight proc MidLeft if ML = false then %empty if turnplayer = true then %%1st player drawfillmapleleaf (0, 100, 100, 200, black) %middle left turnplayer := false %player 2 turn xml := true %player 1's possesion else %%its player 2 drawfillstar (0, 100, 100, 200, black) %middle left turnplayer := true %player 1 turn xml := false %player 2's possesion end if ML := true end if end MidLeft proc MidMid if MM = false then %empty if turnplayer = true then %%1st player drawfillmapleleaf (100, 100, 200, 200, black) %middle middle turnplayer := false %player 2 turn xmm := true %player 1's possesion else %%its player 2 drawfillstar (100, 100, 200, 200, black) %middle middle turnplayer := true %player 1 turn xmm := false %player 2's possesion end if MM := true end if end MidMid proc MidRight if MR = false then %empty if turnplayer = true then %%1st player drawfillmapleleaf (300, 100, 200, 200, black) % middle right turnplayer := false %player 2 turn xmr := true %player 1's possesion else drawfillstar (300, 100, 200, 200, black) % middle right turnplayer := true %player 1 turn xmr := false %player 2's possesion end if MR := true end if end MidRight proc BotLeft if BL = false then %empty if turnplayer = true then %%1st player drawfillmapleleaf (0, 0, 100, 100, black) %bottom left turnplayer := false %player 2 turn xbl := true %player 1's possesion else %%its player 2 drawfillstar (0, 0, 100, 100, black) %bottom left turnplayer := true %player 1 turn xbl := false %player 2's possesion end if BL := true end if end BotLeft proc BotMid if BM = false then %empty if turnplayer = true then %%1st player drawfillmapleleaf (100, 0, 200, 100, black) %bottom middle turnplayer := false %player 2 turn xbm := true %player 1's possesion else %%its player 2 drawfillstar (100, 0, 200, 100, black) %bottom middle turnplayer := true %player 1 turn xbm := false %player 2's possesion end if BM := true end if end BotMid proc BotRight if BR = false then %empty if turnplayer = true then %%1st player drawfillmapleleaf (200, 0, 300, 100, black) % bottom right turnplayer := false %player 2 turn xbr := true %player 1's possesion else %%its player 2 drawfillstar (200, 0, 300, 100, black) % bottom right turnplayer := true %player 1 turn xbr := false %player 2's possesion end if BR := true end if end BotRight proc win %horizontal victories if TL = true and xtl = true and TM = true and xtm = true and TR = true and xtr = true then endgame := true %%to end game Draw.ThickLine (0, 250, 300, 250, 10, brightred) put "player one wins" %%player 2 gets top 3 tiles elsif TL = true and xtl = false and TM = true and xtm = false and TR = true and xtr = false then endgame := true %%to end game Draw.ThickLine (0, 250, 300, 250, 10, brightred) put "player two wins" %%player 1 gets mid 3 tiles elsif ML = true and xml = true and MM = true and xmm = true and MR = true and xmr = true then endgame := true %%to end game Draw.ThickLine (0, 150, 300, 150, 10, brightred) put "player one wins" %%player 1 gets middle 3 tiles elsif ML = true and xml = false and MM = true and xmm = false and MR = true and xmr = false then endgame := true %%to end game Draw.ThickLine (0, 150, 300, 150, 10, brightred) put "player two wins" %%player 1 gets bot 3 tiles elsif BL = true and xbl = true and BM = true and xbm = true and BR = true and xbr = true then endgame := true %%to end game Draw.ThickLine (0, 50, 300, 50, 10, brightred) put "player one wins" %%player 1 gets bot 3 tiles elsif BL = true and xbl = false and BM = true and xbm = false and BR = true and xbr = false then endgame := true %%to end game Draw.ThickLine (0, 50, 300, 50, 10, brightred) put "player two wins" %verticle victories %%player 1 gets left row elsif TL = true and xtl = true and ML = true and xml = true and BL = true and xbl = true then endgame := true Draw.ThickLine (50, 300, 50, 0, 10, brightred) put "player one wins" %%player 2 gets left row elsif TL = true and xtl = false and ML = true and xml = false and BL = true and xbl = false then endgame := true Draw.ThickLine (50, 300, 50, 0, 10, brightred) put "player two wins" %%player 1 gets mid row elsif TM = true and xtm = true and MM = true and xmm = true and BM = true and xbm = true then endgame := true Draw.ThickLine (150, 300, 150, 0, 10, brightred) put "player one wins" %%player 2 gets mid row elsif TM = true and xtm = false and MM = true and xmm = false and BM = true and xbm = false then endgame := true Draw.ThickLine (150, 300, 150, 0, 10, brightred) put "player two wins" %%player 1 gets right row elsif TR = true and xtr = true and MR = true and xmr = true and BR = true and xbr = true then endgame := true Draw.ThickLine (250, 300, 250, 0, 10, brightred) put "player one wins" %%player 2 gets eight row elsif TR = true and xtr = false and MR = true and xmr = false and BR = true and xbr = false then endgame := true Draw.ThickLine (250, 300, 250, 0, 10, brightred) put "player two wins" %diagonal win %%player 1 wins elsif TL = true and xtl = true and MM = true and xmm = true and BR = true and xbr = true then endgame := true Draw.ThickLine (0, 300, 300, 0, 10, brightred) put "player one wins" %%player 2 wins elsif TL = true and xtl = false and MM = true and xmm = false and BR = true and xbr = false then endgame := true Draw.ThickLine (0, 300, 300, 0, 10, brightred) put "player two wins" %%player 1 wins elsif TR = true and xtr = true and MM = true and xmm = true and BL = true and xbl = true then endgame := true Draw.ThickLine (0, 0, 300, 300, 10, brightred) put "player one wins" %%player 2 wins elsif TR = true and xtr = false and MM = true and xmm = false and BL = true and xbl = false then endgame := true Draw.ThickLine (0, 0, 300, 300, 10, brightred) put "player two wins" % one box cats game elsif TL = true and TM = true and TR = true and ML = true and MM = true and MR = true and BL = true and BM = true and BR = true then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TR = true and TM = true and xtr = true and ML = true and MM = true and MR = true and BL = true and BM = true and BR = true then endgame := true Draw.ThickLine (0, 0, 300, 300, 10, brightred) Draw.ThickLine (0, 300, 300, 0, 10, brightred) put "cats game" elsif TL = true and xtl = false and TM = true and xtm = true and TR = true and xtr = false and ML = true and xml = false and BL = true and xbl = true and BM = true and xbm = false and MM = true and xmm = true then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "cats game" elsif TL = true and xtl = false and TR = true and xtr = true and ML = true and xml = true and MM = true and xmm = false and MR = true and xmr = false and BL = true and xbl = false and BR = true and xbr = true then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = true and TR = true and xtr = false and ML = true and xml = false and MM = true and xmm = true and MR = true and xmr = true and BL = true and xbl = true and BR = true and xbr = false then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = false and TR = true and xtr = false and BM = true and xbm = false and MM = true and xmm = true and BL = true and TM = true and xtm = true and BL = true and BR = true and BR = true then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = true and TR = true and xtr = true and BM = true and xbm = true and MM = true and xmm = false and BL = true and TM = true and xtm = false and BL = false and BR = true and xbr = false then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = true and TM = true and xtm = true and TR = true and xtr = false and ML = true and xml = false and BL = true and xbl = true and MM = true and xmm = false and MR = true and xmr = true then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = true and TM = true and xtm = true and TR = true and xtr = false and ML = true and xml = false and BL = true and xbl = true and MM = true and xmm = false and MR = true and xmr = true then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = true and TM = true and xtm = false and TR = true and xtr = true and ML = true and xml = true and BL = true and xbl = false and BM = true and xbm = true and MM = true and xmm = false then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = false and TM = true and xtm = true and TR = true and xtr = false and MR = true and xmr = false and BR = true and xbr = true and BM = true and xbm = false and MM = true and xmm = true then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = true and TM = true and xtm = false and TR = true and xtr = true and MR = true and xmr = true and BR = true and xbr = false and BM = true and xbm = true and MM = true and xmm = false then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = true and BM = true and xbm = true and BR = true and xbr = false and ML = true and xml = false and BL = true and xbl = true and MM = true and xmm = false and MR = true and xmr = true then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL = true and xtl = false and BM = true and xbm = false and BR = true and xbr = true and ML = true and xml = true and BL = true and xbl = false and MM = true and xmm = true and MR = true and xmr = false then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL= true and xtl= true and TM= true and xtm= false and TR= true and xtr= false and ML= true and xml=false and MM=true and xmm= true and MR= true and xmr= true and BL= true and xbl= true and BM=true and xbm=false and BR= false then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL= true and xtl= false and TM= true and xtm= true and TR= true and xtr= true and ML= false and MM=true and xmm= false and MR= true and xmr= false and BL= true and xbl= false and BM=true and xbm=true and BR= true and xbr= true then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL= true and xtl= true and TM= true and xtm= false and TR= false and ML= true and xml= true and MM=true and xmm= false and MR= true and xmr= true and BL= true and xbl= false and BM=true and xbm=true and BR= true and xbr= false then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" elsif TL= true and xtl= false and TM= false and TR= true and xtr= true and ML= true and xml= true and MM=true and xmm= true and MR= true and xmr= false and BL= true and xbl= false and BM=true and xbm=true and BR= true and xbr= false then endgame := true drawline (0, 0, 300, 300, brightred) drawline (300, 0, 0, 300, brightred) put "NO WINNERS FTW" end if end win proc game if turnplayer = true then locate (8,1) put "It is black maple leaf's turn" elsif turnplayer = false then locate (8, 1) put "It is black star's turn" end if var mx, my, mb : int %Mouse chords Mouse.Where (mx, my, mb) if mb = 1 then %%if mouse is clicked if mx <= 100 and mx >= 0 and my <= 300 and my >= 200 then %%Location for top left tile TopLeft elsif mx <= 200 and mx >= 100 and my <= 300 and my >= 200 then %%location for top mid tile TopMid elsif mx <= 300 and mx >= 200 and my <= 300 and my >= 200 then %%top right location TopRight elsif mx <= 100 and mx >= 0 and my <= 200 and my >= 100 then %%Midleft tile location MidLeft elsif mx <= 200 and mx >= 100 and my <= 200 and my >= 100 then %%midmid tile loc MidMid elsif mx <= 300 and mx >= 200 and my <= 200 and my >= 100 then %%mid right loc MidRight elsif mx <= 100 and mx >= 0 and my <= 100 and my >= 0 then %%Bot left tile BotLeft elsif mx <= 200 and mx >= 100 and my <= 100 and my >= 0 then %%Mot mid tile BotMid elsif mx <= 300 and mx >= 200 and my <= 100 and my >= 0 then %%Bot Right tile loc BotRight end if end if win end game %to reset and play game loop if playgame = true then game end if if endgame = true then put "Would you like a replay of the game of tic tac toe?" get ans if ans = 'yes' then playgame := true endgame := false TL := false TM := false TR := false ML := false MM := false MR := false BL := false BM := false BR := false cls Draw.ThickLine (100, 300, 100, 0, 10, brightred) Draw.ThickLine (200, 0, 200, 300, 10, brightred) Draw.ThickLine (0, 200, 300, 200, 10, brightred) Draw.ThickLine (0, 100, 300, 100, 10, brightred) else exit end if end if end loop cls put "GG no rematch" |
Author: | Monduman11 [ Thu Jun 17, 2010 8:06 pm ] | ||||
Post subject: | RE:Need help with my tic tac toe | ||||
umm i played it and for most of the senerios where i tied it actually tied so i dont understand what the problem is umm use
to make your writing in the program not flicker and if possible next time please put your code in syntax
so that it easier to understand |
Author: | Cezna [ Fri Jun 18, 2010 11:23 am ] | ||||
Post subject: | Re: RE:Need help with my tic tac toe | ||||
Monduman11 @ Thu Jun 17, 2010 8:06 pm wrote: umm i played it and for most of the senerios where i tied it actually tied so i dont understand what the problem is
umm use
to make your writing in the program not flicker Don't forget to use cls before you draw everything. You only need to use setscreen once at the top of the file, and use View.Update after you draw everything to display it. Monduman11 @ Thu Jun 17, 2010 8:06 pm wrote: and if possible next time please put your code in syntax
so that it easier to understand Monduman is also right here. For those people who aren't going to bother downloading (or can't download), they may still be able to help you by just reading through your code, but no one is going to read through all of that code if it is not in syntax tags. |