forked from HelmerNylen/mkbsc
/
firstIteration.py
78 lines (63 loc) · 2.4 KB
/
firstIteration.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
77
78
from parse import parse
import json
def firstIteration():
with open('generatedgames.txt') as f:
file = open('firstiterations.txt', 'w')
count = 0
pos = 1
for line in f:
game = json.loads(line)
##iterate mkbscsc acncaioncancand write
print(pos)
pos += 1
# remember kinda yikes in iterate_until_isomorphic with consider_observations=True
magiian = parse(game)
asd = magiian.KBSC()
data = {}
#Konstruerar sigma
sigma = []
for tuple in asd.alphabet:
sigma.append(''.join(tuple))
data["sigma"] = sigma
index = 0
translator = {}
for state in asd.states:
translator[state] = index
index+=1
#Konstruerar obs
obs = []
for i in range (asd.player_count):
playerobs = []
for j in range (len(asd.partitionings[i].observations)):
individualobs = []
for k in range (len(asd.partitionings[i].observations[j].states)):
individualobs.append(translator[asd.partitionings[i].observations[j].states[k]])
playerobs.append(individualobs)
obs.append(str(playerobs))
data["obs"] = obs
##yea
data["L0"] = translator[asd.initial_state]
data["players"] = asd.player_count
data["stabilises"] = game["stabilises"]
#Konstruerar delta
delta = []
for transition in asd.transitions:
trans = "["
trans+=(str(translator[transition.start]))
trans+=","
trans+=(''.join(transition.joint_action))
trans+=","
trans+=(str(translator[transition.end]))
trans+= "]"
delta.append(trans)
data["delta"] = delta
states = []
for state in asd.states:
states.append(translator[state])
data["states"] = states
json.dump(data, file)
file.write('\n')
print(count)
#Reads data from generated game and formats it as usable data for the implemented mkbsc algorithm
#Returns the game data with information if it stabilises or not
firstIteration()