本文整理汇总了Python中board.Board.makeMove方法的典型用法代码示例。如果您正苦于以下问题:Python Board.makeMove方法的具体用法?Python Board.makeMove怎么用?Python Board.makeMove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类board.Board
的用法示例。
在下文中一共展示了Board.makeMove方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNoMove
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
def testNoMove(self):
ai = PseudoRandomAI()
board = Board()
board.makeMove(0,'X')
board.makeMove(1,'O')
board.makeMove(2,'X')
board.makeMove(3,'O')
board.makeMove(4,'X')
board.makeMove(5,'O')
board.makeMove(6,'X')
board.makeMove(7,'O')
board.makeMove(8,'X')
self.assertEqual(ai.getNextMove(board, 'X'), None)
示例2: board
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
class Game:
"""
whole game object
maintain some game status
including a game board ( class Board )
delegate work to different handlers
"""
def __init__(self):
#initialize and start the game
self.board = Board()
self.userHandler = UserHandler()
""" ******** You can control the search broadth for each layer here, the default is 20"""
self.searchHandler = SearchHandler(self.board,20)
self.uiHandler = UIHandler(self.board)
self.run()
def run(self):
self.uiHandler.printInit()
self.uiHandler.printBoard() #the initial board state
while True:
# (OldCoord,newCoord) in the form of ((0,1),(4,3)),illegal intentions are dealt with by userHandler
(oldCoord,newCoord) = self.userHandler.askLegalMove(self.board)
self.board.makeMove((oldCoord,newCoord)) #player move, board state updated
self.uiHandler.printBoard()
if self.checkOver():
exit()
(oldCoord,newCoord) = self.searchHandler.getBestMove(4)
print "*************Computer's move ",(oldCoord,newCoord),"****************"
self.board.makeMove((oldCoord,newCoord)) # computer move, board state updated
self.uiHandler.printBoard()
if self.checkOver():
exit()
def checkOver(self):
winner = self.board.checkWinner()
if winner:
print "Game over!", winner, "Won !"
return True
else:
return False
示例3: testNextMove
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
def testNextMove(self):
ai = PseudoRandomAI()
# If corners are free, choose the corners
board = Board()
self.assertIn(ai.getNextMove(board,'X'), [0,2,6,8])
board.makeMove(0,'X')
board.makeMove(1,'O')
board.makeMove(2,'X')
board.makeMove(6,'O')
self.assertEqual(ai.getNextMove(board, 'X'), 8)
# If corners, aren't free, choose the center if free
board.makeMove(8,'X')
self.assertEqual(ai.getNextMove(board, 'X'), 4)
# If center is not free, choose any other
board.makeMove(4,'O')
self.assertIn(ai.getNextMove(board,'X'), [1,3,5,7])
示例4: playGame
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
def playGame(self, args):
board = Board(args)
blackTurn = True
message = ''
passed = False
while True:
move = self.graphics.getTurn(board, blackTurn, message)
if move == 'pass':
if passed:
return 'game over', board
blackTurn = not blackTurn
message = ''
passed = True
else:
result = board.makeMove(move, blackTurn)
if result == 'success':
blackTurn = not blackTurn
message = ''
passed = False
else:
message = result
示例5: len
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
b.makeMove(mv)
if ply >= len(pv): pv.append(mv)
else: pv[ply] = mv
ply += 1
#wplen = len(winpaths)
search(depth-1,False)
#if isRoot and len(winpaths) > wplen: print(len(winpaths)-wplen)
ply -= 1
b.unmakeMove(mv)
b = Board(9)
print(b)
doSearch(4)
print("nodes = {0}".format(nodes))
print("winpaths = {0}".format(len(winpaths)))
pick = input("type 'p' to step through all winpaths, otherwise press enter to quit: ")
if pick == 'p':
for wp in winpaths:
print("******************************")
bb = Board(9)
print(wp)
print(bb)
for mv in wp:
bb.makeMove(mv)
print(bb)
input("(press enter for next winpath)")
示例6: main
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
def main():
b = Board()
intro = open('readme.txt', 'r')
SIDE = True #True if X, false if O
for line in intro:
print(line)
print("What do you want to play? Type 'pc' for Player vs. Computer or 'pp' for Player vs. Player")
line = input()
if line == 'pc':
print("I haven't done this yet!")
else:
while (line not in exitTerms and (b.xFree < 15 or b.oFree < 15)):
print(b)
roll1 = random.randint(1,6)
roll2 = random.randint(1,6)
turnComplete = False
total = roll1 + roll2
if (roll1 == roll2):
total *= 2
print("You rolled a " + str(roll1) + " and a " + str(roll2) + " giving you a total of " + str(total) + " moves.")
if SIDE:
print("X, what do you want to do?")
else:
print("O, what do you want to do?")
while (not turnComplete and line not in exitTerms and total > 0):
line = input()
space,steps = parseInput(line)
jailFreed = False
jailCase = False
if (SIDE and b.xJail > 0):
jailCase = True
if (not SIDE and b.oJail > 0):
jailCase = True
if (space == 100 and steps == 100):
total = 0
break
if (space == 101 and steps == 101):
break
if (steps != roll1 and steps != roll2 and steps != (roll1 + roll2) and steps != 100 and not jailCase):
print("You didn't roll that!")
continue
# Must jump to beginning of loop
space = space - 1
if (steps == 0 and SIDE and b.xJail > 0):
tempSteps = space - 18
if (tempSteps != roll1 and tempSteps != roll2):
print("You didn't roll that!")
continue
else:
jailFreed = True
elif (steps == 0 and not SIDE and b.oJail > 0):
tempSteps = space + 1
if (tempSteps != roll1 and tempSteps != roll2):
print("You didn't roll that!")
continue
else:
jailFreed = True
if (space < 0 or space > 23 or steps < 0):
print("That move is not allowed. Please try again.")
continue
#Same deal here.
move, response = b.makeMove(space, SIDE, steps)
print(response)
if (move and jailFreed):
steps = tempSteps
if move:
total = total - steps
print(b)
print("You have " + str(total) + " steps left.")
SIDE = not SIDE
示例7: testEmptyBoard
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
def testEmptyBoard(self):
board = Board()
self.assertEqual(board.isEmpty(), True)
board.makeMove(0, 'X')
self.assertEqual(board.isEmpty(), False)
示例8: testBoardFull
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
def testBoardFull(self):
board = Board()
for i in range(9):
board.makeMove(i,'X')
self.assertEqual(board.isFull(), True)
示例9: testInvalidMove
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
def testInvalidMove(self):
board = Board()
board.makeMove(0,'X')
self.assertEqual( board.makeMove(0,'X'), False)
示例10: testWinner
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
def testWinner(self):
board = Board()
board.makeMove(0,'X')
board.makeMove(1,'X')
board.makeMove(2,'X')
self.assertEqual(board.isWinner('X'), True)
示例11: testIsSpaceFree
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import makeMove [as 别名]
def testIsSpaceFree(self):
board = Board()
board.makeMove(5, 'O')
self.assertEqual(board.isSpaceFree(5), False)