Skip to content

C++ implementation of the game Connect4, using Raspberry Pi SenseHat as input and display device. Computer moves are requested from server (api.codebox.net/connect4).

License

Notifications You must be signed in to change notification settings

deverw/Connect4

Repository files navigation

Connect4

C++ implementation of the game Connect4, using Raspberry Pi SenseHat as input and display device. Computer moves are requested from an external server (api.codebox.net/connect4) or placed randomly. The implementation follows a strictly modular approach, so the game logic is completely decoupled from the input and display device. In order to run the game in a different setting, the classes Input (implemented in input.cpp, reading the SenseHat joystick) and Display (implemented in display.cpp, switching the SenseHat LED matrix) need to be replaced without changing the headers. The class Engine (implemented in engine.cpp) is responsible for providing computer moves and can be extended further by your own logic or AI. I am curious to learn what you come up with and whether you are able to beat the API!

Since C++ comes without native support of web based services, libcurl (http://curl.haxx.se/libcurl/c) needs to be installed before compilation:

sudo apt install libcurl4-openssl-dev

After cloning the repository, start with:
make
./connect4

This will start a game human player (red) against computer (yellow). Move the joystick left and right to choose your column, move down or push to drop the current tile.

You can change the roles by calling the program with command line parameters:
./connect4 c h (computer to move first)
./connect4 h h (human vs. human)
./connect4 c c (computer vs. computer)

By adding a one digit number after c, you can change the level of the computer player (0=random moves only, 9=best moves the server can find, intermediate values increase the probability for server moves). Default is always c9 (highest level).
Example: ./connect4 h c7 (human vs. computer with ~22% random moves)

On execution on a RaspberryPi without the SenseHat extension or a normal PC, an Error on call to open(): No such file or directory will be thrown, since the devices defined in libs/joystick.h and libs/led_matrix.h (/dev/input/event0 and /dev/fb1) do not exist.
The SenseHat libraries were written by Pontus Ekberg (pontus.ekberg@it.uu.se).

About

C++ implementation of the game Connect4, using Raspberry Pi SenseHat as input and display device. Computer moves are requested from server (api.codebox.net/connect4).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published