def test_cut_card_seen(self): '''! test method cut_card_seen() ''' shoe = Shoe(8) self.assertTrue(shoe.cut_card_seen(), "new shoe, yes") shoe.set_cut_card(1) self.assertFalse(shoe.cut_card_seen(), "position 1 no deal, no") card1 = shoe.deal() self.assertTrue(shoe.cut_card_seen(), "after 1 dealt, then yes")
def test_shuffle(self): ''' test method shuffle() ''' shoe = Shoe(8) self.assertEqual("Ac", str(shoe.deal()), "no shuffle Ace clubs first") shoe.reset() expected_clubs = "Ac2c3c4c5c6c7c8c9cTcJcQcKc" cards = "" for _ in range(13): cards += str(shoe.deal()) self.assertEqual(expected_clubs, cards, "pre-shuffle") shoe.shuffle() cards = "" for _ in range(13): cards += str(shoe.deal()) self.assertNotEqual(expected_clubs, cards, "post-shuffle")
def test_save_shoe(self): '''! test method save_shoe() ''' shoe = Shoe() #default single deck #no shuffle so we can test a simple single deck in order temp_file = os.sep + 'tmp' + os.sep + 'ut1.shoe' delete_file(temp_file) shoe.save_shoe(temp_file) expect = "Ac 2c 3c 4c 5c 6c 7c \n"+\ "8c 9c Tc Jc Qc \n"+\ "Kc Ad 2d 3d 4d \n"+\ "5d 6d 7d 8d 9d \n"+\ "Td Jd Qd Kd Ah \n"+\ "2h 3h 4h 5h 6h \n"+\ "7h 8h 9h Th Jh \n"+\ "Qh Kh As 2s 3s \n"+\ "4s 5s 6s 7s 8s 9s Ts Js Qs Ks \n" with open(temp_file, 'r') as f: actual = f.read() self.assertEqual(expect, actual, "saved single unshuffled deck")
def __init__(self, shoe=None, player=None, banker=None, system=None): '''! TBD ''' # if shoe is None: shoe = Shoe(8) shoe.shuffle() if player is None: player = Hand() if banker is None: banker = Hand() # self.__shoe = shoe self.__player = player ##!< banker is the Hand for banker self.__banker = banker ##!< system_play is the bacc system we are tracking self.system_play = system # self.count_d7 = 0 self.count_p8 = 0
def test_deal(self): '''! test method deal() ''' shoe = Shoe(8) card1 = shoe.deal() # no shuffle so Ac should start us out self.assertEqual("Ac", str(card1), "no shuffle Ac first card") # create a short custom shoe to test running out of cards shoe2 = Shoe([ Card(43), Card(44), Card(45), ]) # only 3 cards in this shoe2 card1 = shoe2.deal() self.assertIsNotNone(card1, "first of shoe2") card1 = shoe2.deal() self.assertIsNotNone(card1, "second of shoe2") card1 = shoe2.deal() self.assertIsNotNone(card1, "third of shoe2") card1 = shoe2.deal() self.assertIsNone(card1, "fourth of shoe2 (empty)")
def test_set_cut_card(self): ''' test method set_cut_card(int) ''' # good test shoe = Shoe(8) shoe.set_cut_card(-14) # bad test # too big expected = "cut card position value too big" try: shoe.set_cut_card(987) self.fail("expected failure set_cut_card(987)") except Exception as ex: self.assertEqual(expected, str(ex), "too big") # too small expected = "cut card position value too small" try: shoe.set_cut_card(-987) self.fail("expected failure set_cut_card(-987)") except Exception as ex: self.assertEqual(expected, str(ex), "too small")
def just_boards(): print("*** JustBoards ***") shoe = Shoe(8) shoe.shuffle() Game(shoe=shoe, system=JustBoards()).play()
parser = argparse.ArgumentParser("Play a game of Baccarat interactively") parser.add_argument("--create", dest="create_filespec", help="instead of playing just create and save a random shoe") parser.add_argument("--use", dest="use_filespec", help="use a saved shoe instead of random generation") parser.add_argument("--just_boards", type=str2bool, nargs='?', const=True, default=False, help="Just use the program to display board results") args = parser.parse_args() if args.use_filespec is not None: if args.create_filespec is not None: raise ValueError("can not use both --create and --use at same time") # --use creates an empty shoe, then fill from a saved file shoe = Shoe(0) shoe.load_shoe(args.use_filespec) play(shoe) else: # generate a new random shoe if args.create_filespec is not None: shoe = Shoe(8) shoe.shuffle() # --create saves the new shoe and exists shoe.save_shoe(args.create_filespec) shoe = None else: if args.just_boards: just_boards() else: play()