Pseudochess


#1

hey guys,

kinda OT, but I’ve been working on a chess program lately. The reason I am not calling it a chess computer is because there is no AI yet. =) Thats the part I really have no idea where to start with. But I have gotten it to recognize legal moves except for when the king is in check (still working on that).

anyway, I have a feeling that the way I’ve written the program might be kind of ineffecient. But if anyone is good with AI, and thinks I might be able to turn what I have into a chess computer, feel free to give some pointers. (or tell me how much it sucks =). I’ve never seen source code to a chess computer so there is a lot of guesswork here.


#2

ok try this link instead

it might be a little slow


#3

Sorry, but I don’t know a thing about AI. Your script looks very good and neat though, does it run when you compile it yet?


#4

yep it compiles fine. I used Dev-Cpp to write it, but its just a standard c++ compiler (www.bloodshed.net) so you should be able to compile with say borland or visual c++. I’ve done a lot more on it lately, and I almost have it so that the program can detect when the king is in check or not.


#5

Maybe this helps:
http://www.chessbrain.net/beowulf/
and
http://www.tim-mann.org/gnuchess.html with source code.


#6

Ok if you click on the link again, I have changed it to version 0.4

changes include:

EVERYTHING. its now a fully functional chess “syntax checker” so it will allow only legal moves and will detect when a player has been checkmated, etc.

ok I lied, there is one thing I still haven’t added. Its that rule in chess (don’t remember what its called) where if you move your pawn up 2 spaces (first move) to skip past an opponent pawn, he can still move diagonally into the square that you passed through, and take your pawn. other than that, everything works. minus the AI. so its 2 player.

heres a screenshot of it…


#7

That rule in chess is called en-passant (pronounced something like “on-pasSON”).

I wrote a chess program with AI a few years ago. It isn’t really that difficult; the hardest part is finding all the legal moves, since it’s so tedious. My program isn’t exactly what you would call great, but it does play pretty well. You can download the game at http://ce.sharif.edu/~ahmadinejad/HamedChess.zip

Anyway, afterwards, I wrote an article explaining the algorithms and how everything is done, with pseudocode examples. You can see it at: http://ce.sharif.edu/~ahmadinejad/gametree

Good luck!


#8

you know the more I think about it, the more I am reluctant to get help, its sort of becomming my obsession. I’m trying to do it by myself. I thought it was hard programming the legal moves while I was doing it but that all seems trivial now that I am working on the AI.

The one thing I would like to ask though is, how many lines of code did you use? I’m curious to see if it can be done with less than 1000.


#9

I can completely relate! Looking at how other people do it just spoils the fun!

But I still recommend that you read up a bit on Min-Max trees and Alpha-Beta pruning… They’re the bare basics.

My engine is about 1600 lines. But a lot of that is commented code. So I’d say yes, it is possible to do it in 1000 lines. (I use about 200 lines of code just to efficiently handle the three-position-repetition draw condition. You could save a lot of code by not considering that!)


#10

did you design the min-max tress and stuff? I played your chess program and it is pretty good, it beats me about half of the time. About 200 lines of my code is used to handle printing out the checkered board on the console screen. If I were to later make a win32 version of it, I could junk all that. Did you check out my code? Most of the functions are boolean…

isLegal() - returns true if the move is legal
inCheck() - returns true if the king is in check (called by isLegal)
inRange() - returns true if a piece is in range of the king (called by inCheck)
DL_OBS() - returns true if there are obstacles along a diagonal path (if the queen or bishop jumped a piece)
HV_OBS() - returns true if there are obstacles along a horizontal or vertical path (if the queen or rook jumped over a piece).

One other thing I wanted to ask was, how did you choose to represent the board? I used an 8x8 array and decided that a value of 0 means the square is empty and a value between 1 and 12 means a piece is there. I used an enumerated list to represent the pieces.


#11

Design Min-Max trees? Don’t know exactly what you mean… I pretty much used standard textbook algorithms.

How I represented my board? Well, I keep a list of pieces for each player, and I store the location of each piece. I also store in each square, information about the piece, if any, that is in that square. I believe I held the color and piece separate, as two enums. I even calculated and updated the “pressure” on each square. (The number of pieces of each color that can attack that square.) All of this is updated when a piece is moved.

I took a quick look at your source and I have on suggestion for you: Don’t use row+col to reference your squares. Just number the squares from 0 to 63. That way, each square is represented by a single integer, which is both faster and more convenient. And also easier to store lists of valid moves as position offets. For example, the list of legal moves for a king would be {8, 7, -1, -9, -8, -7, 1, 9}. This is much better than generating every move and seeing if it’s legal!

One common representation is called the “and 0x88” board. In it, the board positions are numbered from 0 to 127, 8 rows of 16. You only use the leftern 8 columns; the rest is wasted. The cool thing about this is, while you’re sliding a piece, you can check whether it’s gone off the board or not simply by And-ing it with 0x88! (position P is inside if (P & 0x88)==0)


#12

thats an interesting idea of having the squares numbered from 0 to 63 however, I would have to rewrite a TON of stuff and I’m probably just going to stick with what I have at this point.

btw, yea I was asking if you had designed that alpha beta pruning or whatever


#13

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.