Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Functions
- #
- # Draw a grid(done)
- # Find out who goes first(done)
- # Rules!(done)
- # Devise a method for entering moves(done)
- # Get next move
- # Update grid(done)
- # Check wins/draws
- # If true then:
- # Congratulate player
- # Else rerun from 'Get next move' and switch player
- # Data needed
- #
- # Record of moves
- # Player one name
- # Player two name
- # Current player
- # Check wins/draws
- # Input = record of moves
- # Output = 'x', 'o', 'd', 'f'
- # a = moves()
- # b = whofirst()
- def gridupdate():
- print ("Here is the grid!")
- print (" ")
- print (" | 0 | 1 | 2 |")
- print (" -|-----|-----|-----|")
- print (" | | | |")
- print ("0 | ", a[0][0]," | ", a[0][1]," | ", a[0][2]," |")
- print (" | | | |")
- print (" -|-----|-----|-----|")
- print (" | | | |")
- print ("1 | ", a[1][0]," | ", a[1][1]," | ", a[1][2]," |")
- print (" | | | |")
- print (" -|-----|-----|-----|")
- print (" | | | |")
- print ("2 | ", a[2][0]," | ", a[2][1]," | ", a[2][2]," |")
- print (" | | | |")
- print (" -|-----|-----|-----|")
- def rules():
- print ("Welcome to my Noughts and Crosses game! The rules are simple")
- print ("Each player takes one turn after the other, this happens until:")
- print ("- 3 of the same marker are next to each other")
- print ("- No more spaces left")
- print (" ")
- print ("Just follow through the instructions and get ready.")
- print ("This is the most intensive Noughts and Crosses game ever!")
- print ("When promted, enter your names")
- print ("Once the game has started, use the coordinates on the grid to place your marker 'eg. 0,0'")
- print ("Now just enjoy...")
- print ("---------------------------------------------------------------------------------------------")
- input ("Shall we begin? Just hit enter when you're ready")
- def whofirst():
- playernames = []
- p1 = input ("Who is player one? ")
- print (" ")
- print ("You are noughts")
- print (" ")
- p2 = input ("Who is player two? ")
- print (" ")
- print ("You are crosses")
- print (" ")
- playernames = ([p1, p2])
- print ("---------------------------------------------------------------------------------------------")
- return playernames
- def nextmove(whichplayer):
- if whichplayer == 1:
- print (b[whichplayer])
- whichplayer = whichplayer - 1
- else:
- print (b[whichplayer])
- whichplayer = whichplayer + 1
- nextplace = input ("Where would you like to go?")
- nextplace = str(nextplace)
- return nextplace
- def movecalc(c):
- move1 = c[0]
- move2 = c[1]
- move1 = int(move1)
- move2 = int(move2)
- if whichplayer == 1:
- a[c[0]][c[1]] = 'O'
- else:
- a[c[0]][c[1]] = 'X'
- def moves():
- movelist = ([[' ', ' ', ' ',],[' ', ' ', ' ',],[' ', ' ', ' ',]])
- return movelist
- # Main Program
- whichplayer = 1
- NumMoves = 0
- a = moves()
- #rules()
- #gridupdate()
- #print (" ")
- #print ("So then!")
- #print (" ")
- b = whofirst()
- while NumMoves < 9:
- c = nextmove(whichplayer)
- d = movecalc(c)
- NumMoves = NumMoves + 1
Add Comment
Please, Sign In to add comment