Skip to content

Commit dcf84d9

Browse files
committed
Blind Chess v2.0
1 parent 809b9ce commit dcf84d9

File tree

3 files changed

+72
-72
lines changed

3 files changed

+72
-72
lines changed

generate_audios.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
duration = 4
1515

1616
for i in range(5):
17-
print("Persona" + str(i) + ":")
17+
print("Set " + str(i) + ":")
1818
for k in range(8):
1919
print("Say " + tags0[perm0[k]] + " " + tags1[perm1[k]] + " " + tags2[perm2[k]] + ":")
2020
input()

minimax.py

+60-62
Original file line numberDiff line numberDiff line change
@@ -10,87 +10,85 @@ class Minimax():
1010

1111
pos_value = [
1212
# Rey
13-
[ 0.5, 0.5, 0.5, 0.0, 0.0, 0.5, 0.5, 0.5,
14-
0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5,
15-
-1.0, -2.0, -2.0, -2.0, -2.0, -2.0, -2.0, -1.0,
16-
-2.0, -3.0, -3.0, -4.0, -4.0, -3.0, -3.0, -2.0,
17-
-3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0,
18-
-3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0,
19-
-3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0,
20-
-3.0, -4.0, -4.0, -5.0, -5.0, -4.0, -4.0, -3.0],
13+
[2.0, 2.0, 2.0, 1.5, 1.5, 2.0, 2.0, 2.0,
14+
2.0, 2.0, 1.5, 1.5, 1.5, 1.5, 2.0, 2.0,
15+
2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0,
16+
1.0, 1.0, 1.0, 0.5, 0.5, 1.0, 1.0, 1.0,
17+
1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1.0,
18+
1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1.0,
19+
1.0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1.0,
20+
1.0, 0.5, 0.5, 0.5, 0.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
64-
1.0, 1.0, 2.0, 3.0, 3.0, 2.0, 1.0, 1.0,
65-
5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
66-
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
58+
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
59+
1.5, 1.5, 1.5, 0.5, 0.5, 1.5, 1.5, 1.5,
60+
1.5, 0.5, 0.5, 1.0, 1.0, 0.5, 0.5, 1.5,
61+
1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 1.0, 1.0,
62+
0.5, 0.5, 1.5, 2.0, 2.0, 1.5, 0.5, 0.5,
63+
1.5, 1.5, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5,
64+
2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
65+
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
6766
]
6867

69-
piece_value = [150, -150, 90, -90, 30, -30, 30, -30, 50, -50, 10, -10]
68+
piece_value = [150, 90, 30, 30, 50, 10]
7069

7170
def __init__(self, player):
7271
self.player = player
7372

74-
def evaluate_board(self, board):
73+
def evaluate(self, current):
7574
value = 0.0
76-
for piece in range(len(board.positions)):
77-
for pos in board.positions[piece]:
78-
if pos == -1:
79-
continue
80-
if self.player == 0:
81-
p = pos
82-
value += self.pos_value[piece//2][p] * self.piece_value[piece]
83-
else:
84-
p = 56 - 8 * (pos // 8) + pos % 8
85-
value += self.pos_value[piece//2][p] * -self.piece_value[piece]
75+
for (pos, cell) in enumerate(current.board):
76+
if cell == -1:
77+
continue;
78+
piece, color = cell // 2, cell % 2
79+
p = pos if self.player == 0 else 56 - 8 * (pos // 8) + pos % 8
80+
if color == self.player:
81+
value += self.pos_value[piece][p] * self.piece_value[piece]
82+
else:
83+
value -= self.pos_value[piece][p] * self.piece_value[piece]
8684
return value
8785

8886
def minimax(self, depth, board, alpha, betha, player):
8987

9088
best_move = (0, 0, 0, 0)
9189

9290
if depth == 0:
93-
return (self.evaluate_board(board), best_move)
91+
return (self.evaluate(board), best_move)
9492

9593
all_moves = board.get_all_valid_moves(player)
9694

speech_recognition.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, tags):
2323

2424
for i in range(self.m_train): # Load the audios of the data set
2525
word = self.tags[i // self.m]
26-
filename = 'audios/persona' + str(i % self.m) + '/' + word + '.wav'
26+
filename = 'audios/set' + str(i % self.m) + '/' + word + '.wav'
2727
rate, audio = scipy.io.wavfile.read(filename)
2828
signal = audio.T[0]
2929
X[i] = signal
@@ -76,6 +76,12 @@ def __init__(self):
7676
print("3...")
7777
self.rec_row = Receptor(self.tags_row)
7878

79+
def say(self, move):
80+
a = self.tags_pieces[move[0] // 2]
81+
b = self.tags_col[move[3]]
82+
c = self.tags_row[move[2]]
83+
return a + " " + b + " " + c
84+
7985
def listen(self, valid_moves):
8086
"""
8187
"""
@@ -103,18 +109,14 @@ def listen(self, valid_moves):
103109
for (id_move, move) in enumerate(valid_moves):
104110
tp, idp, r, c = move
105111
val = pred_piece[tp // 2] * pred_row[r] * pred_col[c]
106-
# print(self.tags_pieces[tp // 2] + " " + self.tags_col[c] + " " + self.tags_row[r])
107-
# print(str(pred_piece[tp // 2]) + " " + str(pred_col[c]) + " " + str(pred_row[r]) + " " + str(val))
112+
# print(self.say(move), "%.6f" % val)
113+
# print("%.6f" % pred_piece[tp//2], "%.6f" % pred_col[c], "%.6f" % pred_row[r], '\n')
108114
if val > max_val:
109115
max_val = val
110116
res = id_move
111117

112-
a = self.tags_pieces[valid_moves[res][0] // 2]
113-
b = self.tags_col[valid_moves[res][3]]
114-
c = self.tags_row[valid_moves[res][2]]
115-
116-
print("Probability: " + str(max_val))
117-
print("You say " + a + " " + b + " " + c + "... Is correct? y / n")
118+
print("Probability: %.6f" % max_val)
119+
print("You say " + self.say(valid_moves[res]) + "... Is correct? y / n")
118120
if input() == "y":
119121
break
120122

0 commit comments

Comments
 (0)