Find Chess960 starting position identifier: Difference between revisions
Find Chess960 starting position identifier (view source)
Revision as of 20:45, 23 July 2022
, 1 year ago→{{header|Python}}: Fix algorithm; add demo code with troublesome examples.
(→{{header|Phix}}: Fix algorithm, add troublesome examples.) |
(→{{header|Python}}: Fix algorithm; add demo code with troublesome examples.) |
||
Line 656:
{{works with|Python|3.10.5 2022-06-28}}
<lang python># optional, but task function depends on it as written▼
▲# optional, but task function depends on it as written
def validate_position(candidate: str):
assert (
Line 672 ⟶ 671:
), f"piece type '{piece_type}' has invalid count"
bishops_pos = [index for index,
value in enumerate(candidate) if value == "B"]
assert (
bishops_pos[0] % 2 != bishops_pos[1] % 2
Line 709:
# step 2
subset_step2 = [piece for piece in start_pos if piece != "
Q = subset_step2.index("Q")
Line 723:
return 4 * (4 * (6*N + Q) + D) + L
if __name__ == '__main__':
for example in ["QNRBBNKR", "RNBQKBNR", "RQNBBKRN", "RNQBBKRN"]:
print(f'Position: {example}; Chess960 PID= {calc_position(example)}')</lang>
{{out}}
<pre>
Position: RQNBBKRN; Chess960 PID= 601
Position: RNQBBKRN; Chess960 PID= 617
</pre>
|