Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
chess move generator
#1
Alright here is the challenge:
Write a program which takes as input a chess board, like so:

Code:
rnbqkbnr
pppppppp
........
........
........
........
PPPPPPPP
RNBQKBNR
castle=KQkq
enpas=
turn=W

And then outputs all legal moves for that position, taking into consideration castling and en passant.

The input is shown from white's perspective (in other words, A8 is upper-left, H8 is upper-right, A1 is lower left, H1 is lower right)
castle= tells about castling legalities
K=white kingside legal, Q = white queenside legal,
k = black kingside legal, q = black queenside legal
enpas= tells which (if any) file en passant is legal on, e.g.,
enpas=C mean en passant is legal on the C file.
turn= tells whose turn it is (so don't check for white's legal moves if it's blacks turn). Can either be W or B
and for the pieces:
K=white king, k=black king,
Q=white queen, q=black queen
R=white rook, r=black rook,
B=white bishop, b=black bishop,
N=white knight, n=black knight
P=white pawn, p=black pawn,
. = empty square


The output should be a list of moves, seperated by either comma or new line (at your leisure)
And the output may be in coordinate notation, or, if you're really feeling up to the challenge, in Algebraic notation
for example, for white castling kingside,
E5-E7 is acceptable, the proper way, however would be "o-o"
Algebraic notation would be like this:
e2-e4 (pawn move) would just be e4
e4-d5 (pawn capturing) would be exd5
g1-f3 (knight move) would be Nf3
in algebraic notation, captures use a "x" instead of "-",
and you use the name of the piece moving rather than just coordinates (e.g., Nf3), unless the piece moving is a pawn in which case all you need is the destinateion coordinate (e.g., e4)
also in algebraic notation, en passant moves have a little "ep" at the end (example: exd3ep)
Also, if more than one piece of the same type can move to a given square, it must disambiguate by specifiying the unique rank or file of the moving piece (example: Ng-f3 which reads "knight on G to f3)
And, kingside castling is marked as "o-o" and queenside as "o-o-o"

Also, obviously it must print all the legal moves, and only the legal moves, so if it's white's turn it should not show moves that put white in check.

This would be an example output from the input shown above:

Code:
legal moves:
a2-a3
a2-a4
b1-a3
b1-c3
b2-b3
b3-b4
.....
h2-h4
end of list


Obviously this requires a basic knowledge of the rules of chess. (not to mention an interest)

By the way, if you're wondering, I'm not trying to get anyone to do my homework for me (I've actually already completed this challenge but found it to be pretty fun and really get the mental juices flowing)
So... good luck

Peace
-- Eric / neuro
ignatures suck
Reply
#2
>>I've actually already completed this challenge<<

Cool... post your completion, and I'm sure someone will give you their opinion of it... they might even post their own unique solution too :wink:

Nemesis
Reply
#3
Sure

NOTE: this is a solution so it is a total spoiler, if you actually intend to attempt this then I recommend you not looking at the link below.

But if you really get stuck you can look at it for some hints...

source code

-- Eric / neuro
ignatures suck
Reply
#4
I think I'll give it a go. I would prefer to make a learning one instead, which would be alot harder. I have done some work on learning AI's and it is possible, with a bit of work. I have seen a checkers program that can learn, and it was coded in qb. Also how come I never got to do QB for school, I get stuck with python instead.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)