Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # Name: module1
- # Purpose:
- #
- # Author: User
- #
- # Created: 18/12/2012
- # Copyright: (c) User 2012
- # Licence: <your licence>
- #-------------------------------------------------------------------------------
- #tictactoe board
- import random
- board = [0,1,2,
- 3,4,5,
- 6,7,8]
- def game():
- print (board[0],'|',board[1],'|',board[2])
- print ('----------')
- print (board[3],'|',board[4],'|',board[5])
- print ('----------')
- print (board[6],'|',board[7],'|',board[8])
- def check(char, spot1, spot2, spot3):
- if board[spot1] == char and board[spot2] == char and board[spot3] == char:
- return True
- def checkAll (char):
- if check (char, 0, 1, 2):
- return True
- if check (char, 1, 4, 7):
- return True
- if check (char, 2, 5, 8):
- return True
- if check (char, 6, 7, 8):
- return True
- if check (char, 3, 4, 5):
- return True
- if check (char, 0, 1, 2):
- return True
- if check (char, 2, 4, 6):
- return True
- if check (char, 0, 4, 8):
- return True
- while True:
- p1 = input("Player 1, where do you want to place your marker?")
- p1 = int(p1)
- if str(board[p1]) ! = 'x' and str(board[p1]) ! = 'o':
- board[p1] = 'x'
- if checkAll('x') == True:
- print "Player 1 wins!"
- break
- break
- while True:
- p2 = input("Player 2, where would you like to place your marker?")
- p2 = int(p2)
- if str(board[p2]) ! = 'x' and str(board[p2]) ! = 'o':
- str(board[p2]) = 'o'
- if checkAll('o') == True:
- print "Player 2 wins!"
- break
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement