# Untitled

a guest
Jan 9th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def game(board): #make a game board divided into 9 spaces with a number in each space
2. print (board[0],'|',board[1],'|',board[2])
3. print ('----------')
4. print (board[3],'|',board[4],'|',board[5])
5. print ('----------')
6. print (board[6],'|',board[7],'|',board[8])
7. def check(char, spot1, spot2, spot3): #check the spot asked for
8. if board[spot1] == char and board[spot2] == char and board[spot3] == char:
9. return True
10. return False
11. def checkAll (char):
12. for spot1, spot2, spot3 in [[0, 1, 2], #
13. [3, 4, 5],
14. [6, 7, 8],
15. [0, 3, 6],
16. [1, 4, 7],
17. [2, 5, 8],
18. [2, 4, 6],
19. [0, 4, 8]]:
20. if check(char, spot1, spot2, spot3):
21. return True
22. return False #return false if nobody has won
23.
24. def tie():
25. bool isFull(board){
26. bool isFull = true;
27. for i = 0 to board.length # 0 <= i <= 84.
28. if board[i] != 'x' && board[i] != 'o'
29. isFull = false;
30. break;
31.
32. return isFull;
33. }
34.
35. board = [0,1,2,
36. 3,4,5,
37. 6,7,8]
38.
39. winner = False
40. while not winner:
41. game(board)
42. while True: #loop until unoccupied square found
43. p1 = input("Player 1, where do you want to place your marker?")
44. p1 = int(p1)
45. if 0 <= p1 <= 8:
46. if str(board[p1]) != 'x' and str(board[p1]) != 'o':
47. board[p1] = 'x'
48. game(board)
49. break
50. else:
51. print ("That square is occupied")
52. if checkAll('x') == True:
53. print ("Player 1 wins!")
54. winner = True
55. break
56.
57. while True:
58. p2 = input("Player 2, where would you like to place your marker?")
59. p2 = int(p2)
60. if 0 <= p2 <= 8:
61. if str(board[p2]) != 'x' and str(board[p2]) != 'o':
62. board[p2] = 'o'
63. break
64. else:
65. print ("That square is occupied")
66.
67. if checkAll('o') == True:
68. print ("Player 2 wins!")
69. winner = True
70. break
71.
72.
73. while winner:
74. print ("Thank-you for playing.")
75. break