def __run__(self, player1, player2):
        self.board = board.Board()

        self.now_playing = player1
        self.other_player = player2

        self.gui.show_game(self.board)
        while True:
            winner = self.board.game_won()
            if winner is not None:
                self.now_playing.register_winner(winner)
                self.other_player.register_winner(winner)
                return winner
            valid_moves = self.board.get_valid_moves(self.now_playing.color)
            self.gui.highlight_valid_moves(valid_moves)
            if valid_moves != []:
                move = self.now_playing.get_move(self.board)
                self.gui.flash_move(move, self.now_playing.color)
                if not move in valid_moves:
                    raise Exception("Player %s performed an illegal move: %s" %
                                    (get_color_from_player_number(
                                        self.now_playing.color), move))
                self.board.apply_move(move, self.now_playing.color)
            self.gui.update(self.board, self.other_player)
            self.now_playing, self.other_player = self.other_player, self.now_playing
예제 #2
0
    def update(filename):
        try:

            board_inst = board.Board(puzzle_def)
            board_inst.load(filename)
            score = board_inst.evaluate()
            global max_score
            if score >= max_score:
                print(f"Loading new file {filename}")
                max_score = score
                ui.board = board_inst
                ui.update()
                caption = f'S {board_inst.evaluate()}/{board_inst.max_score()}'
                pygame.display.set_caption(caption)
        except:
            pass
예제 #3
0
파일: play.py 프로젝트: TheSil/edge_puzzle
                        default=None,
                        help='Hint file')
    parser.add_argument('-load',
                        type=str,
                        required=False,
                        default=None,
                        help='Load from saved file')
    args = parser.parse_args()

    puzzle_def = PuzzleDefinition()
    puzzle_def.load(args.conf, args.hints)

    height = puzzle_def.height
    width = puzzle_def.width

    board = board.Board(puzzle_def)

    if args.load:
        board.load(args.load)
        # fill empty pieces
        for id in range(1, height * width + 1):
            if id not in board.board_by_id:
                if board.puzzle_def.all[id].get_type() == TYPE_CORNER:
                    for i, j in board.enumerate_corners():
                        if not board.board[i][j]:
                            board.put_piece(i, j, board.puzzle_def.all[id], 0)
                            break
                    pass
                elif board.puzzle_def.all[id].get_type() == TYPE_EDGE:
                    for i, j in board.enumerate_edges():
                        if not board.board[i][j]:
예제 #4
0
    parser = argparse.ArgumentParser()
    parser.add_argument('-conf',
                        type=str,
                        required=True,
                        help='Definition file')
    parser.add_argument('-dir',
                        type=str,
                        default=".",
                        help='Folder to monitor')
    args = parser.parse_args()

    puzzle_def = PuzzleDefinition()
    puzzle_def.load(args.conf)

    board_inst = board.Board(puzzle_def)
    ui = ui.BoardUi(board_inst)
    ui.init()

    prev_csv_files = set()
    max_score = 0

    def update(filename):
        try:

            board_inst = board.Board(puzzle_def)
            board_inst.load(filename)
            score = board_inst.evaluate()
            global max_score
            if score >= max_score:
                print(f"Loading new file {filename}")
예제 #5
0
from core import board, ui, validate, placement, ai, game

if __name__ == "__main__":
    comp_board = board.Board()
    human_board = board.Board()
    ui = ui.TerminalUi()
    validate = validate.Validate()
    place = placement.Place()
    ai = ai.Ai(validate)
    game = game.Game(comp_board, human_board, ai, ui, validate, place)
    game.play()