Chess Game

The Chess Game is a small game made by myself on my personal time.

This project was made by myself on my free time. It took me three months to get a fully working game.

Legal / Illegal Moves :

At first the movements of the pieces may seem quite simple. The king can move one square in any direction, the bishop can go anywhere along the diagonals and the rook can move anywhere in straight lines.

However, as you dive deeper into the rules of chess, some moves become trickier than others. But the most challenging part of all these rules is the need to filter the moves of each piece to keep the king safe from the enemy’s possible moves.

There is a base function which handle most cases. It returns all the possibles moves in the desired direction. With this function, most movement possibilities are covered. However there are a few special cases. For example the knight who moves in an “L” shape and the pawn can only move in straight lines but attack diagonally.

The solution for these cases is quite simple, the function that finds the possible moves is overridden and modified in the pieces that need it.

The biggest problem is calculating which moves are allowed while keeping the king safe. It works the other way around as well, if the king is in check, the game needs to check which moves will protect the king.

To resolve this, there are two functions, one for when the king is in check, and another one that checks each piece’s moves and only keeps the ones that keep the king safe.

If the player cannot move a piece and isn’t in check, the game ends in a draw. If the player cannot move and their king is in check, it result in a loss.

Multiplayer :

With the game being played in multiplayer, i used the session system from Unreal Engine with the Advanced Sessions Plugin to gain more control over the system without having to code.

The session system itself is quite simple, the only condition to play with someone is to be friend with them on Steam.

The person hosting the match creates a session and waits for a second person to join before starting the game. The person searching for a game only has to find a valid session and join it. After that the server will automatically assign a random team to both players and the match can begin.

The difficult part is to understand what the server and the clients need to know and how they communicate to ensure everything works properly without errors.

For example, to move a piece, a function is executed on the client side. This function sends the move data to the Player Controller of the local player. The data is then sent to the server. Finally, the server redistributes the move data to all the players and itself. The move is then executed on all “sides” of the game.

Naturally, not everything is known by the server and all the clients. For example, all the data concerning the possible moves isn’t replicated, since only the local player needs it.