Beispiel #1
0
def main():
    args = parse_args()
    agent = load_agent(args)
    board_size = args.board_size
    game = GameState.new_game(board_size)
    if args.playas == 'black':
        human_play = Player.black
    elif args.playas == 'white':
        human_play = Player.white
    else:
        raise ValueError('Unknown option for playas: {}'.format(args.playas))
    while not game.is_over():
        print_board(game.board)
        if game.nplayer == human_play:
            human_move = input('-- ')
            if len(human_move) > 1:
                point = point_from_coord(human_move.strip())
                move = Move.play(point)
            else:
                move = Move.pass_turn()
        else:
            move = agent.select_move(game)
        print_move(game.nplayer, move)
        game = game.apply_move(move)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Black win")
    else:
        print("White win")
Beispiel #2
0
def main():
    board_size = 3
    game = GameState.new_game(board_size)
    bots = {
        Player.black: MCTSAgent(362000, 1., 128),
        Player.white: MCTSAgent(362000, 1., 128),

        #    Player.black : MinimaxAgent(5, None),
        #    Player.white : MinimaxAgent(5, None),
    }
    while not game.is_over():
        time.sleep(0.1)

        print_board(game.board)
        bot_move = bots[game.nplayer].select_move(game)
        print_move(game.nplayer, bot_move)
        game = game.apply_move(bot_move)
    print_board(game.board)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Black won")
    else:
        print("White won")
Beispiel #3
0
def main():
    board_size = 9
    game = GameState.new_game(board_size)
    bots = {
        #    Player.black : RandomAgent(),
        #    Player.white : RandomAgent(),
        Player.black:
        FastRandomAgent(board_size),
        Player.white:
        FastRandomAgent(board_size),
    }
    while not game.is_over():
        time.sleep(0.1)  # slow down so we can observe

        #print(chr(27) + "[2J") #clear screen
        print_board(game.board)
        bot_move = bots[game.nplayer].select_move(game)
        print_move(game.nplayer, bot_move)
        game = game.apply_move(bot_move)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Black win")
    else:
        print("White win")
Beispiel #4
0
def main():
    args = parse_args()
    board_size = args.size
    game = GameState.new_game(board_size)
    #bot = RandomAgent()
    bot = MCTSAgent(100, 1., 64)
    while not game.is_over():
        print_board(game.board)
        if game.nplayer == Player.black:
            human_move = input('-- ')
            if len(human_move) > 1:
                point = point_from_coord(human_move.strip())
                move = Move.play(point)
            else:
                move = Move.pass_turn()
        else:
            move = bot.select_move(game)
        print_move(game.nplayer, move)
        game = game.apply_move(move)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Black win")
    else:
        print("White win")
Beispiel #5
0
 def play(self):
     while not self.stopped:
         if self.game_state.nplayer == self.our_color:
             self.play_our_move()
         else:
             self.play_their_move()
         print_board(self.game_state.board)
         print('Estimated result: ')
         score = AreaScore(self.game_state.board)
         print(score)
def generate_game(board_size, rounds, max_moves, temperature):
  boards, moves = [], []
  encoder = get_encoder_by_name('oneplane', board_size)
  game = GameState.new_game(board_size)
  bot = MCTSAgent(100, 1., 1)
  num_moves = 0
  while not game.is_over():
    print_board(game.board)
    move = bot.select_move(game)
    if move.is_play:
      boards.append(encoder.encode(game))
      move_one_hot = np.zeros(encoder.num_points())
      move_one_hot[encoder.encode_point(move.pt)] = 1
      moves.append(move_one_hot)
    print_move(game.nplayer, move)
    game = game.apply_move(move)
    num_moves += 1
    if num_moves > max_moves:
      break
  return np.array(boards), np.array(moves)
Beispiel #7
0
def main():
    args = parse_args()
    with open(args.file) as fd:
        data = fd.read()
        sgf = sgf_game.from_string(data)
        gs, first_move_done = new_game_from_handicap(sgf)
        print_board(gs.board)
        for item in sgf.main_sequence_iter():
            color, move_tuple = item.get_move()
            point = None
            if color is not None:
                if move_tuple is not None:
                    row, col = move_tuple
                    point = Point(row + 1, col + 1)
                    move = Move.play(point)
                    print('Move ({},{})'.format(row + 1, col + 1))
                else:
                    move = Move.pass_turn()
                gs = gs.apply_move(move)
                print_board(gs.board)
Beispiel #8
0
def main():
    board_size = 3
    game = GameState.new_game(board_size)
    #bot = MinimaxAgent(5, None)
    bot = MCTSAgent(362000, 0.1, 64)
    while not game.is_over():
        print_board(game.board)
        if game.nplayer == Player.black:
            human_move = input('-- ')
            point = point_from_coord(human_move.strip())
            move = Move.play(point)
        else:
            move = bot.select_move(game)
        print_move(game.nplayer, move)
        game = game.apply_move(move)
    print_board(game.board)
    winner = game.winner()
    if winner is None:
        print("Tie")
    elif winner == Player.black:
        print("Human won")
    else:
        print("Bot won")
Beispiel #9
0
 def handle_showboard(self):
     print_board(self.game_state.board)
     return response.success()