/
Solution.cs
58 lines (42 loc) · 1.39 KB
/
Solution.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
using System;
using System.Linq;
using System.Collections.Generic;
public class Solution
{
private int _turnCount = 0;
private Brain _brain;
private Grid _gameGrid;
public Solution()
{
_gameGrid = new Grid();
_brain = new Brain(_gameGrid);
// If you need initialization code, you can write it here!
}
/**
* Executes a single step of the tank's programming. The tank can only move,
* turn, or fire its cannon once per turn. Between each update, the tank's
* engine remains running and consumes 1 fuel. This function will be called
* repeatedly until there are no more targets left on the grid, or the tank
* runs out of fuel.
*/
public void Update()
{
// Todo: Write your code here!
Console.WriteLine("Turn #{0}", ++_turnCount);
Console.WriteLine();
Loop();
}
public void Loop()
{
TankAPI.NewTurn();
var preActionState = TankState.Current;
var action = _brain.TakeDecision(preActionState);
_gameGrid.UpdateMap(preActionState);
//_gameGrid.Print(preActionState);
TankAPI.PerformAction(action);
Console.WriteLine(TankState.Current);
Console.WriteLine("Action: {0}", action);
Console.WriteLine();
TankAPI.CompleteTurn();
}
}