def remove(self, hex): remove = self.state[hex] if hexes.add(hex, hexes.down) in self.state: self.state[hex] = self.remove(hexes.add(hex, hexes.down)) else: del self.state[hex] return remove
def hopper_moves(self, hex): hopper_moves = set() for offset in hexes.offsets: destination = hexes.add(hex, offset) if destination in self.state: while destination in self.state: destination = hexes.add(destination, offset) hopper_moves.add(destination) return hopper_moves
def test_spider_moves_middle(m): set_state(m, 'ws wa', step=3) assert len(m.spider_moves(hexes.centre)) == 2 left, right = m.spider_moves(hexes.centre) assert hexes.add(left, right) == hexes.centre
def add(self, token, hex): if hex in self.state: self.add(self.state[hex], hexes.add(hex, hexes.down)) self.state[hex] = token
def beetle_moves(self, hex): if hexes.add(hex, hexes.down) in self.state: return hexes.neighbours(hex) else: return hexes.merge( self.crawl_moves(hex)) | self.occupied_neighbours(hex)
def test_up_down(): assert hexes.add(hexes.up, hexes.down) == hexes.centre
def test_opposite(): for offset in hexes.offsets: assert hexes.opposite(hexes.opposite(offset)) == offset assert hexes.add(hexes.opposite(offset), offset) == hexes.centre
def test_add(): assert hexes.add((1, 2, 3), (4, 5, 6)) == (5, 7, 9)