Is there a free online website that attempts to generate "legal" random chess setups X amount of moves into the game?
I stumbled upon Chess Hero. It looks very nice, but it is not online. Per the website:
- You supply a set of PGN files
- The program picks random positions from the PGN files and challenges you to guess the best move computed by a chess engine
- On every attempt you are given a penalty (the difference in score between your move and the engine best)
The software can be found here.
I've actually programmed precisely that in PHP to test a hypothesis two days ago. If you're interested, I've uploaded the code to github for you: https://github.com/dennisvink/php-random-chess-move-generator
I was unable to find an online tool to do this, but in terms of how, the following appears to be the logic that would be used:
- Both white and black pieces would be in the correct starting positions;
- White would start;
- Turns following white's start would be exchanged between white and black;
- Any piece able to move during a turn would be a member of the list of pieces to be randomly selected to move;
- Once a piece was selected, all squares for that piece that are legal moves would be added to the list of possible moves, and a move would be selected randomly from that list;
- Attacks would not take place unless the attack was randomly selected as a move. If an attack does take place, then the attacked pieced would be removed from the board.
- Iterations of randomly selected moves would stop once the number of moves into the game set before generating the board had been reached.
Besides the two ways already mentioned:
- Pick a random position from a database.
- Play a random amount of random moves.
We should also mention the most simple:
- Generate a totally random position. Validate it. If not legal repeat.
You should be able to find lots of tools for analyzing if a position is legal. (E.g. exactly one king on each side etc.)
How about using live games from lichess? Here is an example call to the server. See the docs for pulling a list of users currently playing.
I think Lichess training do just that. It's software take a game position from it's database and challenge you to pick the best one based on stockfish analysis.