-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13.py
99 lines (90 loc) · 2.47 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import curses
import time
from intcode import intcode_v3
with open('../13.txt') as f:
i = [int(x) for x in f.read().split(',')]
arcade = intcode_v3(i)
count = 0
try:
while True:
next(arcade)
next(arcade)
t = next(arcade)
if t == 2:
count += 1
except StopIteration:
pass
print(count)
def second(stdscr):
i[0] = 2
arcade = intcode_v3(i)
score = 0
paddle_x = None
paddle_y = None
ball_x = None
ball_y = None
old_ball_x = None
old_ball_y = None
curses.curs_set(False)
def update(x, y, t):
nonlocal score
nonlocal paddle_x
nonlocal paddle_y
nonlocal ball_x
nonlocal ball_y
nonlocal old_ball_x
nonlocal old_ball_y
if x == -1 and y == 0:
score = t
stdscr.addstr(0, 0, str(score))
elif t == 0:
stdscr.addstr(y+1, x, ' ') #empty
elif t == 1:
stdscr.addstr(y+1, x, '|') #wall
elif t == 2:
stdscr.addstr(y+1, x, 'X') #block
elif t== 3:
stdscr.addstr(y+1, x, 'T') #paddle
paddle_x = x
paddle_y = y
elif t == 4:
stdscr.addstr(y+1, x, 'o') #ball
old_ball_x = ball_x
old_ball_y = ball_y
ball_x = x
ball_y = y
else:
raise ValueError
stdscr.refresh()
try:
while True:
x = next(arcade)
if x is None:
if old_ball_x is None:
old_ball_x = ball_x - 1
old_ball_y = ball_y - 1
motion_x = ball_x - old_ball_x
motion_y = ball_y - old_ball_y
if motion_y > 0:
steps = paddle_y - ball_y - 1
target = ball_x + steps * motion_x
#if steps == 0 and target == paddle_x and random.:
#target += motion_x
else:
target = ball_x
if target > paddle_x:
stick = 1
elif target < paddle_x:
stick = -1
else:
stick = 0
#stick = int(input())
time.sleep(0.05)
x = arcade.send(stick)
y = next(arcade)
t = next(arcade)
update(x, y, t)
except StopIteration:
pass
curses.wrapper(second)
print(score)