-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKerasUtils.py
52 lines (43 loc) · 1.26 KB
/
KerasUtils.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
import numpy as np
# ---------- For Neural Net ----------------
def orderMoves(probs): # CONDENSE fix for same prob
moves = []
probs = probs.tolist()
tProbs = list(probs)
for i in range(len(probs)):
high = max(tProbs)
index = probs.index(high)
probs[index] = None # working fix for same probs bug
moves.append(index)
tProbs.remove(high)
return moves
def find_moves(game_state, grid_dim):
game_state = clean_game_state(game_state)
moves = [x for x in range(len(game_state)) if game_state[x] == 0]
return moves
def makeCommands(grid_dim):
moveCommands = []
for i in range(grid_dim*2+1):
if i%2==0:
for x in range(grid_dim):
moveCommands.append(str(i)+" "+str(x))
else:
for x in range(grid_dim+1):
moveCommands.append(str(i)+" "+str(x))
return moveCommands
def formatMoves(moveOrder, commands): # CONDENSE
fmatMoves = []
for move in moveOrder:
fmatMoves.append(commands[move])
return fmatMoves
def onlyLegal(moves, game_state): # CONDENSE
legal_moves = []
for i in range(len(game_state)):
if game_state[i] == 0:
legal_moves.append(i)
move_order = filter(lambda x: x in legal_moves, moves) #Remove illegal moves
return move_order
def cleanData(raw):
data = [[int(i)] for x in raw for i in x]
data = np.array(data)
return data