def test_box_cards_favour_fifteen_potential(self): computer = Crib.ComputerPlayer() round = Crib.Round([computer, Crib.ComputerPlayer()]) keep_cards = [cc(1, CLUBS), cc(4, CLUBS)] init_cards = [cc(5, DIAMONDS), cc(7, HEARTS), cc(2, SPADES)] + keep_cards computer.receive_cards(init_cards) round.play_round() for c in keep_cards: self.assertIn(c, computer.hand.cards)
def test_box_cards_keep_jack_if_no_box(self): computer = Crib.ComputerPlayer() round = Crib.Round([computer, Crib.ComputerPlayer()]) keep_card = cc(11, CLUBS) init_cards = [keep_card] + [cc(6, DIAMONDS), cc(1, HEARTS), cc(3, SPADES), cc(7, CLUBS)] computer.receive_cards(init_cards) computer.take_box_turn() print(computer.hand) self.assertIn(keep_card, computer.hand.cards)
def test_box_cards_flush(self): computer = Crib.ComputerPlayer() round = Crib.Round([computer, Crib.ComputerPlayer()]) expected_discards = [cc(11, HEARTS), cc(9, HEARTS)] init_cards = [cc(10, CLUBS), cc(11, CLUBS), cc(9, CLUBS)] + expected_discards computer.receive_cards(init_cards) round.play_round() for d in expected_discards: self.assertNotIn(d, computer.hand.cards)
def test_box_creation(self): p_cards = [cc(6, CLUBS), cc(5, DIAMONDS), cc(5, HEARTS), cc(5, SPADES), cc(5, CLUBS)] c_cards = [cc(11, CLUBS), cc(10, DIAMONDS), cc(12, HEARTS), cc(13, SPADES), cc(11, CLUBS)] player, computer = Crib.ComputerPlayer('P'), Crib.ComputerPlayer('C') crib_round = Crib.Round([player, computer], table=None) crib_round.interface.update_score_info('=== testBoxCreation ===') player.receive_cards(p_cards) computer.receive_cards(c_cards) crib_round.play_round() print('=' * 23)
def test_dozen_in_pairs_pegging(self): player = Crib.ComputerPlayer(name='Dummy player') computer = Crib.ComputerPlayer() player_hand = [cc(2, CLUBS), cc(2, DIAMONDS), cc(5, SPADES), cc(1, HEARTS), cc(6, CLUBS)] comp_hand = [cc(12, CLUBS), cc(2, SPADES), cc(2, HEARTS), cc(1, CLUBS), cc(9, DIAMONDS)] crib_round = Crib.Round([player, computer], table=None) crib_round.interface.update_score_info('=== testDozenInPairsPegging ===') player.receive_cards(player_hand) computer.receive_cards(comp_hand) crib_round.play_round() print('=' * 23)
def test_z_box_cards_two_jacks_and_a_fifteen_no_box(self): computer = Crib.ComputerPlayer() round = Crib.Round([computer, Crib.ComputerPlayer()]) keep_cards = [cc(11, CLUBS), cc(11, DIAMONDS)] init_cards = keep_cards + [cc(1, HEARTS), cc(7, SPADES), cc(8, CLUBS)] round.box_owner = None computer.set_round_and_interface(round) computer.receive_cards(init_cards) computer.take_box_turn() print(computer.hand) for c in keep_cards: self.assertIn(c, computer.hand.cards)
def test_z_box_cards_two_jacks_and_a_fifteen_computer_has_box(self): # result is sensitive to changing card order computer = Crib.ComputerPlayer() round = Crib.Round([computer, Crib.ComputerPlayer()]) discards = [cc(11, CLUBS), cc(11, DIAMONDS)] init_cards = [cc(1, HEARTS), cc(7, SPADES), cc(8, CLUBS)] + discards round.box_owner = computer computer.set_round_and_interface(round) computer.receive_cards(init_cards) computer.take_box_turn() print(computer.hand) for c in discards: self.assertNotIn(c, computer.hand.cards)
def testHowManyPairsInFiveCards(self): hand = Crib.Hand([cc(7, SPADES), cc(7, HEARTS), cc(7, SPADES), cc(7, SPADES)]) score = Crib.HandScore(hand, cc(7, SPADES)) self.assertEqual(20, score.points_value) print('\n', score)
def testTwoRunsOfFour(self): hand = Crib.Hand([cc(11, HEARTS), cc(10, CLUBS), cc(12, HEARTS), cc(11, CLUBS)]) score = Crib.HandScore(hand, cc(9, DIAMONDS)) self.assertEqual(10, score.points_value) print('\n', score)
def testTripletFifteen(self): h = Crib.Hand([cc(1, HEARTS), cc(13, SPADES), cc(2, DIAMONDS), cc(4, CLUBS)]) score = Crib.HandScore(h) self.assertEqual(2, score.points_value) print('\n', score)
def test_one_card_after_31_not_a_run(self): cards_down = [cc(4, HEARTS), cc(2, CLUBS), cc(7, DIAMONDS), cc(8, SPADES), cc(9, CLUBS), cc(10, SPADES)] ps = Crib.PeggingSequence() [ps.add_card(c) for c in cards_down] self.assertEqual(0, ps.run_score())
def test_second_phase_run_in_pegging(self): cards_down = [cc(10, DIAMONDS), cc(13, SPADES), cc(9, HEARTS), cc(8, CLUBS), cc(6, HEARTS), cc(7, SPADES)] ps = Crib.PeggingSequence() [ps.add_card(c) for c in cards_down] self.assertEqual(3, ps.run_score())
def test_morgans_orchard_and_one_for_his_knob(self): hand = Crib.Hand([cc(4, HEARTS), cc(11, HEARTS), cc(11, CLUBS)]) hs = Crib.HandScore(hand, cc(4, CLUBS)) print('\n', hs) self.assertEqual(5, hs.points_value)
def test_hand_score_fifteens_and_nothing_else(self): hand = Crib.Hand([cc(5, HEARTS), cc(10, CLUBS), cc(12, HEARTS), cc(13, CLUBS)]) hs = Crib.HandScore(hand, cc(2, DIAMONDS)) print('\n', hs) self.assertEqual(6, hs.points_value)
def test_hand_score_fifteens(self): hand = Crib.Hand([cc(5, HEARTS), cc(10, CLUBS), cc(12, HEARTS), cc(11, CLUBS)]) hs = Crib.HandScore(hand, cc(5, DIAMONDS)) print('\n', hs) self.assertEqual(17, hs.points_value)
def testFifteenTwo(self): h = Crib.Hand([cc(5, HEARTS), cc(10, SPADES)]) score = Crib.HandScore(h) self.assertEqual(2, score.points_value) print('\n', score)
def testNoRuns(self): hand = Crib.Hand([cc(11, HEARTS), cc(10, CLUBS), cc(7, HEARTS), cc(3, CLUBS)]) score = Crib.HandScore(hand) self.assertEqual(0, score.points_value) print('\n', score)
def test_most_complex_run_in_pegging(self): cards_down = [cc(7, CLUBS), cc(5, CLUBS), cc(4, SPADES), cc(2, DIAMONDS), cc(6, HEARTS), cc(3, CLUBS)] ps = Crib.PeggingSequence() [ps.add_card(c) for c in cards_down] self.assertEqual(6, ps.run_score())
def test_broken_run_in_pegging(self): cards_down = [cc(2, CLUBS), cc(10, DIAMONDS), cc(11, SPADES), cc(12, HEARTS)] ps = Crib.PeggingSequence() [ps.add_card(c) for c in cards_down] self.assertEqual(0, ps.run_score())
def test_mess_about_with_suits(self): card = cc(3, CLUBS) # for s in Crib.SUITS: print('\n') dict_suits = {globals()[gk]: gk.lower() for gk in globals().keys() if globals()[gk] in Crib.SUITS} print(dict_suits)
def test_previous_run_in_pegging(self): cards_down = [cc(9, SPADES), cc(1, HEARTS), cc(2, CLUBS), cc(3, HEARTS), cc(5, SPADES)] ps = Crib.PeggingSequence() [ps.add_card(c) for c in cards_down] self.assertEqual(0, ps.run_score())
def testMultiplePairs(self): h = Crib.Hand([cc(12, CLUBS), cc(6, HEARTS), cc(12, DIAMONDS), cc(12, HEARTS), cc(6, DIAMONDS), cc(12, SPADES), cc(6, CLUBS)]) score = Crib.HandScore(h) self.assertEqual(18, score.points_value) print('\n', score)
def testLongFifteensInTheBox(self): h = Crib.Hand([cc(1, CLUBS), cc(9, SPADES), cc(3, HEARTS), cc(2, DIAMONDS), cc(2, CLUBS)]) score = Crib.HandScore(h) self.assertEqual(12, score.points_value) print('\n', score)
def testMegaRuns(self): h = Crib.Hand([cc(9, HEARTS), cc(4, SPADES), cc(10, DIAMONDS), cc(11, CLUBS), cc(12, DIAMONDS), cc(10, HEARTS), cc(11, CLUBS), cc(3, SPADES)]) score = Crib.HandScore(h) self.assertEqual(20, score.points_value) print('\n', score)
def testNotAFlushInHand(self): h = Crib.Hand([cc(13, CLUBS), cc(12, CLUBS), cc(2, DIAMONDS), cc(4, CLUBS)]) score = Crib.HandScore(h) self.assertEqual(0, score.points_value) print('\n', score)
def testRunsSimple(self): hand = Crib.Hand([cc(11, HEARTS), cc(10, CLUBS), cc(12, HEARTS)]) score = Crib.HandScore(hand, cc(3, CLUBS)) self.assertEqual(3, score.points_value) print('\n', score)
def testBlotchy(self): h = Crib.Hand([cc(6, HEARTS), cc(4, SPADES), cc(8, DIAMONDS), cc(2, CLUBS)]) score = Crib.HandScore(h) self.assertEqual(0, score.points_value) print('\n', score)
def testFifteenEight(self): h = Crib.Hand([cc(5, HEARTS), cc(10, SPADES), cc(5, DIAMONDS), cc(10, CLUBS)]) score = Crib.HandScore(h) self.assertEqual(12, score.points_value) print('\n', score)
def testNotAFlushInBox(self): hand = Crib.Hand([cc(10, CLUBS), cc(3, CLUBS), cc(6, CLUBS), cc(12, CLUBS)]) score = Crib.HandScore(hand, cc(13, HEARTS)) self.assertEqual(0, score.points_value) print('\n', score)
def testThreeCardsFlush(self): hand = Crib.Hand([cc(11, HEARTS), cc(6, HEARTS), cc(13, HEARTS)]) score = Crib.HandScore(hand) self.assertEqual(3, score.points_value) print('\n', score)