# Untitled

a guest
Jan 8th, 2013
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def game(board):
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):
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
23.
24. board = [0,1,2,
25. 3,4,5,
26. 6,7,8]
27.
28. winner = False
29. while not winner:
30. game(board)
31. while True: #loop until unoccupied square found
32. p1 = input("Player 1, where do you want to place your marker?")
33. p1 = int(p1)
34. if 0 <= p1 <= 8:
35. if str(board[p1]) != 'x' and str(board[p1]) != 'o':
36. board[p1] = 'x'
37. game(board)
38. break
39. else:
40. print ("That square is occupied")
41. if checkAll('x') == True:
42. print ("Player 1 wins!")
43. winner = True
44. break
45.
46.
47. while True:
48. p2 = input("Player 2, where would you like to place your marker?")
49. p2 = int(p2)
50. if 0 <= p2 <= 8:
51. if str(board[p2]) != 'x' and str(board[p2]) != 'o':
52. board[p2] = 'o'
53. break
54. else:
55. print ("That square is occupied")
56.
57. if checkAll('o') == True:
58. print ("Player 2 wins!")
59. winner = True
60. break
61.
62. else:
63. if checkAll('x') == False:
64. print('Nobody has won.')
65. winner = True #make the program ask if you want to play again
66. break
67. if checkAll('o') == False:
68. print('Nobody has won.')
69. winner = True #make the program ask if you want to play again
70. break
71.
72. while winner:
73. print ("Thank-you for playing.")
74. break