artist has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I am trying to develope a chess program in Perl, which gives me the board position exactly last 'x' moves before the checkmate. The purpose is to create boards to solve in 'x' moves. I tried to use Chess.pm. I think that code has bugs.There are other Chess modules at present but none of them are helpful for the purpose. What alternative I should try?. Are there C libaries which I should make use of?

Thanks
artist.

Update: Replaced the word check by CheckMate
I am trying to generate the 'chess problems'.

Replies are listed 'Best First'.
Re: Chess Moves
by gmax (Abbot) on Jan 10, 2004 at 08:02 UTC
    the board position exactly last 'x' moves before the check

    Are you sure you are talking about chess? :) A "check" is just a move when one of the kings is attacked by a piece from the opposite side. A winning situation is when your opponent's king is "checkmated" (or when your opponent resigns).

    The purpose is to create boards to solve in 'x' moves.

    Those "boards" in chess are called "problems" and they propose situations where you can checkmate in X moves. Alternatively, there are situations where one side moves and achieves a winning advantage (without a given number of moves), and they are called "studies". Which ones are you referring to?

    Anyway, it isn't clear what you want to achieve. If you are trying to create a program for solving a chess problem, then have a look at some chess engines (Crafty and Baby Chess in particular). If you only want to represent positions, then you may use Chess::PGN::EPD, which can validate chess positions and moves and Chess::PGN::Parse, which can parse a game annotated in Portable Game Notation.

    For a sample complete chess program, try SCID, a GPL chess project written in C++.

    Update
    Added references to more chess engines.

     _  _ _  _  
    (_|| | |(_|><
     _|   
    
Re: Chess Moves
by dws (Chancellor) on Jan 10, 2004 at 06:43 UTC
    What alternative I should try?. Are there C libaries which I should make use of?

    Take a look at pychess. It's in Python, and is fairly readable.

Re: Chess Moves
by cbraga (Pilgrim) on Jan 10, 2004 at 17:52 UTC
    You're taking the wrong approach. You want to generate chess, problems, it seems, and your approach, while valid, won't yeld useful results due primarily to two reasons:

    1 - for a given soluction it'll generate hundreds or thousands of possible starting positions

    2 - a chess problem (what you call the original board position) has many subjective qualities, such as beauty, difficulty and likelihood to occur in a regular game.

    If you can develop an algorithm to evaluate a chess problem according to the criterions in #2, you can use that to filter out the hundreds of positions generated in step #1. But would it be worth your while? It might be cheaper to get a good chess player to invent problems for your.

    ESC[78;89;13p ESC[110;121;13p

Re: Chess Moves
by EdwardG (Vicar) on Jan 11, 2004 at 11:41 UTC

    Best of luck with this; defining the problem in this case seems almost as hard as devising a solution, perhaps even harder.

    There's an excellent introduction to chess problems on the British Chess Problem Society website, it suggests that a good problem consists of six basic elements:

    1. a position
    2. a stipulation
    3. one or more intended solutions
    4. difficulty
    5. a theme
    6. originality

    Anyway, I'm interested in what bugs you think might exist in Chess.pm - can you give an example?

A reply falls below the community's threshold of quality. You may see it by logging in.