This is a multi-player, client-server implementation of the Hit & Blow game (inspired by the Clubhouse Games™ on Nintendo Switch and the board game Mastermind).
The player is assigned a random sequence of 4 colored pegs with the goal of guessing the correct position and color of each peg. After each guess, the player is told how many "hits" and "blows" they scored. A "hit" is when a peg has both correct color and correct position, and a "blow" is when the peg has correct color but incorrect position. To win, the player must guess the correct sequence within 8 attempts. The colors of the pegs are chosen from a set of six colors: red, yellow, blue, green, pink and white.
Specific to this implementation, a server program will manage single and multi-player games. If a user (i.e. a client) chooses to play by themselves, the server will generate a random sequence of colored pegs for them to guess. If the user wants to play with someone else, then the server will match them with another user and generate a sequence of colored pegs. The two users take turns to guess the correct sequence within 8 combined attempts.
Compilation:
Clone the repository locally. Build the source code in the terminal (opened at the root folder) by running the
make
command. Alternatively, run the following comands in the terminal
g++ -std=c++11 -pthread -o server src/server/main.cpp src/server/RPCServer.cpp src/utility/HitAndBlow.cpp
g++ -std=c++11 -o client src/client/main.cpp src/client/RPCClient.cpp src/utility/HitAndBlow.cpp
Execution:
Execute server and client programs:
Method 1 -- Specify IP address and port number of the server (in the LAN). The server program and the client program can operate on two different computers on the same local area network (LAN). Replace
[PORT]
and [IP_ADDRESS]
with the desired port in the server and its IP address.
./server [PORT]
./client [IP_ADDRESS] [PORT]
./server
./client
Termination:
To terminate the server program, use
Ctrl + C
or Cmd + .
command.
- Player selects single-player mode to start the game. (Server set the answer pegs.)
- Player types in four numbers which represent the colored pegs separated by a space to guess the color and position of four pegs.
- Server returns the "hits" and "blows" for the player's guess.
- Player could use this information to improve their guess.
- Repeat steps 2 - 4 until player guesses the correct answer (i.e. the player has won), or a total of 8 guess are made without getting the correct answer (i.e. the player has lost).
- This mode is essentially similar to the single-player mode. The key difference is that the server matches two players who select two-player mode to start the game.
- The two players take turns to guess the color and position of four pegs. The guess made by one player is relayed to the other player.
- They are allowed 4 guess each to estimate the correct peg sequence.