-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathChessGame.py
54 lines (40 loc) · 1.28 KB
/
ChessGame.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
#########################################
# ChessGame.py
# description: chess game
# categories: game, ai
# more info @: http://myrobotlab.org/service/ChessGame
#########################################
# we will virtualize an Arduino
virtual = True
port="COM3"
# start services
arduino = Runtime.start("arduino","Arduino")
chessgame = Runtime.start("chessgame","ChessGame")
# start optional virtual arduino service, used for test
if ('virtual' in globals() and virtual):
virtualArduino = Runtime.start("virtualArduino", "VirtualArduino")
virtualArduino.connect(port)
#you have to replace COMX with your arduino serial port number
# arduino.connect("/dev/ttyUSB0") - Linux way
arduino.connect(port)
# wait 6 seconds for the game to start
sleep(6)
# subscribes to the game engines move method
python.subscribe(chessgame, "makeHMove")
print("game has started !")
# prints out all moves
def onMakeHMove(move):
print('move is ', move)
print('move is encoded as', move.from, move.to)
print('sending data to arduino in custom msg')
arduino.customMsg(move.from, move.to)
# moves pawn from b2 to b3
chessgame.move("b2-b3")
# wait for computer
sleep(15)
# moves pawn from c2 to c3
chessgame.move("c2-c3")
# wait for computer
sleep(15)
# moves pawn from d2 to d3
chessgame.move("d2-d3")