def testPerform(self): slot = TableSlot() player = Player("Test", None, None, MinBettingPolicy()) slot.seatPlayer(player) shoe = Shoe(1,lambda x:x) hitCmd = HitCommand(shoe) standCmd = StandCommand() splitCmd = SplitCommand(hitCmd, standCmd) player.receive_payment(cfg['MINIMUM_BET'] * (1 + cfg['SPLIT_RATIO'])) slot.addCards(Card(5,'C'), Card(5,'H')) slot.promptBet() rc = splitCmd.perform(slot) self.assertFalse(rc, 'testSplitCommand:testPerform:Split should not end hand') self.assertEqual(player.stack.amount, 0, 'testSplitCommand:testPerform:Split should deduct appropriate amount from player') hands = slot.hands self.assertEqual(len(hands), 2, 'testSplitCommand:testPerform:Split should split player\'s hand into two hands') self.assertTrue(hands[0].wasSplit, 'testSplitCommand:testPerform: Split hands should reflect split') self.assertTrue(hands[1].wasSplit, 'testSplitCommand:testPerform: Split hands should reflect split') expected = BlackjackHand() expected.addCards(Card(5,'C'), Card(2, 'S')) self.assertEqual(hands[0], expected, 'testSplitCommand:testPerform:Split hands should draw next card from shoe') expected.reset() expected.addCards(Card(5,'H'), Card(2, 'H')) self.assertEqual(hands[1], expected, 'testSplitCommand:testPerform:Split hands should draw next card from shoe')
def testIsAvailable(self): player = Player("Test", None, None, MinBettingPolicy()) player.receive_payment(cfg['MINIMUM_BET']) self.slot.seatPlayer(player) self.slot.addCards(Card('A','H'), Card(6,'D')) cfg.mergeFile('cfg/no_surrender.ini') self.assertFalse(self.surrenderCmd.isAvailable(self.slot), 'testSurrenderCommand:testIsAvailable:Surrender should not be available if disallowed') cfg.reset() self.assertTrue(self.surrenderCmd.isAvailable(self.slot), 'testSurrenderCommand:testIsAvailable:Surrender should be available if allowed') HitCommand(Shoe(2, lambda x:x)).perform(self.slot) self.assertFalse(self.surrenderCmd.isAvailable(self.slot), 'testSurrenderCommand:testIsAvailable:Surrender should not be available after first action')
def testNumSplits(self): slot = TableSlot() slot.addCards(Card(9,'D'), Card(8,'H')) self.assertEqual(slot.numSplits,0,'testTableSlot:testNumSplits:New hand should have no splits') slot = TableSlot() player = Player('', None, MinBettingPolicy(), None) player.receive_payment(cfg['SPLIT_RATIO']) slot.seatPlayer(player) slot.addCards(Card(7,'D'), Card(7,'H')) slot.splitHand() self.assertEqual(slot.numSplits,1,'testTableSlot:testNumSplits:Split hand should have 1 split') slot.addCards(Card(7,'C')) slot.splitHand() self.assertEqual(slot.numSplits,2,'testTableSlot:testNumSplits:Resplit hand should have 2 splits')
def testIsAvailable(self): slot = TableSlot() player = Player("Test", None, None, MinBettingPolicy()) slot.seatPlayer(player) shoe = Shoe(1,lambda x:x) hitCmd = HitCommand(shoe) standCmd = StandCommand() splitCmd = SplitCommand(hitCmd, standCmd) player.receive_payment(cfg['MINIMUM_BET']) slot.addCards(Card(5,'C'), Card(6,'C')) slot.promptBet() self.assertFalse(splitCmd.isAvailable(slot), 'testSplitCommand:testIsAvailable:Split should not be available to insufficiently funded player') player.receive_payment(cfg['MINIMUM_BET'] * (1 + cfg['SPLIT_RATIO'])) slot.promptBet() self.assertFalse(splitCmd.isAvailable(slot), 'testSplitCommand:testIsAvailable:Split should not be avaible to non-pair hand') slot.clearHands() slot.addCards(Card(10,'C'), Card('K','C')) self.assertFalse(splitCmd.isAvailable(slot), 'testSplitCommand:testIsAvailable:Split should not be available to non rank-paired hand when split by value is disallowed') slot.clearHands() cfg.mergeFile('cfg/split_by_value.ini') slot.addCards(Card(10,'C'), Card('K','C')) self.assertTrue(splitCmd.isAvailable(slot), 'testSplitCommand:testIsAvailable:Split should be availabe to non rank-paired hand when split by value is allowed') hitCmd.perform(slot) player.receive_payment(cfg['MINIMUM_BET']) cfg.reset() self.assertFalse(splitCmd.isAvailable(slot), 'testSplitCommand:testIsAvailable:Split should not be availabe to hand beyond first action') cfg.mergeFile('cfg/resplit_upto.ini') slot.clearHands() slot.promptBet() slot.addCards(Card(5,'C'), Card(5,'C')) self.assertFalse(splitCmd.isAvailable(slot), 'testSplitCommand:testIsAvailable:Split should not be availabe if splitting is disallowed') player.receive_payment(3 * cfg['MINIMUM_BET'] * cfg['SPLIT_RATIO']) slot.clearHands() slot.promptBet() slot.addCards(Card('A','C'), Card('A','H')) splitCmd.perform(slot) slot.hands[0].cards = [] slot.hands[0].addCards(Card('A', 'C'), Card('A', 'D')) cfg.reset() cfg.mergeFile('cfg/resplit_aces.ini') self.assertFalse(splitCmd.isAvailable(slot), 'testSplitCommand:testIsAvailable:Split should not be available if hand is aces from split and resplitting aces is disallowed') player.receive_payment(cfg['MINIMUM_BET'] * (2 + cfg['SPLIT_RATIO'])) cfg.reset() self.assertTrue(splitCmd.isAvailable(slot), 'testSplitCommand:testIsAvailable:Split should be available on split aces if resplit aces allowed')
def testIsActive(self): player = Player('Tim', None, None, MinBettingPolicy()) player.receive_payment(1000) slot = TableSlot() slot.seatPlayer(player) slot.promptBet() self.assertTrue(slot.isActive,'testTableSlot:testIsActive:Slot with betting player should be active') class NoBettingPolicy(BettingPolicy): def bet(self, **kwargs): return 0 player = Player('Jack',None, None, NoBettingPolicy()) slot = TableSlot() slot.seatPlayer(player) slot.promptBet() self.assertFalse(slot.isActive,'testTableSlot:testIsActive:Slot with non-betting player should not be active') slot = TableSlot() self.assertFalse(slot.isActive,'testTableSlot:testIsActive:Empty slot should not be active')
if __name__ == '__main__': nspace = parseCommandLine() try: cfg.mergeFile(nspace.config_file_name) except SemanticConfigError as e: print(e) hip1 = HumanInputPolicy() strat = BasicStrategyPolicy('cfg/three_chart.txt') strat1 = FeedbackDecisionPolicy(hip1, strat) player = Player("Matt", strat1, DeclineInsurancePolicy(), MinBettingPolicy()) player.receive_payment(10000) player2 = Player("Billy Batch", strat, DeclineInsurancePolicy(), MinBettingPolicy()) player2.receive_payment(1000) table = Table() table.register_player(player) nRounds = 0 counter = CardCount('HiLoCount') table.shoe.registerObserver(counter) def handler(_signum, _frame): """Handles Ctrl+C signals"""