Last active
December 9, 2020 21:05
-
-
Save mtimkovich/3174075 to your computer and use it in GitHub Desktop.
Chess960 Initial Position Generator (Python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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