Chess

From UBC Wiki


Authors:

Qingyue, John, Justin

What is the problem?

We decided to make a 2 player Chess game in Prolog! The game takes input from standard in and is able to simulate a game between 2 players inputting moves such as "e4e5". The game also prints its state after every move!

What is the something extra?

Because we didn't learn input and output for Prolog in the class, it was a pretty large task to learn how to receive input from standard in especially with regards to printing out a formatted chess board! Additionally, building the move validator was difficult as there are 6 pieces all with different movement rules.

What did we learn from doing this?

We were able to make a working version of the program with a playable Chess game simulator and visualizer! We learned quite a bit about Input and Output in Prolog as well as how to properly represent a board game like Chess in Prolog. It took quite a while for us to come up with a model for the board and pieces that was easy to work with for all parts of the program (board printing, move inputting, move validating and piece moving).

We ended up coming up with our own strategy for how to represent the board that is quite simple:

- A board is just a list of pieces

- A piece is just something that has an X position, Y position, Color, and Type.

- Color is one of [white, black] (The two colors of chess pieces)

- Type is either a piece type (Pawn, Rook, Knight, Bishop, King, Queen) or "empty" for the empty square

And this was enough for all of our functionality!

Code

Open source on Github Here

Sources

In order to figure out how to use ASCII characters in Prolog with regards to Chess we took some inspiration from: https://github.com/he7850/Prolog-chess-game/blob/master/chess.pl