Computer Chess Club Archives


Search

Terms

Messages

Subject: Outputting randomized mate problems

Author: Andrew Wagner

Date: 06:51:35 03/10/05


I barfed out this pseudo-code this morning for fun. The goal is to generate
(about) 1000 random mate problems in (very roughly) increasing order of
difficulty. Have a look and see what you think. Is the logic ok? (Especially for
the simple mate-finder) Do you think the over-all idea will work?

Don't mind the faked code and the unwritten functions, I was just trying to get
the idea down before filling in the blanks.

void main(void) {
    for (int MateLength = 1; MateLength <= 3; MateLength++)
        for (int TotalPieces = 1; TotalPieces <= 10; TotalPieces++)
            for (int NumDefenders = 0; Defenders < TotalPieces; Defenders++)
                for (int Positions = 0; Positions <=5; Positions++)
                    GenPosition();
}

void GenPosition() {
    for (;;) {
        InitBoard();
        PlaceKings();
        for (int Piece = 0; Piece < TotalPieces; Piece++)
            PlacePiece();
        if MateIn(MateLength * 2 - 1) }
            OutPutFen();
            break;
        }
    }
}

int MateIn(int depth) {   //returning a boolean
    if (!depth) return (perft(0) == 0);
    GenMoves();
    for (int Move = 0; Move < NumMoves; Move++) {
        MakeMove(MoveList(Move));
        if (depth && 1) {
            if (MateIn(depth - 1)) {
                takeback();
                return(1);
            }
        } else {
            if (!(MateIn(depth - 1)) {
                takeback();
                return(0);
            }
        }
        takeback();
    }
    return (!(depth && 1));
}

/*************************************************
Min(x,y) - Macro that returns the lesser of x and y
InitBoard() - Initialized the board and piece list (duh), makes them empty
Random() - randomly returns a 0 or 1
PlaceKings() - Places both kings on the internal board, making sure they aren't
    attacking each other.
PlacePiece() - This is the most complex function I haven't done the basic logic
for yet. Basically, it just places a random piece on a random square, avoiding
headaches like putting opposing king in check, pawns on the 8th, etc. Eventually
I want to weight pieces and squares in this function to make more realistic
positions. In this function, if Piece <= NumDefenders, this piece will belong to
the side being mated.
OutputFEN() - outputs FEN for the position currently on the internal board
GenMoves(), perft(), MakeMove(), and takeback() - these all do what you would
expect them to do if you saw them in a normal engine. Moves generated and made
are legal moves only, not pseudo-legal moves.*/



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.