Skip to content

Instantly share code, notes, and snippets.

@mtimkovich
Last active December 9, 2020 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtimkovich/3174075 to your computer and use it in GitHub Desktop.
Save mtimkovich/3174075 to your computer and use it in GitHub Desktop.
Chess960 Initial Position Generator (Python)
#!/usr/bin/env python
import random
def empty(lst):
return [i for i, value in enumerate(lst) if value == 0]
board = [0] * 8
# Bishops
for i in range(2):
r = random.randrange(0, 7, 2) + i
board[r] = 'B'
# Queen, Knights
for i, piece in zip(random.sample(empty(board), 3), list('QNN')):
board[i] = piece
# Rook, King, Rook
for i, piece in zip(empty(board), list('RKR')):
board[i] = piece
# Print board
print(' '.join(map(str, board)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment