forked from BuddhiGamage/chess_robot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreturn_move_old.py
More file actions
52 lines (46 loc) · 1.54 KB
/
return_move_old.py
File metadata and controls
52 lines (46 loc) · 1.54 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
def get_move(previous_state, current_state):
# Define the board columns and rows
columns = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
rows = ['1', '2', '3', '4', '5', '6', '7', '8'] # Bottom to top
# Find the source and destination positions
source = None
destination = None
for i in range(8):
for j in range(8):
if previous_state[i][j] == 1 and current_state[i][j] == 0:
# Piece moved from (i, j)
source = columns[j] + rows[7 - i] # Flip row index
elif previous_state[i][j] == 0 and current_state[i][j] == 1:
# Piece moved to (i, j)
destination = columns[j] + rows[7 - i] # Flip row index
if source:
if destination:
return f'{source}{destination}'
else:
return source
else:
return "No move detected"
# Example matrices
previous_state = [
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0], # initial position
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1]
]
current_state = [
[1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 1], # Piece removed from d2
[0, 0, 0, 0, 0, 0, 0, 0], # Piece added to d4
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1]
]
# # Get the move
# move = get_move(previous_state, current_state)
# print(move)