

#Unbeatable chess ai code#
I have designed the application in a way that, if the user interface is to be improved (for example, if someone decides to fork this code and develop a GUI), no changes should be made in the chess.cpp file.

user_interface.cpp: Basically consists of functions printing information to the console, like printing the board, last moves, menu, messages for the user, etc.It also contained functions to determine if the king is in check, if castling is allowed, if a square is occupied, everything that is necessary to verify if a move is valid or not. It stores all the information that a single game has, like the position of every piece in the board, list of moves made, list of pieces captured. The second one is called Game, it inherits from Chess. The first one is named Chess and contains enums, structs and simple functions to describe chess pieces, colors and the board. Prompts the user for an action ( new game, move, undo, save, load, quit) and, depending on the action to be performed, prompts for more information and call the functions from the other files. main.cpp: Entry-point of the application.Game.getPieceAtPosition(iLine,iPair*2+1) : iColor2) Game.getPieceAtPosition(iLine, iPair* 2) : iColor1) Ĭout < < char(game.getPieceAtPosition(iLine,iPair*2+1) != 0x20 ? The piece should be in the "middle" of the cellĬout < < char(game.getPieceAtPosition(iLine, iPair* 2) != 0x20 ? A sub-line is consisted of 8 cells, but we can group itįor ( int subColumn = 0 subColumn < CELL subColumn++) So if we have CELL characters, we must have CELL/2 sublinesįor ( int subLine = 0 subLine < CELL/2 subLine++) we need to use two characters in a row.


Since the width of the characters BLACK and WHITE is half of the height, (an odd number will make the squares look rectangular) You can change it to alter the size of the board The number of vertical characters will be CELL/2 It represents how many horizontal characters will form one squarite Void printLine( int iLine, int iColor1, int iColor2, Game& game) PrintLine(iLine, WHITE_SQUARE, BLACK_SQUARE, game) PrintLine(iLine, BLACK_SQUARE, WHITE_SQUARE, game) We can use the ASCII characters 0xDB and 0xFF to draw white and black cells, respectively. I will try to explain some of the concepts I used when developing the game, if anything is not clear or if I missed an important point, please let me know in the discussion. They are all represented by the first letter of their names, the only exception being the Knight, which is represented by an N, leaving the K for the king): The white pieces are represented by capital letters and the black pieces are represented in lowercase letters. All the input is taken from the keyboard, and for that, it uses the Coordinate Notation. This game runs in a console, i.e., that means no GUI is available to the user. Does not have artificial intelligence (AI).The size of version 1.0 of the application is 155 KB. Nevertheless, there's no demerit on developing a simpler, lightweight piece of software, specially aiming for didatic purposes. There are lots of implementations of Chess' games available on the internet, most of them richer in features than this one.
#Unbeatable chess ai free#
Source Codeįeel free to fork the project on GitHub. (If don't have the VS 2015 Redistributables, please find it here). If you want to verify the hash for the executable after unzipped, the SHA-1 is: 7B69131E72320DF6DEE49ED6E1CCBD6ACE95082F.
