本文整理汇总了Python中board.Board.getInverse方法的典型用法代码示例。如果您正苦于以下问题:Python Board.getInverse方法的具体用法?Python Board.getInverse怎么用?Python Board.getInverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类board.Board
的用法示例。
在下文中一共展示了Board.getInverse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: trainWithSelf
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getInverse [as 别名]
def trainWithSelf(winner, game_count):
for game in tqdm(range(game_count)):
game_board = Board()
game_history = []
turn_count = 0
tie_flag = False
while game_board.checkGameStatus(AI_COLOR) == CONTINUE:
if turn_count > 100:
tie_flag = True
break
player_move = winner.getNextMove(game_board.getInverse())
game_history.append((game_board, player_move.getInverse()))
game_board = Board(game_board.applyMove(player_move.getInverse()))
if game_board.checkGameStatus(AI_COLOR) == LOSE:
break
ai_move = winner.getNextMove(game_board)
game_history.append((game_board, ai_move))
game_board = Board(game_board.applyMove(ai_move))
turn_count += 1
if tie_flag:
winner.updateWeights(game_history, status = TIE)
else:
winner.updateWeights(game_history, status = game_board.checkGameStatus(AI_COLOR))
return winner
示例2: playLoser
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getInverse [as 别名]
def playLoser(winner, game_count):
loser = Learner()
wins = 0
losses = 0
ties = 0
for game in tqdm(range(game_count)):
game_board = Board()
winner_moves = []
loser_moves = []
game_history = []
turn_count = 0
tie_flag = False
while game_board.checkGameStatus(AI_COLOR) == CONTINUE:
if turn_count > 100:
tie_flag = True
break
loser_move = loser.getNextMove(game_board.getInverse())
loser_moves.append(loser_move.getInverse())
assert(loser_move is not None and game_board is not None)
game_history.append((game_board, loser_move.getInverse()))
game_board = Board(game_board.applyMove(loser_move.getInverse()))
if game_board.checkGameStatus(AI_COLOR) == LOSE:
break
# assert (temp != game_board)
winner_move = winner.getNextMove(game_board)
assert(winner_move is not None and game_board is not None)
game_history.append((game_board, winner_move))
winner_moves.append(winner_move)
game_board = Board(game_board.applyMove(winner_move))
turn_count += 1
if tie_flag or game_board.checkGameStatus(AI_COLOR) == TIE:
ties += 1
elif game_board.checkGameStatus(AI_COLOR) == WIN:
wins += 1
elif game_board.checkGameStatus(AI_COLOR) == LOSE:
losses += 1
return { WIN : wins, LOSE : losses, TIE : ties}
示例3: get_AI_move
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getInverse [as 别名]
def get_AI_move():
try:
current_board = pickle.load(open("current_board.pkl", "rb"))
except:
current_board = Board()
pickle.dump(current_board, open("current_board.pkl", "wb"))
try:
learner = pickle.load(open("learner.pkl", "rb"))
except:
learner = Learner()
pickle.dump(learner, open("learner.pkl", "wb"))
# Use the learner to make an AI move
move = learner.getNextMove(current_board.getInverse())
next_board = move[0].getInverse()
# Save move into pickle file
pickle.dump(next_board, open("current_board.pkl", "wb"))
next_board_array = next_board.getArray()
return json.dumps(next_board_array.tolist())
示例4: BoardTestCase
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getInverse [as 别名]
class BoardTestCase(ut.TestCase):
def setUp(self):
self.board = Board()
def tearDown(self):
self.board = None
def testGetMovesList(self):
def testWithGrid(grid = None, red_c = 7, black_c = 7):
self.board = Board(new_grid = grid)
self.board.getMoveList(RED)
self.board.getMoveList(BLACK)
# self.board.printBoard()
# print "red moves:", len(self.board.getMoveList(RED))
# print "black moves:", len(self.board.getMoveList(BLACK))
self.assertEqual(len(self.board.getMoveList(RED)), red_c, \
'incorrect number of RED moves available')
self.assertEqual(len(self.board.getMoveList(BLACK)), black_c, \
'incorrect number of BLACK moves available')
# for board, move in self.board.getMoveList(BLACK) + self.board.getMoveList(RED):
# print
# move.printMove()
# board.printBoard()
# ---------- My Testing -----------------
# self.board = Board(new_grid = RED_EASY_LOOKAHEAD)
# for bd in self.board.getMoveList(RED):
# bd[0].printBoard()
testWithGrid()
testWithGrid(KINGS, 6, 1)
testWithGrid(CORNER, 6, 2)
self.board = Board(new_grid = NEW_KING)
test_board = Board(new_grid = NEW_KING_RESULT)
self.assertTrue(any(bd[0] == test_board for bd in self.board.getMoveList(RED)))
def testApplyMove(self):
for board, move in self.board.getMoveList(BLACK) + self.board.getMoveList(RED):
self.assertEqual(board, self.board.applyMove(move), \
'move_board does not match move applied to self.board')
self.board = Board(new_grid = NEW_KING)
for board, move in self.board.getMoveList(BLACK) + self.board.getMoveList(RED):
self.assertEqual(board, self.board.applyMove(move), \
'move_board does not match move applied to self.board')
self.board = Board(new_grid = BLK_DOUBLE)
for board, move in self.board.getMoveList(BLACK) + self.board.getMoveList(RED):
self.assertEqual(board, self.board.applyMove(move), \
'move_board does not match move applied to self.board')
def testVerifyMove(self):
'''
For board verify that a move is valid and in the set of moves
'''
# self.board = Board(new_grid = START_MOVE_B_9_13).getInverse()
self.board.getMoveList(RED)
self.board.getMoveList(BLACK)
self.assertTrue(self.board.verifyMove(BLACK, next_board = Board(new_grid = START_MOVE_B_9_13)))
self.assertTrue(self.board.verifyMove(RED, next_board = Board(new_grid = START_MOVE_R_21_17)))
def testGetInverse(self):
self.assertEqual(self.board.getInverse().getInverse(), self.board, \
'inverse of inverse of board is not original board')
示例5: trainWithLoser
# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import getInverse [as 别名]
def trainWithLoser(winner, game_count):
loser = Learner()
# game_board = Board()
for game in tqdm(range(game_count)):
game_board = Board()
winner_moves = []
loser_moves = []
game_history = []
turn_count = 0
tie_flag = False
while game_board.checkGameStatus(AI_COLOR) == CONTINUE:
if turn_count > 100:
tie_flag = True
break
loser_move = loser.getNextMove(game_board.getInverse())
loser_moves.append(loser_move.getInverse())
assert(loser_move is not None and game_board is not None)
game_history.append((game_board, loser_move.getInverse()))
# loser_move.printMove()
# loser_move.getInverse().printMove()
# game_board.printBoard()
# temp = game_board
# game_board.printBoard()
game_board = Board(game_board.applyMove(loser_move.getInverse()))
# game_board.printBoard()
# assert(temp != game_board)
# loser_move.getInverse().printMove()
# print turn_count
# game_board.printBoard()
if game_board.checkGameStatus(AI_COLOR) == LOSE:
break
# assert (temp != game_board)
winner_move = winner.getNextMove(game_board)
assert(winner_move is not None and game_board is not None)
game_history.append((game_board, winner_move))
# winner_move.printMove()
winner_moves.append(winner_move)
# temp = game_board
game_board = Board(game_board.applyMove(winner_move))
# game_history.append(game_board)
# game_board.printBoard()
turn_count += 1
# print game
if not tie_flag and game_board.checkGameStatus(AI_COLOR) != TIE:
winner.updateWeights(game_history, status = game_board.checkGameStatus(AI_COLOR))
# winner.updateWeights(game_board, loser_moves, winner_moves, game_history = game_history)
else:
winner.updateWeights(game_history, status = TIE)
# game_board.printBoard()
# winner.updateWeights(game_board, loser_moves, winner_moves, status = TIE, game_history = game_history)
loser_moves = None
winner_moves = None
return winner