Created
June 3, 2020 00:06
-
-
Save UlisseMini/631e8db5837e735befae13982e68f69b to your computer and use it in GitHub Desktop.
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
import chess | |
import statistics | |
import random | |
def median_move_count(b, depth = 3): | |
if depth < 0: return [] | |
mvs = [] | |
mvs.append(len(list(b.legal_moves))) | |
for move in b.legal_moves: | |
b.push(move) | |
mvs += median_move_count(b, depth = depth - 1) | |
b.pop() | |
return mvs | |
# total_moves, avg_movecount | |
def length_of_random_game() -> (int, int): | |
b = chess.Board() | |
movecounts = [] | |
while not b.is_game_over(): | |
legal_moves = list(b.legal_moves) | |
movecounts.append(len(legal_moves)) | |
b.push(random.choice(legal_moves)) | |
return len(b.move_stack), statistics.mean(movecounts) | |
# mvs = [] | |
# avg_possible = [] | |
# for _ in range(1000): | |
# mvcount, avg_poss = length_of_random_game() | |
# print(mvcount, avg_poss) | |
# avg_possible.append(avg_poss) | |
# mvs.append(mvcount) | |
# print(statistics.mean(mvs), statistics.mean(avg_possible)) | |
# => 364.375 22.794588314087207 | |
avg_movecount = 364.375 | |
avg_possible = 22.794588314087207 | |
print(f'{avg_possible:.3f} ^ {avg_movecount:.3f}') | |
print(round(avg_possible) ** round(avg_movecount)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment