Talk:Generate Chess960 starting position: Difference between revisions
Content added Content deleted
(→Python: Correct by construction?: Add check that all can be generated.) |
|||
Line 138: | Line 138: | ||
from random import choice |
from random import choice |
||
def |
def random960(): |
||
start = ['R', 'K', 'R'] # Subsequent order unchanged by insertions. |
start = ['R', 'K', 'R'] # Subsequent order unchanged by insertions. |
||
# |
# |
||
for piece in ['Q', 'N', 'N']: |
for piece in ['Q', 'N', 'N']: |
||
start.insert(choice(range(len(start))), piece) |
start.insert(choice(range(len(start)+1)), piece) |
||
# |
# |
||
bishpos = choice(range(len(start)+1)) |
bishpos = choice(range(len(start)+1)) |
||
Line 150: | Line 150: | ||
return ''.join(start).upper() |
return ''.join(start).upper() |
||
#print(random960()) |
|||
⚫ | |||
⚫ | |||
"Exact copy of the one above except other pieces are all '_'" |
"Exact copy of the one above except other pieces are all '_'" |
||
start = ['_', '_', '_'] # Subsequent order unchanged by insertions. |
start = ['_', '_', '_'] # Subsequent order unchanged by insertions. |
||
# |
# |
||
for piece in ['_', '_', '_']: |
for piece in ['_', '_', '_']: |
||
start.insert(choice(range(len(start))), piece) |
start.insert(choice(range(len(start)+1)), piece) |
||
# |
# |
||
bishpos = choice(range(len(start)+1)) |
bishpos = choice(range(len(start)+1)) |
||
Line 166: | Line 168: | ||
s, i = set(), 0 |
s, i = set(), 0 |
||
while len(s) < len(starts) and i < 9999: |
while len(s) < len(starts) and i < 9999: |
||
start = |
start = _random960() |
||
check(start) |
check(start) |
||
s.add(tuple(start)) |
s.add(tuple(start)) |
||
Line 175: | Line 177: | ||
if s == starts: |
if s == starts: |
||
print(' Generated all the %i separations in %i attempts' % (len(starts), i)) |
print(' Generated all the %i separations in %i attempts' % (len(starts), i)) |
||
else: |
|||
print(' Error! could not do it in %i' % i) |
|||
print('\nCheck we can generate all 960 randomly:') |
|||
s960, i = set(), 0 |
|||
while len(s960) < 960 and i < 99999: |
|||
start = random960() |
|||
check(start) |
|||
s960.add(tuple(start)) |
|||
i += 1 |
|||
if not i % 500: |
|||
print(' @%5i %5i/960' % (i, len(s960))) |
|||
s960 = sorted(s960) |
|||
if len(s960) == 960: |
|||
print(' Generated all the %i separations in %i attempts' % (960, i)) |
|||
else: |
else: |
||
print(' Error! could not do it in %i' % i)</lang> |
print(' Error! could not do it in %i' % i)</lang> |
||
Line 198: | Line 218: | ||
Check we can generate all separations of bishops randomly: |
Check we can generate all separations of bishops randomly: |
||
Generated all the 16 separations in |
Generated all the 16 separations in 117 attempts |
||
Check we can generate all 960 randomly: |
|||
@ 500 368/960 |
|||
@ 1000 573/960 |
|||
@ 1500 692/960 |
|||
@ 2000 768/960 |
|||
@ 2500 831/960 |
|||
@ 3000 871/960 |
|||
@ 3500 892/960 |
|||
@ 4000 909/960 |
|||
@ 4500 922/960 |
|||
@ 5000 933/960 |
|||
@ 5500 941/960 |
|||
@ 6000 945/960 |
|||
@ 6500 950/960 |
|||
@ 7000 951/960 |
|||
@ 7500 953/960 |
|||
@ 8000 954/960 |
|||
@ 8500 954/960 |
|||
@ 9000 955/960 |
|||
@ 9500 955/960 |
|||
@10000 955/960 |
|||
@10500 955/960 |
|||
@11000 956/960 |
|||
@11500 957/960 |
|||
@12000 959/960 |
|||
@12500 959/960 |
|||
@13000 959/960 |
|||
Generated all the 960 separations in 13166 attempts</pre> |