src/quagen/ai/biased.py
def _get_lookback_candidates(self, available_spots, num_candidates, num_turns):
        """
        Looks around recent moves made by opponents' and randomly chooses a
        handful of available spots

        Args:
            available_spots (list): All spots to choose from
            num_candidates (int): Number of spots to choose
            num_turns (int): Number of turns to look back in history

        Returns:
            (list) of choosen candidates
        """
        candidate_spots = []

        # Combines all the recent moves into one long list -- exclude moves
        # made by this AI
        past_moves = self._game.history[-num_turns:]
        past_moves = list(itertools.chain.from_iterable(past_moves))
        past_moves = [move for move in past_moves if move[2] != self._color]

        # Select spots immediately surronding each past move
        lookback_spots = []
        for past_move in past_moves:

            for x in range(-1, 2):
                for y in range(-1, 2):
                    spot = (past_move[0] + x, past_move[1] + y)
                    if spot in available_spots:
                        lookback_spots.append(spot)

        # Randomly select out the desired count of candidates
        random.shuffle(lookback_spots)
        while len(candidate_spots) < num_candidates and lookback_spots:
            candidate_spots.append(lookback_spots.pop())

        return candidate_spots

        Looks around recent moves made by opponents' and randomly chooses a
        handful of available spots

        Args:
            available_spots (list): All spots to choose from
            num_candidates (int): Number of spots to choose
            num_turns (int): Number of turns to look back in history

        Returns:
            (list) of choosen candidates
        
Looks around recent moves made by opponents' and randomly chooses a
handful of available spots
Looks around recent moves made by opponents ' and randomly chooses a handful of available spots
def _get_lookback_candidates(self, available_spots, num_candidates, num_turns):
        candidate_spots = []
        past_moves = self._game.history[-num_turns:]
        past_moves = list(itertools.chain.from_iterable(past_moves))
        past_moves = [move for move in past_moves if move[2] != self._color]
        lookback_spots = []
        for past_move in past_moves:
            for x in range(-1, 2):
                for y in range(-1, 2):
                    spot = (past_move[0] + x, past_move[1] + y)
                    if spot in available_spots:
                        lookback_spots.append(spot)
        random.shuffle(lookback_spots)
        while len(candidate_spots) < num_candidates and lookback_spots:
            candidate_spots.append(lookback_spots.pop())
        return candidate_spots
def _get_lookback_candidates ( self , available_spots , num_candidates , num_turns ) : candidate_spots = [ ] past_moves = self . _game . history [ - num_turns : ] past_moves = list ( itertools . chain . from_iterable ( past_moves ) ) past_moves = [ move for move in past_moves if move [ 2 ] != self . _color ] lookback_spots = [ ] for past_move in past_moves : for x in range ( - 1 , 2 ) : for y in range ( - 1 , 2 ) : spot = ( past_move [ 0 ] + x , past_move [ 1 ] + y ) if spot in available_spots : lookback_spots . append ( spot ) random . shuffle ( lookback_spots ) while len ( candidate_spots ) < num_candidates and lookback_spots : candidate_spots . append ( lookback_spots . pop ( ) ) return candidate_spots
Looks around recent moves made by opponents' and randomly chooses a
handful of available spots
Looks around recent moves made by opponents ' and randomly chooses a handful of available spots
"""
        Looks around recent moves made by opponents' and randomly chooses a
        handful of available spots

        Args:
            available_spots (list): All spots to choose from
            num_candidates (int): Number of spots to choose
            num_turns (int): Number of turns to look back in history

        Returns:
            (list) of choosen candidates
        """ # Combines all the recent moves into one long list -- exclude moves # made by this AI # Select spots immediately surronding each past move # Randomly select out the desired count of candidates
(list) of choosen candidates
( list ) of choosen candidates
self
available_spots
All spots to choose from
All spots to choose from
num_candidates
Number of spots to choose
Number of spots to choose
num_turns
Number of turns to look back in history
Number of turns to look back in history