chess game communication with mrl

Hi, i'm looking for information or documentation regarding sending chess moves back and forth (from arduino to comuuter and vice versa) using the serial. Thank you

GroG's picture

Hi Greg, I'm glad you are not

Hi Greg,

I'm glad you are not the kind of person who gives up quickly, nor gets frustrated when things do not work.  This is an excellent trait to develop and will serve you well, sir.

Let us start with a bit of history.  It helps to understand how we got where we are now ...

The chess stuff was orignall developed for Patrick Maccabe - http://patrickmccabemakes.com/hardware/Chess_Robot_V2/

And then used by metaatur to develop his automated chessboard

http://myrobotlab.org/content/robotic-chess-board

http://myrobotlab.org/content/chess-automated-10-project-update

http://myrobotlab.org/content/chess-automated-project-update

Others have began similar projects

http://myrobotlab.org/content/chess-playing-robot-0

And they kickstarted "Square Off"

 

 

I added to the service script so that is writes "customMsgs" to the Arduino 


#file : service/ChessGame.py edit raw
#########################################
# 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")
  

the script will do a couple of moves, and you'll see data being written to the virtual arduino 

Most of the output here is "heartbeat" - where the computer and the arduino make sure each is listening and attached.  But other messages (including the custom message) will be visible here.  They are also visible in the output of Python script below.

I've given you a lot more information.  Perhaps we could better assit you if we know your future goal is.
GroG

 
greg's picture

Thank you, Thank you, Thank

Thank you, Thank you, Thank you Gr0G, this was especially helpful. I'm working on a capstone project for my final year at the university, i spent a ton of time on the movement and sensing part of the project that i neglected the communication aspect. The ultimate goal is basically to play a game of chess via wi-fi on two remote chess boards (when i found mrl i though i struck gold). The detection mechanism at the moment is a capacitive sensor (i'm considering changing this), The movement is going to be handled by a 3d printer movement axis with the z-axis torn out and reprogrammed to hold a magnet with  would move the pieces undernesth the chess board based on commands from mrl. at the moment 'm using mrl as virtual chess board and building only one physical board. where the game will be phisically visualized

what i'm trying to do for now on mrl just to understand how things work:

Cause---> effect

Bob moves d2-d3 on his physical chessboard ---> mrl moves d2-d3 on chessgame service

Computer moves a2-a3 on chess game service---> Arduino in bob's physical board implements computer's move.

My new questions:

  • Why do the moves need to be encoded as integers(i'm assuming the customMsg method only takes in integers)
     
  • How does the arduino receive these messages. (what are the steps i'd need to take in the MRL comm sketch to receive these chess moves ("a2-a3" say) from mrl).
     
  • How would i go about sending a chess move from the arduino to mrl (move d2-d3 on chessgame service)

Goals in the longterm: 

I have a bunch of things i'd like to improve on, there's so much i'd exceed the allowable writing limit on this  reply. At the moment i'd just like to understand how most of mrl works to be honest and build this prototype.

Thanks again.

GroG's picture

Why do the moves need to be

Why do the moves need to be encoded as integers(i'm assuming the customMsg method only takes in integers)

The chess game engine understands "HMove" object 
https://github.com/MyRobotLab/myrobotlab/blob/develop/src/org/myrobotlab/chess/HMove.java#L15
it has a "to" & "from" as ints
I would "guess" the values are square numbers 1 through 64 for a chessboard... its only a guess as I did not write the chess game engine.  It seems like a simple way to send movement information.  And yes arduino.customMsg(int[]) takes an array of integers.  You could send string values if you wanted to - but you would need to convert the string to an ascii character array - then convert to ints

How does the arduino receive these messages. (what are the steps i'd need to take in the MRL comm sketch to receive these chess moves ("a2-a3" say) from mrl).

 
To receive a message PC --> Arduino
 
 
How would i go about sending a chess move from the arduino to mrl (move d2-d3 on chessgame service)
 
To send a message from Arduino --> PC
use this method
 

 

greg's picture

I think i understand this

I think i understand this alot beter now after taking a look at the links and the .cpp files in mrlcomm, thanks.