Chess program!

Pages: 12
Jan 17, 2012 at 5:52am
So I plan on starting a simple program. I want to make this as OO as possible. The classes I have in mind are:
1. Board
2. Peice(Pawn, bishop, queen, etc.)
3. Move(Tests legality of move.)
4. AI...?

I can't really think of any other I would need. In Move, should I have the pawn swap rules in there? Like, when a pawn reaches the opponents side, user gets to choose to replace the pawn with a better piece.
Jan 17, 2012 at 7:13am
I presume that we are talking about the back-end (the engine).

If you are new to chess programming, the Chess Programming Wiki is a good place to start.
http://chessprogramming.wikispaces.com/

Some more useful links are available here: http://www.top-5000.nl/prostuff.htm



Jan 17, 2012 at 7:24am
I had just planned on having a console front end. The front end wasn't really my concern though, no. I'll check the links out though
Jan 17, 2012 at 12:00pm
Like, when a pawn reaches the opponents side, user gets to choose to replace the pawn with a better piece.


Is this seriously a rule? I love chess and I've not heard of this one before...
Jan 17, 2012 at 12:12pm
Is this seriously a rule? I love chess and I've not heard of this one before...


Yes it is.
Jan 17, 2012 at 12:52pm
Oh, I guess you meant, the opponent's "end".. I know about that.. Rank 1 or 8... for some reason, I was thinking of the half-way mark (Rank 4 and 5's border)... o.O How silly of me... Please don't think I'm dumb.. :(
Jan 17, 2012 at 1:23pm

Like, when a pawn reaches the opponents side, user gets to choose to replace the pawn with a better piece.



Is this seriously a rule? I love chess and I've not heard of this one before...


Are you serious ? You love chess and have no idea about this rule?

Last edited on Jan 17, 2012 at 1:23pm
Jan 17, 2012 at 1:32pm
It's alright, I just learned of the en passant rule of chess while doing research for this. I've never heard of that one before
Jan 17, 2012 at 2:26pm
Don't forget the 50 moves rule too!
Jan 17, 2012 at 2:28pm
Yea that'll be the least of my worries haha. After quite a bit of research, I realize how daunting this project is gonna be now.
Jan 17, 2012 at 3:14pm
> I realize how daunting this project is gonna be now.

Divide and conquer. Take one baby step at a time and make sure that what you have got so far is working correctly, then take the next small step, and so on.

1. Start with the board representation - for example bitboard - which can represent a chess position

2. Add the functionality for basic movement of pieces - how rooks, knights etc. move.

3. Add the more complicated rules - checkmate, castling, pawn-promotion etc. At the end of this step, given any chess position your program should be able to generate a list of valid chess moves. Make sure that this is working perfectly *before* you go any further.

4. Add the functionality to play a complete game of chess, pick an arbitray random move from the list of all legal moves when it is the program's turn to play, wait for the opponent response and repeat.

After that try to make the program intelligent - search trees, evaluation, pruning and so on; the really interesting parts in programming a chess engine.


Jan 17, 2012 at 4:32pm
^ I like the way this guy thinks... I'd do what he says... :D In addition, just as a further step, how cool would it be, if it wrote the game in a text file in standard chess language!? You could store all the games anyone plays, and they could actually map their progress! :D

ThangoDo - I misunderstood what he meant... I realized later that I actually do know all the possible moves and rules in chess..! Knew about the en passant (I used to call it side-step move earlier :P ) and the 50-move draw... (I'm not that good a player though.. I just like playing it.. :D )

Though I do feel programming a chess game in a console would be a tad tedious! Enjoy! :D
Jan 17, 2012 at 6:25pm
I'm excited to get this started. Just hope I'll have time with classes starting back up now. Just the bitboard concept I'm struggling with. Not entirely sure what it is/how it works.
Jan 17, 2012 at 6:42pm
assuming we know it's in C3 how we'll find the location of it in a vector<byte> board(64) ?
Jan 17, 2012 at 9:40pm
Why use a vector? I think an array would be much more efficient. Considering we never have to resize, I see no need for a vector.
Jan 18, 2012 at 3:33am
You can avoid a whole can of worms by using a std::bitset<64> instead of an array.
http://www.cplusplus.com/reference/stl/bitset/

Jan 18, 2012 at 3:50am
@JLBorges : Genius , that's what I expected !
Jan 18, 2012 at 3:57am
Hmm, how would I use this bitset to represent all I need to? I was initially thinking of using a 2D array or 64 element array of struct. The struct would hold information about each square. But, after some digging around I came to the conclusion that this would be highly inefficient.
Jan 18, 2012 at 4:13am
Good luck with this project.

JLBorges, he won't be able to store much information about each square that way :/

On a totally unrelated note, has anyone here played bughouse chess? I've recently started playing it, and it's amazing, definitely try it if you have four people, I like it much more than traditional chess ^^
Jan 18, 2012 at 5:09am
I have not heard of it.

Thanks for the useful links and comments everyone! I'll get back about it once I have something to show (or ran into a problem, which will likely happen first). If anyone wants to join in on the fun, just PM me. I plan on having this quite robust.
Pages: 12