示例#1
0
    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)
示例#2
0
 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)
示例#3
0
文件: gameengine.py 项目: roblacy/pit
 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)
示例#4
0
 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'])
示例#5
0
 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'])
示例#6
0
 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'])
示例#7
0
 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'])
示例#8
0
文件: test_util.py 项目: roblacy/pit
 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'])
示例#9
0
文件: test_util.py 项目: roblacy/pit
 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'])
示例#10
0
文件: test_util.py 项目: roblacy/pit
 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'])
示例#11
0
文件: test_util.py 项目: roblacy/pit
 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'])