예제 #1
0
 def save(self):
     """
     Save any changes in difficulty to the yaml save file
     """
     dikt = save_file.load()
     dikt['difficulty'] = self.difficulty
     save_file.save(dikt)
예제 #2
0
    def load_previous(self, code_str):
        """
        Load a previous board from memory
        """
        if code_str is None or code_str == '':
            return self.show_turns(code_str)

        # Load fens from file
        fens = save_file.load().setdefault('fens', [])
        fen = fens[int(code_str)]
        self.referee.board.set_fen(fen)
        self.show_board()
예제 #3
0
 def commit_fen(self):
     """
     Add the current board state to the board, so if there is a crash or
     mistake, we can reset the board to a previous state.
     """
     dikt = save_file.load()
     dikt.setdefault('fens', [])
     # Add to the front of the fens list (nicer looking)
     dikt['fens'].insert(0, self.board.fen())
     # Only keep (for now) the past 10 board states
     while len(dikt['fens']) > 10:
         dikt['fens'].pop()
     save_file.save(dikt)
예제 #4
0
    def __init__(self, difficulty=None, turn_time=timedelta(seconds=10)):
        """
        Creates a stockfish AI chess player.
        The AI difficulty is modulated by limiting stockfish's intelligence
        (difficulty is float [0-1], roughly what % of it's brain it can to use)
        The amount of time stockfish can spend
        thinking on a turn is limited to the given turn_time (default 10)
        """
        self.turn_time = turn_time

        # If we were given a difficulty, use that
        if difficulty is not None:
            self.difficulty = difficulty
        # Otherwise, load it from file (default of .5)
        else:
            self.difficulty = save_file.load()['difficulty']
예제 #5
0
    def show_turns(self, code_str):
        """
        Show previous boards stored in memory
        """
        # Board so we can print expected fen load
        board = self.referee.board.copy()

        # Load fens from file
        fens = save_file.load().setdefault('fens', [])
        self.hear('Previously played boards:')
        for i, fen in enumerate(fens):
            board.set_fen(fen)
            player_name = self.referee.active_player(board).name
            # Get string explain that saved fen
            s = f'\n#{i} {player_name}:\n{fen}\n{board}'
            # Add indentation
            s = '\n    '.join(s.split('\n'))
            self.hear(s)
        self.hear('\nTo load one of these, use the prev code.\n'
                  'Eg, to load #5, input: "*prev 5"')