-
Notifications
You must be signed in to change notification settings - Fork 0
/
LanderSimulator.cs
66 lines (56 loc) · 1.63 KB
/
LanderSimulator.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace useAIble.GameLibrary.LunarLander
{
public class LanderSimulator
{
public const double Gravity = 1.62;
public const double Thrust = 10;
public const double TerminalVelocity = 40;
public LanderSimulator()
{
Fuel = 200;
Seconds = 0;
Altitude = 10000;
Velocity = 0;
}
public int Fuel { get; set; }
public int Seconds { get; set; }
public double Altitude { get; set; }
public double Velocity { get; set; }
public int Score
{
get { return (int)((Fuel * 10) + Seconds + (Velocity * 1000)); }
}
public void Turn(bool thrust)
{
Seconds++;
Velocity -= Gravity;
Altitude += Velocity;
if (thrust && Fuel > 0)
{
Fuel--;
Velocity += Thrust;
}
Velocity = Math.Max(-TerminalVelocity, Velocity);
Velocity = Math.Min(TerminalVelocity, Velocity);
if (Altitude < 0)
Altitude = 0;
}
public String Telemetry()
{
return string
.Format("Elapsed: {0} s, Fuel: {1} l, Velocity: {2} m/s, {3} m",
Seconds,
Fuel,
Velocity.ToString("#0.####"),
(int)Altitude);
}
public bool Flying
{
get { return Altitude > 0; }
}
}
}