Is there a free online website that attempts to generate "legal" random chess setups X amount of moves into the game?

  • 1
    I'm curious why you would find such a tool useful May 18, 2012 at 17:51
  • @altvali: No reason.
    – blunders
    May 18, 2012 at 18:08
  • How random do you want them ? Equiprobable ? Do you need a series of moves to lead to that position ? If that's random, what sense does “​X moves into the game” exactly make ? In what format do you want the result ? (FEN, diagram, series of moves…) Dec 8, 2012 at 14:42

7 Answers 7


I stumbled upon Chess Hero. It looks very nice, but it is not online. Per the website:

  1. You supply a set of PGN files
  2. The program picks random positions from the PGN files and challenges you to guess the best move computed by a chess engine
  3. 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.

  • +1 @xaisoft: Interesting, wonder why someone would build a system that's not online. Anyway, as you might guess, this is not really the problem I'm attempting to solve, that being a point-based guess the next move based on archival PGN files; though weighting the random selection of a move on a scale of best to worst was a more advance feature I'd hoped for in the "random opening" game; meaning that you would handicap one-sides opening in a semi-random, yet statistically weighted way.
    – blunders
    May 19, 2012 at 2:13

Find an online database of games. Choose a random game and a random move in that game. Voila, an instant realistic and legal position.

  • It's not the same thing, meaning while it's possible the select of the game, and the point within it might be selected randomly -- the openings would not be random. That said, I realize now that the use of "natural" in the body of the question was confusing, so I've replaced it with legal. Also, might note that currently the answer posted by me covers roughly, if not exactly the method of board generation I'm talking about. Thanks of the suggestion, and I agree that if attempt to select a randomly select a "natural" game it'd be the way to go.
    – blunders
    May 18, 2012 at 21:31
  • 2
    If that's all you need, then what you're talking about would be pretty easy to write. Given that what we're talking about seems useless, I doubt it exists on the web anywhere.
    – Tony Ennis
    May 18, 2012 at 23:58
  • So, you're saying that using stats from chess opening explorer would be more useful (which is likely true), but I'm saying my way would be more fun, and lead to more creative games.
    – blunders
    May 19, 2012 at 0:32
  • 1
    @blunders no, I'm saying that if you want realistic positions, pulling them from real games would be easy. If you want random positions, generating them randomly would be easy.
    – Tony Ennis
    May 19, 2012 at 0:44

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:

  1. Pick a random position from a database.
  2. Play a random amount of random moves.

We should also mention the most simple:

  1. 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.