Example #1
0
    def make_move(self, current_node):
        def fill_board(board, bits, value):
            for i, v in enumerate(
                    reversed('{{:0>{}}}'.format(config.N**2).format(
                        bin(bits)[2:]))):
                if v == "1":
                    x = i % config.N
                    y = i // config.N
                    board[y][x] = value

        board = np.zeros((config.N, config.N), dtype=np.int)
        fill_board(board, current_node.board.black, 1)
        fill_board(board, current_node.board.white, 2)

        board_string = "\n".join(" ".join(map(str, row)) for row in board) \
            + "\n" + str(1 if current_node.player == config.black else 2) + "\n"

        self.player.stdin.write(board_string)
        self.player.stdin.flush()

        out = self.player.stdout.readline()

        if out.strip() == "pass":
            return config.pass_move

        return plane_2_line(out)
Example #2
0
    def make_move(self, current_node):
        if current_node.move == config.pass_move:
            self.write_stdin("pass")
        else:
            self.write_stdin(line_2_plane(current_node.move))
        self.read_stdout()

        self.write_stdin("go")
        edax_move_plane = self.read_stdout().split("plays ")[-1][:2]
        if edax_move_plane == "PS":
            return config.pass_move
        else:
            return plane_2_line(edax_move_plane)
Example #3
0
    def make_move(self, current_node):
        human_input = -1
        while True:
            human_input_str = input(">")
            if human_input_str == "pass":
                human_input = config.pass_move
            else:
                human_input = plane_2_line(human_input_str)

            if human_input is None or current_node.legal_moves[human_input] == 0:
                print("illegal.")
            else:
                return human_input