-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmove_sequence_draw.py
74 lines (51 loc) · 1.99 KB
/
move_sequence_draw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from game_extrapolation import extrapolate_all_games, remove_near_duplicates
from specific_games import start_game
from utils import flat_format
import numpy as np
games = extrapolate_all_games([start_game], prune_symmetrical=True, skill=4)
games = remove_near_duplicates(games)
flattened = [flat_format(x) for x in games]
move_sequences = [[int(np.argwhere(array[i] != array[i-1])[0]) + 1 for i in range(1, len(array))]
for array in flattened]
all_moves = {}
for move_sequence in move_sequences:
current_move_dict = all_moves
for move in move_sequence:
if move not in current_move_dict:
current_move_dict[move] = {}
current_move_dict = current_move_dict[move]
# -------------------------- Pygame script -------------------------------
import pygame
SCREEN_DIM = 1920, 1080
MARGINS = 100, 100
x_step = (SCREEN_DIM[0] - 2 * MARGINS[0]) / 8
y_step = (SCREEN_DIM[1] - 2 * MARGINS[1]) / 8
def draw_move_lines(screen, move_dict, origin=None):
if origin:
for x in move_dict:
endpoint = origin[0] + x_step, MARGINS[1] + (x - 1) * y_step
pygame.draw.line(screen, (255, 255, 255), origin, endpoint, 2)
draw_move_lines(screen, move_dict[x], endpoint)
else:
for x in move_dict:
draw_move_lines(screen, move_dict[x], (MARGINS[0], MARGINS[1] + (x - 1) * y_step))
def main():
# Initialize pygame
pygame.init()
# Set up the display
screen = pygame.display.set_mode(SCREEN_DIM)
# Set running to True to keep the window open
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Fill the screen with a black color
screen.fill((0, 0, 0))
# Draw a single white line segment
draw_move_lines(screen, all_moves)
# Update the display
pygame.display.flip()
pygame.quit()
if __name__ == "__main__":
main()