BlackJack-Simulator icon indicating copy to clipboard operation
BlackJack-Simulator copied to clipboard

KeyError Message

Open FantasyAres opened this issue 8 years ago • 2 comments

Hi, I am having an issue running the program. When I try to run, I get the following below.


python blackjack_original.py BasicStrategy.csv Traceback (most recent call last): File "blackjack_original.py", line 468, in game.play_round() File "blackjack_original.py", line 436, in play_round self.player.play(self.shoe) File "blackjack_original.py", line 261, in play self.play_hand(hand, shoe) File "blackjack_original.py", line 275, in play_hand flag = HARD_STRATEGY[hand.value][self.dealer_hand.cards[0].name] KeyError: 'Ace'


The KeyError is related to the cards dict? How can I resolve? Thank you

FantasyAres avatar Apr 05 '17 22:04 FantasyAres

This error occurs when the: HARD_STRATEGY = {} SOFT_STRATEGY = {} PAIR_STRATEGY = {} are empty - this is a result of loading an invalid CSV file. See the other post related to " INDEX" error for comments on correctly loading the csv file via the importer.

djl314 avatar Feb 23 '21 04:02 djl314

SOLUTION FOR INDEX ERROR in other post:

This is the expected behavior, the sys object receives arguments when calling the script from the command line. sys.argv[1] is the first argument passed - it should be the name/path to the Strategy.csv file. EX: python blackjack_sim.py strategy.csv (assumes csv file in same directory as py file.)

In the alternativve, if you are running from within editor, you can remove the argv[1] and just hard code the file name/path: EX: importer = StrategyImporter('BS.csv')

djl314 avatar Feb 23 '21 04:02 djl314