-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblackjack-ai-runner.py
executable file
·77 lines (62 loc) · 1.92 KB
/
blackjack-ai-runner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import os
import sys
import argparse
opts = argparse.ArgumentParser(
description=""
)
opts.add_argument('-i','--interactive',
action='store_true',
help='interactive, Enable the human player.')
opts.add_argument('-r','--rate',
type=float,
help='Rate of play in seconds (time to deal 1 card, requires interaction.')
opts.add_argument('-d','--decks',
type=int,
help='Number of decks in each shoe')
opts.add_argument('-s','--shoes',
type=int, default=5,
help='Number of shoes (games) to play')
opts.add_argument('-a','--agents',
type=str, nargs='+', default='',
help='Agents to enable')
opts.add_argument('-z','--randomSeatOrder',
action='store_true',
help='Randomize table seats at start of run.')
opts.add_argument('-v','--verbose',
action='store_true',
help='Print table as each card is delt')
args = opts.parse_args()
import importlib
import pkgutil
import player.players
def iter_namespace(ns_pkg):
return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".")
table_seats = {}
if len(args.agents) == 0:
table_seats = {
name: importlib.import_module(name)
for finder, name, ispkg in iter_namespace(player.players)
if(
((name != 'player.players.human' or args.interactive) and len(args.agents) == 0)
or
((name.split('.')[2] in args.agents or name in args.agents )and len(args.agents) > 0)
)
}
else:
table_seats = {
name: importlib.import_module('player.players.' + name)
for name in args.agents
}
game_opts = {
'shoes': args.shoes or 2,
'decks': args.decks or 6,
'rate': args.rate or None,
'randomSeats': args.randomSeatOrder or False,
'hitSoft17': True,
'insurance': True,
'verbose': args.verbose or False,
}
from game.game import Game
game = Game( game_opts, table_seats )
game.play()