-
Notifications
You must be signed in to change notification settings - Fork 0
/
13.py
80 lines (67 loc) · 1.89 KB
/
13.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
75
76
77
78
79
80
from IntCodes import IntCodes
def parse_input():
program = []
with open("13.in") as input:
for line in input:
line = line.strip()
program += list(map(int, line.split(",")))
return program
def game():
program = parse_input()
runner = IntCodes()
controls = []
process = runner.run_program(program, controls)
board = [[0 for i in range(50)] for j in range(20)]
score = 0
ball_x = None
paddle_x = None
while True:
try:
x = next(process)
y = next(process)
tile = next(process)
if x is None or y is None or tile is None:
break
if x == -1 and y == 0:
score = tile
continue
if tile == 0:
board[y][x] = 0
else:
board[y][x] = tile
if tile == 4:
ball_x = x
elif tile == 3:
paddle_x = x
# print_game(board, score)
if ball_x is not None and paddle_x is not None:
runner.input = [
-1 if ball_x < paddle_x else 1 if ball_x > paddle_x else 0
]
except StopIteration:
break
# part 1
# print(sum([sum([1 if cell == 2 else 0 for cell in row]) for row in board]))
print(score)
print_game(board, score)
def print_game(board, score):
for row in board:
print(
"".join(
[
"|"
if c == 1
else "#"
if c == 2
else "_"
if c == 3
else "*"
if c == 4
else " "
for c in row
]
)
)
print(score)
print("======================")
game()