-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_common_mistakes.py
More file actions
121 lines (106 loc) · 4.12 KB
/
find_common_mistakes.py
File metadata and controls
121 lines (106 loc) · 4.12 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# William Kavanagh, June 2020
from helper_fns import *
import numpy as np
import matplotlib.pyplot as plt
import math
from bson import objectid
s1data = process_lookup("beta")
#s2data = process_lookup("tango-2-3")
def flip_state(s):
return [1] + s[10:] + s[1:10]
s1 = {}
s2 = {}
# Process S1 games
set_config("beta")
for g in db.completed_games.find({"winner":{"$exists":True}, "balance_code":{"$exists":False}}):#"1.2"}):
if g["_id"] == objectid.ObjectId("5e98b4658a225cfc82573fd1"): # Ignore dodgy game.
continue
if g["_id"] == objectid.ObjectId("5eaaee2c684de5692fc01ef6") or g["_id"] == objectid.ObjectId("5ec108ef29108c1ba22cb375"): # Ignore dodgy game.
continue
state = get_initial_state(g)
pair1 = g["p1c1"][0] + g["p1c2"][0]
pair2 = g["p2c1"][0] + g["p2c2"][0]
if chars.index(pair1[0]) > chars.index(pair1[1]):
pair1 = pair1[1]+pair1[0]
if chars.index(pair2[0]) > chars.index(pair2[1]):
pair2 = pair2[1]+pair2[0]
for m in g["Moves"]:
if m[1] == "1":
c = cost(state, pair1, m, s1data)
if str(state) in s1:
s1[str(state)] += [c]
else:
s1[str(state)] = [c]
elif m[1] == "2":
c = cost(flip_state(state), pair2, m, s1data)
if str(flip_state(state)) in s1:
s1[str(flip_state(state))] += [c]
else:
s1[str(flip_state(state))] = [c]
do_action(m, state)
for s in s1.keys():
c = np.average(s1[s])
l = len(s1[s])
m = sum(v > 0 for v in s1[s])
s1[s] = {"cost": c, "visits":l, "mistakes":m/l}
def find_worst_n_moves_seen_m_times(n,m):
ret_list = []
ret_list_values = []
for item in range(n):
ret_list_values += [0]
ret_list += [""]
for s in s1.keys():
if s1[s]["visits"] >= m:
for i in range(n):
if s1[s]["cost"] > ret_list_values[i]:
tmp_v = ret_list_values[i]
tmp = ret_list[i]
ret_list_values[i] = s1[s]["cost"]
ret_list[i] = s
for j in range(i,n):
if tmp_v > ret_list_values[j]:
other_tmp_v = ret_list_values[j]
other_tmp = ret_list[j]
ret_list_values[j] = tmp_v
ret_list[j] = tmp
tmp_v = other_tmp_v
tmp = other_tmp
break
#return ret_list, ret_list_values
for r in ret_list:
print(r, s1[r])
def find_worse_with_over_n_moves(n):
current = ""
max = 0.0
for state in s1.keys():
if s1[state]["cost"] > max and s1[state]["visits"] > n:
max = val
current = state
print("Worst state with at least " + str(n) + " moves is: " + current)
print("move was made " + str(len(s1[current])) + " times with an average cost of: " + str(max))
def find_move_mistakes_with_over_n_moves(n):
current = ""
max = 0.0
for state in s1.keys():
if s1[state]["mistakes"] > max and s1[state]["visits"] > n:
max = s1[state]["mistakes"]
current = state
print("Worst state with at least " + str(n) + " moves is: " + current)
print("{0} mistakes were made out of {1} visists".format(s1[current]["mistakes"]*s1[current]["visits"], s1[current]["visits"]))
# find_worse_with_over_n_moves(1)
# find_worse_with_over_n_moves(5)
# find_worse_with_over_n_moves(10)
# find_worse_with_over_n_moves(20)
# find_worse_with_over_n_moves(40)
# find_worse_with_over_n_moves(80)
# find_worse_with_over_n_moves(100)
#find_worst_n_moves_seen_m_times(30,9)
# s = "[1, 0, 0, 0, 8, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 0, 0]"
# print(s1[s])
s1.pop("[1, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0]")
s1.pop("[1, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0]")
find_move_mistakes_with_over_n_moves(5)
find_move_mistakes_with_over_n_moves(15)
find_move_mistakes_with_over_n_moves(25)
find_move_mistakes_with_over_n_moves(35)
find_move_mistakes_with_over_n_moves(45)