def test_set_tiles(self): test_board = b.Board(1) test_board.board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] test_tiles = ts.Tiles(3, test_board) self.assertEqual([x.val for x in test_tiles.tile_list], [0, 0, 0, 0, 0, 0, 0, 0, 0]) test_board.board = [[1, 0, 1], [2, 3, 1], [0, 3, 0]] test_tiles = ts.Tiles(3, test_board) self.assertEqual([x.val for x in test_tiles.tile_list], [1, 0, 1, 2, 3, 1, 0, 3, 0])
def test_text_init(self): "Test the Tiles object creation from text" # 1. Create Tiles object from text myobj = tiles.Tiles(text=aoc_24.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 20) self.assertEqual(len(myobj.tiles), 15) # 3. Test methods self.assertEqual(myobj.count_black(), 10) myobj.one_day() self.assertEqual(myobj.count_black(), 15) myobj.one_day() self.assertEqual(myobj.count_black(), 12) myobj.one_day() self.assertEqual(myobj.count_black(), 25) myobj.one_day() self.assertEqual(myobj.count_black(), 14) myobj.one_day() self.assertEqual(myobj.count_black(), 23) myobj.one_day() self.assertEqual(myobj.count_black(), 28) myobj.one_day() self.assertEqual(myobj.count_black(), 41) myobj.one_day() self.assertEqual(myobj.count_black(), 37) myobj.one_day() self.assertEqual(myobj.count_black(), 49) myobj.one_day() self.assertEqual(myobj.count_black(), 37)
def test_part_two(self): "Test part two example of Tiles object" # 1. Create Tiles object from text myobj = tiles.Tiles(part2=True, text=aoc_24.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_part_one(self): "Test part one example of Tiles object" # 1. Create Tiles object from text myobj = tiles.Tiles(text=aoc_24.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
def test_empty_init(self): "Test the default Tiles creation" # 1. Create default Tiles object myobj = tiles.Tiles() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None)
def __init__(self, screen, new_game_engine): self._game_engine = new_game_engine self._board_screen = screen # build tiles self._tiles = tiles.Tiles(self._game_engine) # build zones on board where tiles fit self._board_zones_collection = [] for i in range(get_num_board_zones()): self._board_zones_collection.append(hexes.Hexes()) self._board_zones_collection[i].number = i
def __init__(self, text=None, part2=False): # 1. Set the initial values self.part2 = part2 self.text = text self.tiles = None self.image = None # 2. Process text (if any) if text is not None and len(text) > 0: self.tiles = tiles.Tiles(text=text, part2=part2)
def part_one(args, input_lines): "Process part one of the puzzle" # 1. Create the puzzle solver solver = tiles.Tiles(part2=False, text=input_lines) # 2. Determine the solution for part one solution = solver.part_one(verbose=args.verbose, limit=args.limit) if solution is None: print("There is no solution") else: print("The solution for part one is %s" % (solution)) # 3. Return result return solution is not None
def __init__(self, gamestate): self._gamestate = gamestate self._board = self._gamestate._board self.root = Tk() self.player_list = [] self._current_player = None self.tiles = tiles.Tiles() #move data fields self._movetype = StringVar() self._word = StringVar() self._game = StringVar() self._error = StringVar() self._exchange_pieces_var = StringVar() #game data fields self._turn = StringVar() self._score = StringVar() self._letters = StringVar()
def test_text_init(self): "Test the Tiles object creation from text" # 1. Create Tiles object from text myobj = tiles.Tiles(text=aoc_20.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 9 * 11) self.assertEqual(len(myobj.tiles), 9) self.assertEqual(myobj.size, 3) self.assertEqual(myobj.grid, None) # 3. Test placing tiles into a grid myobj.position_tiles() self.assertNotEqual(myobj.grid, None) numbers = [] for row in myobj.grid: for col in row: numbers.append(col[0].number) self.assertEqual(numbers, GRID) # 4. Test the image self.assertEqual(myobj.get_image(), IMAGE)
def generateDB(self, resolution): """Generate the database from a tile stack""" [ximagesz, yimagesz] = self.dbcfg.imagesz[resolution] [xcubedim, ycubedim, zcubedim] = self.dbcfg.cubedim[resolution] [self.startslice, endslice] = self.dbcfg.slicerange self.slices = endslice - self.startslice + 1 # round up to the next largest slice if self.slices % zcubedim != 0: self.slices = (self.slices / zcubedim + 1) * zcubedim tilestack = tiles.Tiles(self.dbcfg.tilesz, self.dbcfg.inputprefix + '/' + str(resolution), self.startslice) # Set the limits on the number of cubes in each dimension xlimit = ximagesz / xcubedim ylimit = yimagesz / ycubedim zlimit = self.slices / zcubedim # list of batched indexes idxbatch = [] # This parameter needs to match to the max number of slices to be taken. # The maximum z slices that prefetching will take in this prefetch # This is useful for higher resolutions where we run out of tiles in # the x and y dimensions zmaxpf = 256 zstride = 256 # This batch size is chosen for braingraph1. # It loads 32x32x16cubes equivalent to 16 x 16 x 256 tiles @ 128x128x16 per tile and 512x512x1 per cube # this is 2^34 bytes of memory batchsize = 16384 # Ingest the slices in morton order for mortonidx in zindex.generator([xlimit, ylimit, zlimit]): xyz = zindex.MortonXYZ(mortonidx) # if this exceeds the limit on the z dimension, do the ingest if len(idxbatch) == batchsize or xyz[2] == zmaxpf: # preload the batch tilestack.prefetch(idxbatch, [xcubedim, ycubedim, zcubedim]) # ingest the batch for idx in idxbatch: bc = self.ingestCube(idx, resolution, tilestack) self.saveCube(bc, idx, resolution) # commit the batch self.conn.commit() # if we've hit our area bounds set the new limit if xyz[2] == zmaxpf: zmaxpf += zstride # Finished this batch. Start anew. idxbatch = [] #build a batch of indexes idxbatch.append(mortonidx) # preload the remaining tilestack.prefetch(idxbatch, [xcubedim, ycubedim, zcubedim]) # Ingest the remaining once the loop is over for idx in idxbatch: bc = self.ingestCube(idx, resolution, tilestack) self.saveCube(bc, idx, resolution) # commit the batch self.conn.commit()
def __init__(self, player_num): #number of players is between 2 and 4 self._player_num = player_num self._board = self._new_board() self._tiles = tiles.Tiles()