def create_nice_board_and_hive(radius): e = Board(20,20,radius) p = Piece('exists') g = Piece('grasshopper') map(lambda loc_type: e.place_piece(lp(Piece(loc_type[1]),loc_type[0],radius)), zip(nice_hive, nice_hive_types)) e.place_piece(lp(g, (5,-8,3),radius)) return e
def create_complicated_board_and_hive(radius): e = Board(20,20,radius) p = Piece('exists') a = Piece('ant') map(lambda adj_spot: e.place_piece(lp(p,adj_spot, radius)), adjacent_spots) map(lambda hive_spot: e.place_piece(lp(a,hive_spot, radius)), complicated_hive) return e
def __init__(self, width, height, radius, validator=MoveValidator()): self.width = width self.height = height self.radius = radius self.validator = validator self.positions = self.translate_wh_into_hex_coords() self.empty_grid = {hex_coord:lp(Piece("blank"),hex_coord,self.radius) for hex_coord in self.positions} self.pieces_dict = {} self.location_pieces = [ lp(piece, hex_coords, self.radius) for hex_coords, piece in self.pieces_dict.items()] self.location_pieces_empty_grid = [ lp(piece, hex_coords, self.radius) for hex_coords, piece in self.empty_grid.items()]
def test_refresh_lp(self): e = Board(10,10,100) spot = (3,-3,0) self.assertFalse(e.location_in_lp(spot)) p = Piece('exists') locpie = lp(p,spot,100) e.pieces_dict[locpie.hex_coordinates] = locpie.piece_object e.refresh_lp() self.assertTrue(e.location_in_lp(spot))
def test_board_does_not_move_when_move_validator_disallows_it(self): move_validator = fmv() b = Board(5,5,'0',move_validator) start_place = (0,0,0) end_place = (0,1,-1) p = Piece('_') b.place_piece(lp(p, start_place,0)) b.move_piece(start_place, end_place) self.assertTrue(b.pieces_dict[start_place] == p and end_place not in b.pieces_dict)
def place_piece(self,piece_type,x,y,z): print "PLACE PIECE" print x, y, z locpie = lp(Piece(piece_type), (x,y,z), self.radius) self.e.place_piece(locpie)
def test_place_piece(self): b = Board(5,5,60) place = (2,-4,2) piece = Piece('some') b.place_piece(lp(piece,place,60)) self.assertTrue(b.pieces_dict[place] == piece)
def refresh_lp(self): self.location_pieces = [ lp(piece, hex_coords, self.radius) for hex_coords, piece in self.pieces_dict.items()]