def test_create_state_too_little_players(self): """ Purpose: Test creating a state with only 1 player """ with self.assertRaises(ValueError): FishGameStateFactory.create_place_penguins_state( CreateStateTest.test_board, [(PlayerColor.RED, [])])
def test_create_placement_state_bad_penguin_amount(self): """ Purpose: Test creating a penguin placement state with having the older player having penguins placed already Signature: Void -> Void """ with self.assertRaises(ValueError): FishGameStateFactory.create_place_penguins_state( CreateStateTest.test_board, [(PlayerColor.RED, []), (PlayerColor.BROWN, [(0, 0)])])
def test_create_placement_state_bad_player_amount(self): """ Purpose: Test creating a penguin placement state with too many players Signature: Void -> Void """ with self.assertRaises(ValueError): FishGameStateFactory.create_place_penguins_state( CreateStateTest.test_board, [(PlayerColor.RED, []), (PlayerColor.BROWN, []), (PlayerColor.WHITE, []), (PlayerColor.BLACK, []), (PlayerColor.RED, [])])
def test_create_placement_state_no_penguins(self): """ Purpose: Test creating a penguin placement state with no penguins Signature: Void -> Void """ game_state = FishGameStateFactory.create_place_penguins_state( CreateStateTest.test_board, [(PlayerColor.RED, []), (PlayerColor.BROWN, [])]) self.assertEqual(GamePhase.PLACE_PENGUINS, game_state.get_game_phase()) self.assertEqual(2, len(game_state.get_player_order()))
def test_remove_invalid_color_from_game(self): """ Purpose: Tests the remove invalid color from game function when an invalid color (not in the game) is removed. Signature: Void -> Void """ game_state = FishGameStateFactory.create_place_penguins_state( GameStateTest.test_board, [(PlayerColor.BLACK, []), (PlayerColor.BROWN, [])]) # check if color is not in game with self.assertRaises(ValueError): game_state.remove_color_from_game(PlayerColor.RED)
def test_not_move_state(self): """ Purpose: Test trying to create a tree from a state that is not the player movement state """ with self.assertRaises(ValueError): small_board = FishBoardModel.create_with_same_fish_amount(4, 3, 3) game_state = FishGameStateFactory.create_place_penguins_state( small_board, [(PlayerColor.RED, []), (PlayerColor.BLACK, [])] ) FishGameTree(game_state)
def test_basic_placement(self): """ Test getting basic placement from this player. """ test_board = FishBoardModel.create_with_same_fish_amount(4, 3, 3) test_state = FishGameStateFactory.create_place_penguins_state(test_board, [(PlayerColor.RED, []), (PlayerColor.WHITE, [])]) player = BasicPlayer() placement = player.player_place_penguin(test_state) self.assertEqual((0, 0), placement)
def test_check_penguin_amount(self): """ Purpose: Test the check penguin's amount function with valid and invalid arguments Signature: Void -> Void """ game_state = FishGameStateFactory.create_place_penguins_state( GameStateTest.test_board, [(PlayerColor.BLACK, []), (PlayerColor.BROWN, [])]) # Situation where not all penguins placed with self.assertRaises(ValueError): game_state.check_penguin_amount( 2, { PlayerColor.BLACK: game_state.get_penguins_for_player(PlayerColor.BLACK), PlayerColor.BROWN: game_state.get_penguins_for_player(PlayerColor.BROWN) }, True) # Situation where not all penguins placed but not needed game_state.check_penguin_amount( 2, { PlayerColor.BLACK: game_state.get_penguins_for_player(PlayerColor.BLACK), PlayerColor.BROWN: game_state.get_penguins_for_player(PlayerColor.BROWN) }, False) # Situation where all penguins placed game_state.set_turn(PlayerColor.BROWN) game_state.place_penguin(PlayerColor.BROWN, (0, 0), increase_turn=False) game_state.place_penguin(PlayerColor.BROWN, (1, 1), increase_turn=False) game_state.place_penguin(PlayerColor.BROWN, (0, 2), increase_turn=False) game_state.place_penguin(PlayerColor.BROWN, (2, 0), increase_turn=False) game_state.set_turn(PlayerColor.BLACK) game_state.place_penguin(PlayerColor.BLACK, (2, 2), increase_turn=False) game_state.place_penguin(PlayerColor.BLACK, (3, 3), increase_turn=False) game_state.place_penguin(PlayerColor.BLACK, (3, 1), increase_turn=False) game_state.place_penguin(PlayerColor.BLACK, (1, 3), increase_turn=False) game_state.check_penguin_amount( 2, { PlayerColor.BLACK: game_state.get_penguins_for_player(PlayerColor.BLACK), PlayerColor.BROWN: game_state.get_penguins_for_player(PlayerColor.BROWN) }, True)
def test_create_placement_state_one_less(self): """ Purpose: Test creating a penguin placement state with second penguin in order having one less penguin Signature: Void -> Void """ game_state = FishGameStateFactory.create_place_penguins_state( CreateStateTest.test_board, [(PlayerColor.BROWN, [(0, 0)]), (PlayerColor.RED, [])]) self.assertEqual(GamePhase.PLACE_PENGUINS, game_state.get_game_phase()) self.assertEqual(2, len(game_state.get_player_order())) self.assertEqual([(0, 0)], game_state.get_penguins_for_player(PlayerColor.BROWN))
def test_if_players_can_move(self): """ Purpose: Test the state if a player can't move, if 1 player can move, and where more than one player can move. Signature: Void -> Void """ test_board = FishBoardModel.create_with_same_fish_amount(4, 3, 3) game_state = FishGameStateFactory.create_place_penguins_state( test_board, [(PlayerColor.BLACK, []), (PlayerColor.BROWN, [])]) game_state.place_penguin(PlayerColor.BLACK, (0, 0)) game_state.place_penguin(PlayerColor.BROWN, (1, 1)) self.assertEqual(True, game_state.can_any_player_move()) # Remove tiles test_board.remove_tile(2, 2) test_board.remove_tile(2, 0) test_board.remove_tile(0, 2) test_board.remove_tile(1, 3) game_state_holes = FishGameStateFactory.create_place_penguins_state( test_board, [(PlayerColor.BLACK, [(0, 0)]), (PlayerColor.BROWN, [(1, 1)])]) self.assertEqual(False, game_state_holes.can_any_player_move())
def test_placing_penguin_valid(self): """ Purpose: Test what happens when you place a penguin in a valid tile on the board. Signature: Void -> Void """ test_board_hole = FishBoardModel.create_with_same_fish_amount(4, 3, 3) test_board_hole.remove_tile(0, 0) game_state = FishGameStateFactory.create_place_penguins_state( test_board_hole, [(PlayerColor.BLACK, []), (PlayerColor.BROWN, [])]) game_state.place_penguin(PlayerColor.BLACK, (1, 1)) game_state.place_penguin(PlayerColor.BROWN, (2, 2)) game_state.place_penguin(PlayerColor.BLACK, (3, 3))
def test_remove_color_from_game_next_player(self): """ Purpose: Tests removing a color from the game, checks to see if the current turn will shift to be the next player's turn once the color is removed Signature: Void -> Void """ game_state = FishGameStateFactory.create_place_penguins_state( GameStateTest.test_board, [(PlayerColor.BLACK, []), (PlayerColor.BROWN, [])]) turn_before = game_state.get_current_turn() self.assertEqual(PlayerColor.BLACK, turn_before) game_state.remove_color_from_game(PlayerColor.BLACK) turn_after = game_state.get_current_turn() self.assertEqual(PlayerColor.BROWN, turn_after)
def test_remove_color_from_game_order(self): """ Purpose: Tests removing a color from a game, then checks if the state's game order has changed once a player color is removed from the game. Signature: Void -> Void """ # check if removed from order game_state = FishGameStateFactory.create_place_penguins_state( GameStateTest.test_board, [(PlayerColor.BLACK, []), (PlayerColor.BROWN, [])]) order_before = game_state.get_player_order() self.assertEqual([PlayerColor.BLACK, PlayerColor.BROWN], order_before) game_state.remove_color_from_game(PlayerColor.BLACK) order_after = game_state.get_player_order() self.assertEqual([PlayerColor.BROWN], order_after)
def test_remove_color_from_game_player_info(self): """ Purpose: Tests removing a color from the game, checks to see if the Player Color would be removed from the players in the state Signature: Void -> Void """ game_state = FishGameStateFactory.create_place_penguins_state( GameStateTest.test_board, [(PlayerColor.BLACK, []), (PlayerColor.BROWN, [])]) # check if removed from player info game_state.remove_color_from_game(PlayerColor.BROWN) brown_not_in_players = PlayerColor.BROWN in game_state._players.keys() black_in_players = PlayerColor.BLACK in game_state._players.keys() self.assertFalse(brown_not_in_players) self.assertTrue(black_in_players)
def test_placing_penguin_invalid(self): """ Purpose: Test what happens when you place a penguin where one was already placed, where a tile doesn't exist, or off of the board completely. Signature: Void -> Void """ test_board_hole = FishBoardModel.create_with_same_fish_amount(4, 3, 3) test_board_hole.remove_tile(0, 0) game_state = FishGameStateFactory.create_place_penguins_state( test_board_hole, [(PlayerColor.BLACK, []), (PlayerColor.BROWN, [])]) # placing at position off board with self.assertRaises(PenguinPlacementError): game_state.place_penguin(PlayerColor.BLACK, (-1, -1)) with self.assertRaises(PenguinPlacementError): game_state.place_penguin(PlayerColor.BLACK, (10, 10)) # placing where penguin already exists game_state.place_penguin(PlayerColor.BLACK, (1, 1)) with self.assertRaises(PenguinPlacementError): game_state.place_penguin(PlayerColor.BROWN, (1, 1)) # placing where no tile with self.assertRaises(PenguinPlacementError): game_state.place_penguin(PlayerColor.BROWN, (0, 0))
import sys import os sys.path.insert( 0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))) from Fish.Common.representations.enumerations.player_color_enum import PlayerColor from Fish.Common.representations.fish_board import FishBoardModel from Fish.Common.representations.game_state import FishGameStateFactory from Fish.Common.views.state_view import FishGameStateView board = FishBoardModel.create_with_same_fish_amount(3, 3, 3) placed_penguins = [(PlayerColor.RED, [(0, 0)]), (PlayerColor.WHITE, [(2, 2)]), (PlayerColor.BROWN, [(1, 1)]), (PlayerColor.BLACK, [(2, 0)])] state = FishGameStateFactory.create_place_penguins_state( board, placed_penguins) FishGameStateView.display_state(state)