Posts

Showing posts from September, 2016

The Whole Lot

Previous Games: In this post, I will list all the games and a utility program that I have written till now.By that i mean to say , all the programs that are almost complete (except 1).However it will not include the code that i wrote for testing the programs, the codes that I wrote while practicing various concepts for  OCPJP 7 or codes from competetive programming(because that alone will make more than 200 files.) So , here we go :- QBASIC: These are my most notable programs in Qbasic.For all of them, paste the folders/ files in the Qb64 file location and then open the .bas file in the IDE and run. Ping pong  ~~> This was the first game that I wrote, or indeed, the first program that was more than      30 lines of code.The whole game was written entirely in pen and paper.The only minor problem is that the collision detection is not really that good.Also , understanding the code is quite difficult. Records  ~~>  This is the only utility-type program in

The AI

Image
Min-Max: The AI of the chess engine is actually the min-max algorithm along with some optimizations.I will give certain links for a detailed explanation at the end of this blog but for now i will try to explain it for anyone who does not have even the basic knowledge of graph theory.However recursion is a prerequisite.(Of course, someone with no graph theory knowledge will find it a little difficult, so i suggest that you read the basics , and DFS and BFS. Really, nothing more is required.) Let's say we have a position where white has certain moves(assuming it is white two play).Now, here I should mention that 1 move is actually divided into two ply ,one of white and one for black. Now what min-max does is that we play every move that is possible for white!And then, for every one of the arising positions,we play every move for black!And this goes on as a cycle.I know, this may sound time consuming and dumb as every chess player knows(myself included,being a tournament player

The Move Class

The Move class is probably the only class ( except the classes of the evaluation  package) that I have had to change so many times. The Move  class basically encapsulates the following details: Location from Location to Piece movingPiece Piece capturedPiece ~~> Null if nothing has been captured. More about it in MoveType MoveType type int searchVal ~~> This is for sorting the moves after generating them based on some static features. At first, there were only the aforementioned variables and there getters and setters.However, there were several difficulties.First and foremost was that this representation was not suitable for castling moves. So, I made an enum called MoveType. There are 7 move catagories  Normal ~~> just plain moves Capture ~~> capturing moves ShortCastle_White LongCastle_White ShortCastle_Black LongCastle_Black EnPassent Initially ,   having just learnt enums to quite a extent for the OCP exam, I was really on a mood to try

The Backbone Class ~~> Board Class

BOARD : The board is a simply represented by an array of Spots .  The Spot class performs the basic operations of changing the locations of the pieces through the functions occupy() and vacate().  It also has a couple of other methods like checking if it isOccupied() etc. This brings us to another important class .. Location . I had built this program not for commercial usage and so playing excellent was not a criteria(although it can beat a fritz at 1700-1850 rating ). The location class encapsulates the row and column position of each piece and also helps in easier manipulation as it has a couple of in-built methods. Some of the important methods of the board class are:-   void addPiece(Piece piece,Location l); -- this method adds a piece to the board  void executeMove(Move move); -- makes a move.This move further calls two other methods   a) void executeIndividualMove(Move move)                                                                                 b)   v