Example #1
0
 def occupied_neighbour_hexes(self, hex):
     if hex not in self.cache_neighbours:
         self.cache_neighbours[hex] = set([
             neighbour for neighbour in hexes.neighbours(hex)
             if neighbour in self.tokens
         ])
     return self.cache_neighbours[hex]
Example #2
0
 def update_neighbours(self, add=None, remove=None):
     hex = add or remove
     for neighbour in hexes.neighbours(hex):
         if neighbour in self.cache_neighbours:
             cache_entry = self.cache_neighbours[neighbour]
             if add:
                 cache_entry.add(hex)
             elif remove:
                 cache_entry.remove(hex)
Example #3
0
 def update_neighbours(self,add=None,remove=None):
     hex = add or remove
     for neighbour in hexes.neighbours(hex):
         if neighbour in self.cache_neighbours:
             cache_entry = self.cache_neighbours[neighbour]
             if add:
                 cache_entry.add(hex)
             elif remove:
                 cache_entry.remove(hex)
Example #4
0
    def valid_destinations(self, token):
        player = self.players[token.colour]
        opponent = self.opponent(player)

        if token.is_in_hand():

            # First token: only one valid location
            if self.board.count_tokens() == 0:
                return set([hexes.centre])

            # Second token: is allowed to touch opponent token
            elif self.board.count_tokens() == 1:
                return hexes.neighbours(hexes.centre)

            # If three tokens have been placed but not the bee, must place the bee
            elif len(player.tokens_on_board()) == 3 and player.bee.is_in_hand(
            ) and token.kind != Game.bee:
                return set()

            # Normal situation: token can be placed on any free space that touches own token but not opponent's
            else:
                return self.player_neighbours(player) - self.player_neighbours(
                    opponent) - self.board.occupied_hexes()

        else:

            # Cannot move tokens if the bee has not been played
            if player.bee.is_in_hand():
                return set()

            # Cannot move a token if it would split the hive
            elif self.board.trapped(token):
                return set()

            # Normal situation: token can be moved according to its rules
            elif token.kind == Game.bee:
                return self.board.bee_moves(token.hex)
            elif token.kind == Game.ant:
                return self.board.ant_moves(token.hex)
            elif token.kind == Game.hopper:
                return self.board.hopper_moves(token.hex)
            elif token.kind == Game.beetle:
                return self.board.beetle_moves(token.hex)
            elif token.kind == Game.spider:
                return self.board.spider_moves(token.hex)
Example #5
0
    def valid_destinations(self,token):
        player = self.players[token.colour]
        opponent = self.opponent(player)

        if token.is_in_hand():

            # First token: only one valid location
            if self.board.count_tokens() == 0:
                return set([hexes.centre])

            # Second token: is allowed to touch opponent token
            elif self.board.count_tokens() == 1:
                return hexes.neighbours(hexes.centre)

            # If three tokens have been placed but not the bee, must place the bee
            elif len(player.tokens_on_board()) == 3 and player.bee.is_in_hand() and token.kind != Game.bee:
                return set()

            # Normal situation: token can be placed on any free space that touches own token but not opponent's
            else:
                return self.player_neighbours(player) - self.player_neighbours(opponent) - self.board.occupied_hexes()

        else:

            # Cannot move tokens if the bee has not been played
            if player.bee.is_in_hand():
                return set()

            # Cannot move a token if it would split the hive
            elif self.board.trapped(token):
                return set()

            # Normal situation: token can be moved according to its rules
            elif token.kind == Game.bee:
                return self.board.bee_moves(token.hex)
            elif token.kind == Game.ant:
                return self.board.ant_moves(token.hex)
            elif token.kind == Game.hopper:
                return self.board.hopper_moves(token.hex)
            elif token.kind == Game.beetle:
                return self.board.beetle_moves(token.hex)
            elif token.kind == Game.spider:
                return self.board.spider_moves(token.hex)
Example #6
0
 def player_neighbours(self, player):
     return merge_sets(
         hexes.neighbours(token.hex) for token in player.tokens_on_board())
Example #7
0
 def beetle_moves(self, hex):
     if self.tokens[hex] in self.covered_tokens:
         return hexes.neighbours(hex)
     else:
         return self.occupied_neighbour_hexes(hex) | self.bee_moves(hex)
Example #8
0
 def player_neighbours(self, player):
     return merge_sets(hexes.neighbours(token.hex) for token in player.tokens_on_board())
Example #9
0
 def beetle_moves(self,hex):
     if self.tokens[hex] in self.covered_tokens:
         return hexes.neighbours(hex)
     else:
         return self.occupied_neighbour_hexes(hex) | self.bee_moves(hex)
Example #10
0
 def occupied_neighbour_hexes(self,hex):
     if hex not in self.cache_neighbours:
         self.cache_neighbours[hex] = set([neighbour for neighbour in hexes.neighbours(hex) if neighbour in self.tokens])
     return self.cache_neighbours[hex]