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_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'))
class Player: def __init__(self): self.strategy = BestStrategy() #set_color means starting #get_placement's next #get_move's next #end_game means final # String --> Void # Alerts a player that the given player (represented as the string of their color) has been kicked from the game # Can be called at any time (as a player may fail or cheat at any time) def has_been_kicked(self, color): #this implementation of player does nothing special upon learning a player was kicked return # String -> Void # Takes in a string representing the color of this player # Called once at the beginning of each game def set_color(self, color): #this implementation of player does nothing special upon learning its color return # state --> placement # - where a placement is a tuple of the string "placement" and a tuple of 2 integers representing position (x,y) # - example: ("Placement", (1,2)) # Takes in a game state and uses it to return a placement action (represented by a tuple of "placement" and a pair of integers for the position) # Called once for the individual player's turn. Expects a placement given back(as a return value) based off the given state # Note: based off of referee specifications, this method will only be called when a player has a valid move to be made def get_placement(self, state): return self.strategy.place_penguin(state) # state --> move # - where a move is tuple of of the string "placement", a tuple of 2 integers representing starting position (x,y), and a tuple of 2 integers representing ending position (x,y) # - example: (" # Move", (1,2), (0,1)) # Takes in a game state and uses it to return a move action (represented by a tuple of "move", a pair of integers for the starting position, and a pair of integers for the ending position) # Called once for the individual player's turn. Expects a move given back(as a return value) based off the given state # Note: - based off of referee specifications, this method will only be called when a player has a valid move to be made # - By default our Player implementation uses a depth of 2 to plan moves def get_move(self, state): return self.strategy.move_penguin(state, 2) # state --> void # Takes in a ending game state that has final scores for players. This function will be used to communicate game winner(s) and scores. # Called once at the end of the game def end_game(self, state): #this implementation of player does nothing special upon learning a game has ended return
def strategy(self): _strategy = BestStrategy() _strategy.set_working_directory(self._working_directory) return _strategy
def __init__(self): self.strategy = BestStrategy()