Analysis
Analysis
Analysis
Background to and identification of problem
I am keen to undertake this project because I am interested in algorithms and wish to explore this
topic in greater detail. Algorithms are very important to computer science and a good understanding
of these can open doors for more complex programs to be created.
Chess is a great game to start on because while keeping simple rules, it is more complicated at its
core, since there are so many different combinations of moves that each player can make.
Algorithms can be quite difficult to understand at first, as they can become extremely complicated
very quickly. Chess would serve as a good frame to help me understand this better, as I would be
able to utilise my knowledge of chess to help me follow each step in the minimax algorithm, which is
the main algorithm I will be using in this project.
Many people may want to start playing chess, however they may be scared away by the apparent
complexity of the game. My program will teach novice players how to play the game in a private
setting, against a watered-down algorithm, allowing them to learn the basics, improve, and
eventually compete against harder AI or other players. It will also however allow more seasoned
chess players to practice their game against harder AI and test their skills against the algorithm. It
also serves as an alternative to a chess board; this is more travel friendly and may also help those
who do not own a chess board. This would also help people who would like to try out chess, and see
if they find enjoyment in this game, without having to invest in a chess board.
You can play chess on a physical chess board; this can’t be done absolutely everywhere and requires
set up.
In addition to this, you can also play chess on chess programs. These are available as an application
on your phone, as a computer program, and hosted on several websites. These are usually quite
simple and do a good job of representing a physical chess board; aside from the installation of the
program itself, they are easy to set up and play, although from my experience (as a beginner) a lot of
these are not beginner friendly, often lacking a wide selection of difficulties. Hardware requirements
are minimal; they are usually able to run normally on most devices if they have the storage space for
it.
1
Noah Schutte
Fig 2. Chess Free, a chess program downloadable from the Microsoft store.
Chess AI are most commonly made using an algorithm known as Minimax. This involves feeding the
algorithm all the possible moves that could be made from the current state of the board, calculating
all the possible moves after that until you reach the specified depth (how many moves to search
ahead, e.g. depth 3 = search 3 moves ahead). Each of these moves are assigned point values, e.g. if a
queen is taken you gain 90 points, if you lose a queen, you lose 90 points; this enables self-
2
Noah Schutte
preservation and provides an incentive for the AI to take opposing pieces. The program then
recursively finds the move in which point yield is maximised, assuming that the opponent will also be
choosing the best possible move.
Made in Paint.
Chess AI, whilst able to play chess well, either suffer from being too slow if the algorithm is pushed
to search too many moves ahead, or end up making mistakes due to not being able to see many
moves into the future or use advanced chess tactics such as moving pieces to strategically
advantageous positions. One way to solve this issue is giving the algorithm more avenues to earn
points; for example, reward the AI for moving certain pieces to advantageous positions by assigning
point values to those coordinates.
Prospective users for this console chess program could be anyone with a PC and any interest in
playing chess.
Identification of user needs and acceptable limitations (use of formal methods, e.g. observation,
analysis of existing paperwork, interviews, surveys)
My client is my mother; she is not very experienced with playing chess and would like to be able to
learn and improve. She is also very busy, so it is important for her to be able to pick the program up
at a moment’s notice and progress in her own time.
Client: I’m not very experienced at playing chess. I would like to learn how to play chess and be able
to do it in my own time.
3
Noah Schutte
Client: Well, I think it should be like the real chess game, with the same mechanics. I would like it to
help me learn and improve my game. As I am busy, I should be able to continue your game at a later
date. I would like it to keep my scores and those of my opponent.
Me: So, you want to be able to save your game to your computer and load the save game later?
Client: Yes, I’d like to be able to go back to any saved game at a later date.
Me: Do you think it would be useful to be able to transfer saves to different computers?
Client: As long as the login and setup is easy, that would be great.
Me: Yes, it’s easy, all it requires is the program and the save files. You just run the executable and
then from the program you can load the save.
Client: Ok, can it be in simple language when I login, making it clear in asking me what I want, such
as asking me if I want to start a new game or go back to an old one?
Me: Do you want the game to show you all possible moves?
Client: Yes, that would be great to help me learn the game and see what else I could do to improve.
Client: Yes, because at the start the easy function would allow me to learn, and as I get better I could
progress to the more difficult functions.
Client: I would like to be able to play on my own and have the choice to invite people I know.
Me. The multiplayer would work on one device, you just pass the controls back and forth.
Takeaways
The program should be easy to use and understand, with a user-friendly interface. This should allow
the client to pick the program up with no experience of chess and be able to quickly understand the
fundamentals of chess. Given the restrictions of the console and my limited programming
experience, I propose the ability to select different game-modes and difficulties. This will allow the
user to choose to play with their friends, play against AI, and watch two AI against each other. This
way the user can watch the AI play and start to understand basic chess tactics. Additionally, the user
can test out their new tactics against a beginner AI, allowing them to learn chess in a real game
without the stress of losing. Finally, the program should allow the user to play with their friends and
family; this allows users to test their skills against each other.
The program should allow the user to save and load game states at appropriate times, allowing the
user to come back to their game at any time; this is important because chess games can be very
4
Noah Schutte
long, and my client would not necessarily have time to sit through an entire chess game. It could
however be confusing to come back to a chess game after a while, as the user may not remember
what had happened previously. My solution to this problem is a vibrant board with user friendly
features, clearly displaying each of the pieces, the last move made, the current turn, etc; this allows
the user to not only quickly get back into the game, but to also enable the user to follow games
much more easily.
a. The pawn moves one square forward. At the start of the game, it can move two squares
forward. Once it has been moved it can no longer do this. It can only take pieces diagonally
left or right in front of it.
b. The king moves exactly one square horizontally, vertically, or diagonally.
c. A rook moves any number of vacant squares horizontally or vertically.
d. A bishop moves any number of vacant squares diagonally.
e. The queen moves any number of vacant squares horizontally, vertically, or diagonally.
f. A knight moves to the nearest square not on the same rank, file, or diagonal. (This can be
thought of as moving two squares horizontally then one square vertically, or moving one
square horizontally then two squares vertically—i.e. in an "L" pattern.) The knight is not
blocked by other pieces: it jumps to the new location.
g. When a piece is moved on top of the other player’s piece, the other player’s piece is taken.
2. Algorithms
a. Check and checkmate detection. Display all possible moves to save king piece (if it can be
saved; if not game over) and force the player to use one of these moves.
b. Legal move resolution (so that you cannot put yourself in check).
4. Game Parameters
5. User Interface
5
Noah Schutte
h. A command allowing the user to move the piece. Reflect this move on the board.
6. Advanced
a. If the game reaches a point where it is unlikely to progress, a draw state should be reached.
b. Advanced chess rules: En passant - You can capture en passant when your opponent pushes
his pawn twice (to the 4th rank (white) or the 5th rank (black)) and you have a pawn sitting
next to it. Then you can capture the pawn as if it only moved one square - but only
immediately after the pawn push of your opponent, you can't delay this. Castling - Castling is
a move in the game of chess involving a player's king and either of the player's original
rooks. It is the only move in chess in which a player moves two pieces in the same move, and
it is the only move aside from the knight's move where a piece can be said to "jump over"
another. Promotion - Promotion in chess is a rule that requires a pawn that reaches its
eighth rank to be replaced by the player's choice of a queen, knight, rook, or bishop of the
same colour. The new piece replaces the pawn within the same move.
c. Ability to save games, store them, and load saved games and continue where you left off.
Research
• Basic Chess AI Tutorial (Algorithms) to help me have a basic idea of how to create the
working program and the algorithm(s) involved. This was also the first inspiration for my
project.
https://www.freecodecamp.org/news/simple-chess-ai-step-by-step-1d55a9266977/
• Rules of Chess to ensure the program abides to the rules of the game.
https://en.wikipedia.org/wiki/Rules_of_chess
• How to Save/Load (Game) Object to understand how to save and load each game.
https://stackoverflow.com/questions/6115721/how-to-save-restore-serializable-object-to-
from-file
Modelling
6
Noah Schutte
Credit to wikipedia
Proposed System
A simple and easy to understand chess game run in the console. Allows the user to play a chess
game and start to learn the fundamentals of chess.
Each piece will be identified as an object. The default Piece class will be used to represent a pawn,
and each different type of piece will be a subclass of the Piece class. Each Piece will contain
attributes to designate their team, the point value of the piece, the number of times the piece has
been moved, the ‘symbol’ used to display the piece on the board and whether the piece is dead or
not. Each Piece will be able to return every possible position it could move to when given a copy of
the board and its position on it. The game itself will also be an object. Within the Game class, a 2D
array of type Piece will be created to simulate a board. The IsDead attribute within the Piece class
can be used to designate a place on a board where no piece exists. The Game class will also keep
track of the turn. There will also be an attribute used to simulate the hand of the player. This
attribute will store the x and y values of the piece the player has selected.
Piece
Attributes:
Team
IsDead
Symbol
MoveCounter
Points
Methods:
GetSymbol
GetMovementList
Game
Attributes:
Board
Turn
7
Noah Schutte
Hand
AIPlayer1
AIPlayer2
Methods:
ResetBoard
PrintBoard
Pick
Place
Run
Fig. 1
8
Noah Schutte
Fig. 2