def confirm(self, response, response_cards, confirm_cards): """Confirm a trade between two players Sends full hand update to the two players involved in the trade """ self.offers.remove(response.offer) util.swap_cards( self.player_info[response.player]['cards'], response_cards, self.player_info[response.offer.player]['cards'], confirm_cards) # notify players of trade, send full hands to the two involved for player in self.players: if player == response.player: player.trade_confirmation(response.copy(), hand=self.player_info[response.player]['cards']) elif player == response.offer.player: player.trade_confirmation(response.copy(), hand=self.player_info[response.offer.player]['cards']) elif player in self.available_players(): player.trade_confirmation(response.copy(), hand=None) # the two players who trade are now busy for a bit self.delay_player(response.player, TRADE_DURATION) self.delay_player(response.offer.player, TRADE_DURATION)
def execute_trade(self, offer, match): """Trades cards between two players, notifies other players. """ util.swap_cards(self.player_data[offer.uid]['cards'], offer.cards, self.player_data[match.uid]['cards'], match.cards) self.broadcast_trade(offer, match) # only match was actually stored in binding_offers self.player_data[match.uid]['binding_offers'].remove(match)
def test_swap_four(self): """Tests swapping foursome of cards""" util.swap_cards(self.cards1, ['a', 'b', 'b', 'b'], self.cards2, ['a', 'a', 'd', 'd']) self.assertEqual(sorted(self.cards1), ['a', 'a', 'a', 'd', 'd']) self.assertEqual(sorted(self.cards2), ['a', 'b', 'b', 'b', 'c'])
def test_swap_trio(self): """Can swap three cards""" util.swap_cards(self.cards1, ['a', 'a', 'b'], self.cards2, ['d', 'd', 'c']) self.assertEqual(sorted(self.cards1), ['b', 'b', 'c', 'd', 'd']) self.assertEqual(sorted(self.cards2), ['a', 'a', 'a', 'a', 'b'])
def test_swap_pair(self): """Can swap a pair of cards""" util.swap_cards(self.cards1, ['a', 'a'], self.cards2, ['d', 'd']) self.assertEqual(sorted(self.cards1), ['b', 'b', 'b', 'd', 'd']) self.assertEqual(sorted(self.cards2), ['a', 'a', 'a', 'a', 'c'])
def test_swap_single(self): """Can swap a single card""" util.swap_cards(self.cards1, ['a'], self.cards2, ['d']) self.assertEqual(sorted(self.cards1), ['a', 'b', 'b', 'b', 'd']) self.assertEqual(sorted(self.cards2), ['a', 'a', 'a', 'c', 'd'])
def test_swap_four(self): """Tests swapping foursome of cards""" util.swap_cards(self.cards1, ['a', 'b', 'b', 'b'], self.cards2, ['a', 'a', 'd', 'd']) self.assertEqual(sorted(self.cards1), ['a','a','a', 'd', 'd']) self.assertEqual(sorted(self.cards2), ['a', 'b', 'b', 'b', 'c'])
def test_swap_trio(self): """Can swap three cards""" util.swap_cards(self.cards1, ['a', 'a', 'b'], self.cards2, ['d', 'd', 'c']) self.assertEqual(sorted(self.cards1), ['b','b','c', 'd', 'd']) self.assertEqual(sorted(self.cards2), ['a', 'a', 'a', 'a', 'b'])
def test_swap_pair(self): """Can swap a pair of cards""" util.swap_cards(self.cards1, ['a', 'a'], self.cards2, ['d', 'd']) self.assertEqual(sorted(self.cards1), ['b','b','b', 'd', 'd']) self.assertEqual(sorted(self.cards2), ['a', 'a', 'a', 'a', 'c'])