Detail of the breadboard and wiring
Successful calibration with detected game pieces outlined on the homography-adjusted picture of game board
Diagram of the Hex game (credit to Jean-Luc W on Wikipedia)
The game board we printed
The project was inspired by Igor, which is a chess board with AI. The pieces are magnetic, and when a move is made, the computer (Igor) scans the board and announces the next move.
What it does
The project is an interactive game of Hex played against the robot Vladimir. When the player makes a move and presses a button signalling their move is made, Vladimir uses a camera to scan the board and chooses his move, announcing it on a set of speakers.
How we built it
We designed the game board in Gimp and printed it as a poster at College Library. The robot rig to mount the camera, raspberry pi, and speaker is built with coffee cups, miscellaneous boxes, and tape. The camera is mounted to an adjustable lamp so it can be easily positioned to fit the board into frame.
The codebase is in Python, and we include a third-party C++ library which implements the Hex AI.
Once the PI captures a picture of the game board, we run the image through OpenCV color filters to detect the coordinates of the four corners. Then, we calculate a homography matrix to remove the perspective distortion of the camera. The game board is constructed by sampling the color of the image at the tile locations.
We wrote a ctypes bridge to a Hex AI which works with Montecarlo sampling. Once the game board is in memory, the library is invoked to determine the best AI move.
We voice the best move on the speakers using the Python espeak text-to-speech library. An operator places the appropriate game piece and waits for the player move. The player signals that their move is finished by pressing a button on a breadboard.
Challenges we ran into
Calibration of the color detection was our biggest setback. Lighting changes throughout the day made it difficult to calibrate, and the poster paper we used for the board picked up some glare.
Accomplishments that we're proud of
We were really happy with the computer vision result. The project came together in the end with many moving parts.
What we learned
We learned how to set up a Raspberry PI and how to connect it to a breadboard and wire up a push button. I also learned how to use the Python ctypes library and various Raspberry PI audio and camera libraries.
We learned how to use the Python OpenCV library.
What's next for Vladimir's Lattice
Vladimir will develop self-awareness, and 2017 will forever be known as the dawn of Skynet.