def move_allowed(protocol, own_side, player_side, card, hand) : contract = protocol.contract if contract is None : return False decl = contract[-1] valid_card = bridge.valid_card(hand, card, protocol.moves) res = (player_side == own_side or (decl == own_side and player_side == bridge.partner_side(own_side))) and valid_card return res
def test_card_wrong_suit(self) : self.assertFalse(bridge.valid_card([1, 14], 1, [15]), 'another suit - disallowed')
def test_card_no_suit(self) : self.assertTrue(bridge.valid_card([1], 1, [15]), 'no same suit - allowed')
def test_card_right_suit(self) : self.assertTrue(bridge.valid_card([1], 1, [0]), 'same suit - allowed')
def test_card_new_round(self) : self.assertTrue(bridge.valid_card([1], 1, []), 'new round - everything allowed')
def test_card_played_already(self) : self.assertFalse(bridge.valid_card([1], 1, [1]), 'card is already played')
def test_card_not_in_hand(self) : self.assertFalse(bridge.valid_card([2], 1, []), 'card not in hand')