-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPower of Thor - Episode 1.py
More file actions
64 lines (52 loc) · 1.8 KB
/
Power of Thor - Episode 1.py
File metadata and controls
64 lines (52 loc) · 1.8 KB
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
import sys
import math
light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]
# game loop
# the vectors in wich thor moves in every direction
rightDirs = [
[0, -1],
[1, -1],
[1, 0],
[1, 1],
[0, 1],
]
leftDirs = [
[-1, -1],
[-1, 0],
[-1, 1],
]
# movement commands
# i saperated the right movs and the left ones to seperate the movs with the same
# angle, for example SE => pi/4 and SW => pi/4
rightMovs = ["N", "NE", "E", "SE", "S"]
leftMovs = ["NW", "W", "SW"]
# the angles of every direction (for example N => pi)
# the angles are taken with respect to the y direction or [0, 1] vector
rightAngles = [1*math.pi, 3/4*math.pi, 1/2*math.pi, 1/4*math.pi, 0]
leftAngles = [3/4*math.pi, 1/2*math.pi, 1/4*math.pi]
def move(angle, angList, movsList, dirsList):
global initial_tx, initial_ty
i = 0
for ang in angList:
# the thor->light angle might not be exaclly equal to the movs angles
# so we have this interval
if ang - math.pi*1/8 <= angle <= ang + math.pi*1/8:
print(movsList[i])
# changing to the new position
initial_tx += dirsList[i][0]
initial_ty += dirsList[i][1]
break
i += 1
def ComputeAngle(x, y):
# calculate the angle between [0, 1] and [x, y]
angle = math.acos((0 + 1 * y)/(math.sqrt(1) * math.sqrt(x*x + y*y)))
# checking wich movmens thor has to do, right movs or left movs
if initial_tx <= light_x:
move(angle, rightAngles, rightMovs, rightDirs)
else:
move(angle, leftAngles, leftMovs, leftDirs)
while True:
remaining_turns = int(input())
# computing the vector from thor to the light
vect = [light_x - initial_tx, light_y - initial_ty]
ComputeAngle(vect[0], vect[1])