示例#1
0
 def test_easy_position(self):
     position = [
         TTTPiece.X,
         TTTPiece.O,
         TTTPiece.X,
         TTTPiece.X,
         TTTPiece.E,
         TTTPiece.O,
         TTTPiece.E,
         TTTPiece.E,
         TTTPiece.O,
     ]
     test_board = TTTBoard(position, TTTPiece.X)
     actual = find_best_move(test_board)
     self.assertEqual(6, actual)
示例#2
0
 def test_hard_position(self):
     '''このテストは期待をどうやって求めたのか'''
     position = [
         TTTPiece.X,
         TTTPiece.E,
         TTTPiece.E,
         TTTPiece.E,
         TTTPiece.E,
         TTTPiece.O,
         TTTPiece.O,
         TTTPiece.X,
         TTTPiece.E,
     ]
     test_board = TTTBoard(position, TTTPiece.X)
     actual = find_best_move(test_board)
     self.assertEqual(1, actual)
示例#3
0
def main():
    board = C4Board()
    while True:
        human_move = get_player_move(board)
        board = board.move(human_move)
        if board.is_win:
            print("You win!")
            return
        elif board.is_draw:
            print("Draw.")
            return
        ai_move = find_best_move(board, 3)
        print(f"AI move is {ai_move}.")
        board = board.move(ai_move)
        print(board)
        if board.is_win:
            print("You lose...")
            return
        elif board.is_draw:
            print("Draw.")
            return