-
Notifications
You must be signed in to change notification settings - Fork 0
/
mars_land.rb
110 lines (87 loc) · 2.24 KB
/
mars_land.rb
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
100
101
102
103
104
105
106
107
108
109
110
class MarsLand
def initialize
STDOUT.sync = true # DO NOT REMOVE
$N = gets.to_i # the number of points used to draw the surface of Mars.
$MAP = Array.new
$N.times do
$LAND_X, $LAND_Y = gets.split(" ").collect { |x| x.to_i }
$MAP<< [$LAND_X, $LAND_Y]
end
#get_atterissage_surface
f = $MAP.first
x, y = f
x1, y1 = f
(1..($MAP.length-1)).each do |i|
if $MAP[i][0] - x > 1000 and $MAP[i][1] == y
x1, y1 = $MAP[i]
break
else
x, y = $MAP[i]
end
end
# game loop
loop do
# HS: the horizontal speed (in m/s), can be negative.
# VS: the vertical speed (in m/s), can be negative.
# F: the quantity of remaining fuel in liters.
# R: the rotation angle in degrees (-90 to 90).
# P: the thrust power (0 to 4).
$X, $Y, $HS, $VS, $F, $R, $P = gets.split(" ").collect { |x| x.to_i }
r_init = $R
if (x - ($X ) ) > 0
$R -= 15 if $R >= -75
if (x - $X) < 150 or $VS.abs >= 35
$R += 15 if $R.abs > 30
end
if $HS.abs >= 40 and $VS.abs < 45
$R += (15 - ($R - r_init))
end
elsif (($X) - x1) > 0
$R += 15 if $R <= 75
if ($X - x1) < 150 or $VS.abs >= 15
$R -= 15 if $R.abs > 30
end
if $HS.abs >= 40 and $VS.abs < 45
$R -= (15 - ($R - r_init) )
end
else
if $HS > 19
$R -= 25 if $R.abs > 30
end
# if
if $R.abs < 15
$R = 0
elsif $R > 15
$R -= 15
else
$R += 15
end
if $VS.abs >= 35
$P += 1 if $P < 4
else
if $Y - y >500
$P > 1 ? $P -= 1 : $P = +1
end
if $Y - y > 50 and $Y - y < 500
($P >3) ? $P -= 1 : (($P > 1)? $P = $P : $P +=1 )
end
if $Y - y < 50
$P -= 1 if $P >0
end
end
if $HS > 19
$R += 10 if $R.abs < 80
else
$R -= 10 if $R.abs < 80
end
end
if (x - $X) > 0 or ($X - x1) > 0
$P += 1 if $P < 4
end
$R += 25 if $R < -90
$R -= 25 if $R > 90
puts "#{$R} #{$P}"
end
end
end
MarsLand.new