Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError Message #6

Open
FantasyAres opened this issue Apr 5, 2017 · 2 comments
Open

KeyError Message #6

FantasyAres opened this issue Apr 5, 2017 · 2 comments

Comments

@FantasyAres
Copy link

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

@djl314
Copy link

djl314 commented Feb 23, 2021

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
Copy link

djl314 commented Feb 23, 2021

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants