-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (37 loc) · 1.41 KB
/
Copy pathmain.py
File metadata and controls
49 lines (37 loc) · 1.41 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
#!/user/bin/env python3
import numpy as np
from constants import *
import chess
from cali_mux import chessboard as incoming_board_data, copy_board, current_readings, display_chessboard, find_changes
import RPi.GPIO as GPIO
import time
from Game import *
# Create start positions
Start = [[0 for _ in range(COLS)] for _ in range(ROWS)]
Prev = [[0 for _ in range(COLS)] for _ in range(ROWS)]
print(Start)
# wait for all pieces to be placed
# Start game
chess_board = chess.Board()
chess_init = [[0,0,0,0,0,0,0,0], [1,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [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,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0]]
previous_board = chess_init
game = Game(chess_board)
try:
while not chess_board.is_game_over():
current_readings()
# Check for changes
changes = find_changes(incoming_board_data, previous_board)
if changes:
print(f"\nDetected {len(changes)} change(s):")
for change in changes:
print(f" {change['square']}: piece {change['action']}")
game.calc(changes, incoming_board_data)
display_chessboard()
previous_board = copy_board()
time.sleep(1) # Slightly longer delay for chess moves
except KeyboardInterrupt:
print("\nI'm dyinggg...")
pixels = neopixel.NeoPixel(board.D18, 8, auto_write=False)
pixels.fill((0,0,0))
pixels.show()
GPIO.cleanup()