-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtrain_agent.py
More file actions
41 lines (36 loc) · 1.7 KB
/
train_agent.py
File metadata and controls
41 lines (36 loc) · 1.7 KB
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
import sqlite3
import json
from casino import main as casino_main
def main():
conn = sqlite3.connect('tables.sqlite')
# Read json config file
with open('settings.json') as data_file:
configs = json.load(data_file)
table_name = configs['table_name']
if configs['drop_table']:
conn.execute('DROP TABLE IF EXISTS [' + table_name + ']')
table_query = 'CREATE TABLE [' + table_name + '] (' + \
'[StateID] INTEGER PRIMARY KEY AUTOINCREMENT,' + \
'[PlayerPoints] INTEGER NOT NULL,' + \
'[DealerPoints] INTEGER NOT NULL,' + \
'[SoftHand] INTEGER NOT NULL,' + \
'[FirstTurn] INTEGER NOT NULL,' + \
'[PlayerAce] INTEGER NOT NULL,' + \
'[PlayStand] INTEGER NOT NULL,' + \
'[PlayHit] INTEGER NOT NULL,' + \
'[FinalStand] INTEGER NOT NULL,' + \
'[FinalHit] INTEGER NOT NULL,' + \
'[BadPlay] INTEGER NOT NULL);'
conn.execute(table_query)
states = [(pp, dp, sh, ft, pa, 1, 1, 1, 1, 1) for pp in range(3, 22) \
for dp in range(2, 22) for sh in [0, 1] for ft in [0, 1] for pa in [0, 1]]
states_query = 'INSERT OR IGNORE INTO ' + table_name + \
' (PlayerPoints, DealerPoints, SoftHand, FirstTurn, PlayerAce, PlayStand,' + \
'PlayHit, FinalStand, FinalHit, BadPlay) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
conn.executemany(states_query, states)
conn.commit()
n_games = configs['n_games']
print("Training agent with " + str(n_games)+ ":")
casino_main(n_games=n_games)
if __name__ == '__main__':
main()