def test_destroy(game): # arrange num_districts = len(game.districts) player1 = game.add_player('Player1', city=[District.Manor]) player1.cash_in(3) player2 = game.add_player('Player2', city=[District.Docks, District.Cathedral]) command = commands.Destroy() # act assert [ p.name for p in command.choices(ShadowPlayer(player1, me=True), ShadowGame(player1, game)) ] == ['Player1', 'Player2'] command.select(player2) assert command.choices(ShadowPlayer(player1, me=True), ShadowGame(player1, game)) == [District.Docks] command.select(District.Docks) assert not command.choices(ShadowPlayer(player1, me=True), ShadowGame(player1, game)) command.apply(player1, game) # assert assert player1.gold == 1 assert player2.city == (District.Cathedral, ) assert len(game.districts) == num_districts + 1 assert game.districts[-1] == District.Docks
def test_replace_hands(game): # arrange player = game.add_player( 'Player', hand=[District.Cathedral, District.Tavern, District.Cathedral]) command = commands.ReplaceHand() num_districts = len(game.districts) # act assert command.choices(ShadowPlayer(player, me=True), ShadowGame(player, game)) == [ District.Cathedral, District.Tavern, District.Cathedral ] command.select(District.Cathedral) assert command.choices(ShadowPlayer(player, me=True), ShadowGame(player, game)) == [ District.Tavern, District.Cathedral ] command.apply(player, game) # assert assert len(player.hand) == 3 assert list(player.hand)[:2] == [District.Tavern, District.Cathedral] assert player.hand[2] != District.Cathedral assert len(game.districts) == num_districts
def test_swap_hands(game): # arrange player1 = game.add_player('Player1', hand=[District.Manor]) player2 = game.add_player('Player2', hand=[District.Tavern, District.Cathedral]) command = commands.SwapHands() # act choices = command.choices(ShadowPlayer(player1, me=True), ShadowGame(player, game)) assert [p.name for p in choices] == ['Player2'] command.select(player2) assert not command.choices(ShadowPlayer(player1, me=True), ShadowGame(player, game)) command.apply(player1, game) # assert assert player1.hand == ( District.Tavern, District.Cathedral, ) assert player2.hand == (District.Manor, )
def start_turn(self): game = self._game game.new_turn() # TURN-FACEDOWN game.turn.drop_char(Card(game.characters.take_random()).facedown) # TURN-FACEUP if self._config.turn_unused_faceup_chars: faceup_cards = self._config.turn_unused_faceup_chars else: faceup_cards = {2: 2, 3: 2, 4: 2, 5: 1, 6: 0, 7: 0}[len(self._game.players)] for _ in range(faceup_cards): card = game.characters.take_random() # TURN-FACEUP-KING if card == Character.King: card = game.characters.take_random() game.characters.put_on_bottom(Character.King) game.turn.drop_char(card) self.fire_event('turn_started') # TURN-PICK-FIRST, TURN-PICK for player in game.players.order_by_char_selection(): controller = self.player_controller(player) selected_char = controller.pick_char(game.characters, ShadowPlayer(player, me=True), ShadowGame(player, game)) game.characters.take(selected_char) player.char = selected_char # TURN-PICK-FACEDOWN while game.characters: game.turn.drop_char(Card(game.characters.take_from_top()).facedown)
def test_kill(player, game): # arrange command = commands.Kill() game.turn.drop_char(Character.Architect) # act choices = command.choices(ShadowPlayer(player, me=True), ShadowGame(player, game)) assert choices assert Character.Assassin not in choices assert Character.Architect not in choices command.select(Character.King) assert not command.choices(ShadowPlayer(player, me=True), ShadowGame(player, game)) command.apply(player, game) # assert assert game.turn.killed_char == Character.King
def take_turns(self): if self.game_over: return game = self._game # TURN-CALL for player in game.players.order_by_take_turn(): self.fire_event('player_plays', player, player.char) # KILLED if player.char == game.turn.killed_char: self.fire_event('player_killed', player) continue # ROBBED if player.char == game.turn.robbed_char: thief = game.players.find_by_char(Character.Thief) if player.gold: # TODO: make tx with EventTransaction(self, 'player_robbed', player, player.gold): thief.cash_in(player.gold) player.withdraw(player.gold) # KING-CROWNING if player.char == Character.King: game.crowned_player = player # fires event itself player_controller = self.player_controller(player) command_sink = CommandsSink(player, game) while not command_sink.done: player_controller.take_turn(ShadowPlayer(player, me=True), ShadowGame(player, game), command_sink) if rules.is_city_complete(player) and not game.turn.first_completer: game.turn.first_completer = player self.fire_event('player_played', player) # KING-KILLED if game.turn.killed_char == Character.King: king = game.players.find_by_char(Character.King) if king: game.crowned_player = king