RosettaCodeData/Task/Generate-Chess960-starting-position/Python/generate-chess960-starting-position-2.py
2015-02-20 09:02:09 -05:00

11 lines
291 B
Python

>>> import re
>>> pieces = 'KQRRBBNN'
>>> bish = re.compile(r'B(|..|....|......)B').search
>>> king = re.compile(r'R.*K.*R').search
>>> starts3 = {p for p in (''.join(q) for q in permutations(pieces))
if bish(p) and king(p)}
>>> len(starts3)
960
>>> starts3.pop()
'QRNKBNRB'
>>>