def test_setToLimitedBlocks(self): board = Board.parseGameID( "4x4:3,2,7,cRLaRhR,3,3,3,3,3,3,2,0,0,0,3,2,3,2,2,3") board._map[2][1] = Block.GHOST.value solve = Solve(board) result1 = solve.setToLimitedBlocks() self.assertEqual( sorted(result1), sorted( ((0, 0, {Block.ZOMBIE.value}), (0, 2, {Block.ZOMBIE.value}), (0, 3, {Block.ZOMBIE.value}), (1, 0, {Block.ZOMBIE.value}), (1, 1, {Block.ZOMBIE.value }), (1, 3, {Block.ZOMBIE.value, Block.VAMPIRE.value}), (2, 0, {Block.ZOMBIE.value}), (2, 2, {Block.GHOST.value}), (2, 3, {Block.GHOST.value}), (3, 1, {Block.VAMPIRE.value})))) solve.appendNewPossibles(((x[0], x[1]), x[2]) for x in result1) solve.searchAndSetOnlyOnePossible() result2 = solve.setToLimitedBlocks() self.assertEqual( sorted(result2), sorted(((3, 2, {Block.ZOMBIE.value}), (1, 3, {Block.ZOMBIE.value, Block.VAMPIRE.value})))) solve.appendNewPossibles(((x[0], x[1]), x[2]) for x in result2) solve.searchAndSetOnlyOnePossible() result3 = solve.setToLimitedBlocks() self.assertEqual(sorted(result3), sorted(((1, 3, {Block.VAMPIRE.value}), )))
def test_parseGameID(self): board = Board.parseGameID( "10x10:1.3.1/3/5.3/1.5/7/4/3.1.2/3.2/2.2/2/1.1.4/1.4/5.2/3.1/6/3/5/4/3.3/1.3" ) self.assertEqual(board.inRow, ((1, 1, 4), (1, 4), (5, 2), (3, 1), (6, ), (3, ), (5, ), (4, ), (3, 3), (1, 3))) self.assertEqual(board.inColumn, ((1, 3, 1), (3, ), (5, 3), (1, 5), (7, ), (4, ), (3, 1, 2), (3, 2), (2, 2), (2, )))
def test_setTo0Blocks(self): self.assertEqual( sorted( tuple( Solve( Board.parseGameID( "4x4:5,3,2,aLcRLcLLaLb,3,2,1,0,0,1,2,2,3,1,0,3,1,3,2,0" )).setTo0Blocks())), sorted(((0, 0, Block.GHOST.value), (2, 0, Block.GHOST.value), (3, 0, Block.GHOST.value), (3, 1, Block.GHOST.value), (0, 1, Block.VAMPIRE.value), (0, 3, Block.VAMPIRE.value))))
def test_parseGameID(self): parsed = Board.parseGameID( "4x4:3,4,2,LaLReLLaRaRa,2,3,0,0,3,3,1,1,1,1,0,2,0,2,3,0") self.assertEqual(tuple(tuple(row) for row in parsed._map), ((Block.MIRROR_LEFT.value, Block.EMPTY.value, Block.MIRROR_LEFT.value, Block.MIRROR_RIGHT.value), (Block.EMPTY.value, Block.EMPTY.value, Block.EMPTY.value, Block.EMPTY.value), (Block.EMPTY.value, Block.MIRROR_LEFT.value, Block.MIRROR_LEFT.value, Block.EMPTY.value), (Block.MIRROR_RIGHT.value, Block.EMPTY.value, Block.MIRROR_RIGHT.value, Block.EMPTY.value))) self.assertEqual(parsed.SeenFromTop, (2, 3, 0, 0)) self.assertEqual(parsed.SeenFromRight, (3, 3, 1, 1)) self.assertEqual(parsed.SeenFromBottom, (2, 0, 1, 1)) self.assertEqual(parsed.SeenFromLeft, (0, 3, 2, 0)) self.assertEqual(parsed.Vampires, 4) self.assertEqual(parsed.Ghosts, 3) self.assertEqual(parsed.Zombies, 2) self.assertEqual(parsed.Width, 4) self.assertEqual(parsed.Height, 4)
def test_isValid(self): data = ( ("10x10:1/2.2/2.3/8/1.6/1.3/1/4.2/6.2/5.1/2/1.1.1/5.1/3.3/7/4.3/6.3/4.1/2/3", "0001100000010100001001111100100011100111000111111100111101111111110111011110000100000001100000000111", True), ("10x10:1.3/3/1.3/1.2/3.1/3/2.5/8/8/6/1.1.3/1.4/3.4/3/3/3.4/9/4.4/2/1", "1000100111000010111100111011110000000111000000011111100011111111111110111101111000000001100000001000", False), ("20x20:1.4.6.1/4.4/3.3/3.3.1.2/4.1.1.4/4.5.4/3.4/4.7/4.5.2/3.3.5/1.1.6/2.1.5/4.2.5/3.1.5/3.1.5/3.3.7/3.3.2.2/2.6.3.2/3.1.3.2.1/3.6.1.1/1.5.5/6.5/7.2.2/3.5/2.1.1/8.3/4.3.3.1.1/9.6.1/4.10/1.2.1.4/3.2.1.3/3.3.1/4.2.1/2.4.2.1/1.2.4/1.11/2.7/1.2.7/3.2.6/3.2.8", "1000111110000001111100011111100000011111000111111100000110110001110111110000000011000000010100000000111111110000000001111111011100000111010111111111100011111101000001111011111111110000010110001000111111100001100010000111111000011100010000001111000001101000000011000000011110110100100000000011000111101000000001111111111100001100011111110000100011000111111100000001110011001111110000011100110011111111", True), ("15x15:3.2.3/3.3/4.3.3/2.6.3/2.1.3/1.2.5/1.3/4.3/2.1.1.1/1.3.3/3.1/5/7.2/11/11/6.1/5.2/3/4.2.1/1.3.4/1.1.6/2.1.6/2.7/2.4/1.3/1.1.1.2/1.4.2/8.1.3/8.3/7.2", "111111001000000111110001100000111000000000000001111011000100000101110001111000100010111111001100010111111001100001111111001100000001111100000000000111100001000100011000001011110011111111110100111111111110000111111111100000101", False), ) for gameID, boardBlocks, status in data: board = Board.parseGameID(gameID) for x in range(0, board.Width * board.Height): board._map[x // board.Width][ x % board.Width].type = BlockType.BLACK if boardBlocks[ x] == '1' else BlockType.WHITE self.assertEqual(board.isValid(), status)
def test_getAllSeenBlocks(self): solve = Solve( Board.parseGameID( "4x4:3,3,2,LbLLRbLaLcLL,3,1,2,0,0,2,2,3,0,1,3,1,1,0,0,0")) self.assertEqual( # From Left on column with ID 1 solve.getAllSeenBlocks(Direction.LEFT, 1), ((1, 2, 1), )) self.assertEqual( # From Left on column with ID 0 solve.getAllSeenBlocks(Direction.LEFT, 0), ((1, 0, 1), )) self.assertEqual( # From Bottom on column with ID 1 solve.getAllSeenBlocks(Direction.BOTTOM, 1), ((1, 3, 0), (1, 2, 0), (2, 1, 1), (3, 1, 1))) self.assertEqual( # From Right on column with ID 3 solve.getAllSeenBlocks(Direction.RIGHT, 3), ((3, 2, 1), (3, 1, 1), (2, 0, 1), (1, 0, 1))) self.assertEqual( # From Top on column with ID 2 solve.getAllSeenBlocks(Direction.TOP, 2), ((2, 0, 0), (2, 1, 0), (3, 2, 1)))