9 states_dim = 147456 # 2^12 * 6^2
10 actions_dim = 637 # 12+1 * (6+1)^2
13 def find_state_qid(shutable, diced):
17 for i in range(len(diced)):
18 qid += (diced[i]-1) * pow(6, i) * pow(2, 12)
21 def find_option_qid(option):
23 for i in range(len(option)):
24 qid += option[i] * pow(7, i) * pow(13, len(option)-1)
27 def select_option(opts, qs):
31 opt_qid = find_option_qid(opt)
32 opt_qid_pairs.append( [opt, opt_qid] )
33 opt_qsum += qs[opt_qid]
34 random.shuffle(opt_qid_pairs)
35 ran_pt = random.uniform(0.0, opt_qsum)
37 for opt_qid_pair in opt_qid_pairs:
38 decision_pt += qs[ opt_qid_pair[1] ]
39 if ran_pt <= decision_pt:
40 return (opt_qid_pair[0], opt_qid_pair[1])
43 Q = np.zeros([states_dim, actions_dim])
45 for i in range(num_episodes):
47 while not g.is_over():
49 state_qid = find_state_qid(g.get_shutable(), g.get_diced())
50 opt, opt_qid = select_option( g.get_options(), Q[state_qid, :] )
53 print( "%d: %d" % (i, g.get_score()) )