def test_move_penguin(self): player_list = ["red", "white"] ex_board = f.FishBoard(4, 3) ex_board.createBoard(equal=True, randomHoles=False) ex_state = s.State(ex_board, player_list) ex_state.place_penguin(0, 0, "red") ex_state.place_penguin(1, 0, "white") ex_state.place_penguin(0, 2, "red") ex_state.place_penguin(1, 2, "white") ex_state.place_penguin(2, 0, "red") ex_state.place_penguin(1, 3, "white") ex_state.place_penguin(2, 1, "red") ex_state.place_penguin(0, 1, "white") fish_on_tile = ex_board.tiles[2][1].numFish ex_state.move_penguin(2, 1, 2, 2, "red") #Assert previous tile is empty self.assertEqual(ex_board.tiles[2][1].numFish, 0) #Assert penguin got moved self.assertEqual(ex_state.penguin_map["red"][3], (2, 2)) #Assert that points got updated self.assertEqual(ex_state.score_map["red"], fish_on_tile)
def test_move_wrong_penguin(self): player_list = ["red", "white"] ex_board = f.FishBoard(4, 3) ex_board.createBoard(equal=True, randomHoles=False) ex_state = s.State(ex_board, player_list) ex_state.place_penguin(0, 0, "red") ex_state.place_penguin(1, 0, "white") ex_state.place_penguin(0, 2, "red") ex_state.place_penguin(1, 2, "white") ex_state.place_penguin(2, 0, "red") ex_state.place_penguin(1, 3, "white") ex_state.place_penguin(2, 1, "red") ex_state.place_penguin(0, 1, "white") fish_on_tile = ex_board.tiles[2][1].numFish with self.assertRaises(ValueError): ex_state.move_penguin(2, 1, 2, 2, "white")
def test_place_in_order(self): player_list = ["red", "white"] ex_board = f.FishBoard(4, 3) ex_board.createBoard(equal=True, randomHoles=False) ex_state = s.State(ex_board, player_list) with self.assertRaises(ValueError): ex_state.place_penguin(0, 0, "white")
def test_placement_1(self): player_list = ["red","white"] b = [[1,2,3,2],[4,0,5,1],[1,1,0,4]] ex_board = f.FishBoard(3,4) ex_board.createBoard(exact=b) ex_peng_map = {"red":[(0,0),(1,0),(2,0)], "white":[(3,2),(3,1),(0,2)]} ex_state = s.State(ex_board,player_list, ex_peng_map, {"red":0,"white":0}, "red", "Moving") red_strat = BestStrategy() placement = red_strat.place_penguin(ex_state) self.assertEqual(placement, ("Placement", (3,0)))
def test_move_before_all_placed(self): player_list = ["red", "white"] ex_board = f.FishBoard(4, 3) ex_board.createBoard(equal=True, randomHoles=False) ex_state = s.State(ex_board, player_list) ex_state.place_penguin(0, 0, "red") ex_state.place_penguin(1, 0, "white") with self.assertRaises(ValueError): ex_state.move_penguin(0, 0, 1, 0, "red")
def test_place_avatar_empty_tile(self): hole_locations = [[0, 0]] player_list = ["red", "white"] ex_board = f.FishBoard(4, 3) ex_board.createBoard(holes=hole_locations, equal=True, randomHoles=False) ex_state = s.State(ex_board, player_list) with self.assertRaises(ValueError): ex_state.place_penguin(0, 0, "red")
def test_place_avatar(self): player_list = ["red", "white"] ex_board = f.FishBoard(4, 3) ex_board.createBoard(equal=True, randomHoles=False) ex_state = s.State(ex_board, player_list) # Place youngest players penguins at 0,0 ex_state.place_penguin(0, 0, "red") ex_state.place_penguin(1, 1, "white") self.assertEqual(ex_state.penguin_map["red"][0], (0, 0)) self.assertEqual(ex_state.penguin_map["white"][0], (1, 1))
def test_move_2(self): player_list = ["red","white"] b = [[1,2,3,2],[4,0,5,1],[1,1,0,4]] ex_board = f.FishBoard(3,4) ex_board.createBoard(exact=b) ex_peng_map = {"red":[(0,0),(1,0),(2,0),(3,0)], "white":[(3,2),(3,1),(0,2),(0,1)]} ex_state = s.State(ex_board,player_list, ex_peng_map, {"red":0,"white":0}, "red", "Moving") strat = BestStrategy() move = strat.move_penguin(ex_state,4) self.assertEqual(move, ('Move', (2, 0), (2, 1), 'red'))
def test_board_move_unavailible(self): player_list = ["red", "white"] ex_board = f.FishBoard(4, 2) ex_board.createBoard(equal=True, randomHoles=False) ex_state = s.State(ex_board, player_list) ex_state.place_penguin(0, 0, "red") ex_state.place_penguin(1, 0, "white") ex_state.place_penguin(0, 1, "red") ex_state.place_penguin(1, 1, "white") ex_state.place_penguin(0, 2, "red") ex_state.place_penguin(1, 2, "white") ex_state.place_penguin(0, 3, "red") ex_state.place_penguin(1, 3, "white") self.assertEqual(ex_state.any_moves(), False)
def test_placement_3(self): player_list = ["red", "white"] b = [[1, 2, 3, 2], [4, 0, 5, 1], [1, 1, 0, 4]] ex_board = f.FishBoard(3, 4) ex_board.createBoard(exact=b) ex_peng_map = { "red": [(0, 0), (1, 0), (2, 0), (3, 0)], "white": [(3, 2), (3, 1), (0, 2)] } ex_state = s.State(ex_board, player_list, ex_peng_map, { "red": 0, "white": 0 }, "white", "Moving") test_player = Player() placement = test_player.get_placement(ex_state) self.assertEqual(placement, ('Placement', (0, 1)))
def test_placement_2(self): player_list = ["red", "white"] b = [[1, 2, 3, 2], [4, 0, 5, 1], [1, 1, 0, 4]] ex_board = f.FishBoard(3, 4) ex_board.createBoard(exact=b) ex_peng_map = { "red": [(0, 0), (1, 0), (2, 0), (3, 0)], "white": [(3, 2), (3, 1), (0, 2)] } ex_state = s.State(ex_board, player_list, ex_peng_map, { "red": 0, "white": 0 }, "red", "Moving") player = Player() with self.assertRaises(ValueError): player.get_placement(ex_state)
def test_move_4(self): player_list = ["red", "white"] b = [[1, 2, 3, 2, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0], [0, 3, 1, 4, 1], [2, 3, 1, 4, 1]] ex_board = f.FishBoard(5, 5) ex_board.createBoard(exact=b) ex_peng_map = { "red": [(0, 0), (1, 0), (2, 0), (3, 0)], "white": [(3, 0), (3, 1), (3, 2), (3, 3)] } ex_state = s.State(ex_board, player_list, ex_peng_map, { "red": 0, "white": 0 }, "red", "Moving") test_player = Player() move = test_player.get_move(ex_state) self.assertEqual(move, ('Move', (0, 0), (0, 4), 'red'))