Hardware Reference
In-Depth Information
Listing 3-10 continued
board[move[0]] = 'O'
print 'My move is ',move[0] + 1
moved = True
return moved
def win_block(): #move to win or block
global board
testBoard = board
players = ['O','X']
moveMade = False
for moveTry in players:
for square in range(0, len(board) ) :
if testBoard[square] == ' ' and moveMade == False:
testBoard[square] = moveTry
if checkWin(moveTry,testBoard):
board[square] = 'O'
moveMade = True
print 'My move is ',square + 1
else:
testBoard[square] = ' ' # retract move
return moveMade
def swapPlayer(player):
if player == 'X' :
player = 'O'
else:
player = 'X'
return player
def getMove(player):
global board
correct_number = False
while correct_number == False :
square = raw_input('Square to place the '+ player + ' ')
try:
square = int(square)
except:
square = -2
square -= 1 # make input number ;
match internal representation
if square >= 0 and square < 10 : # number in range
if board[square] == ' ' : # if it is blank
board[square] = player
Search WWH ::




Custom Search