forked from CodinGame/gameofdrones
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.cs
More file actions
117 lines (96 loc) · 3.01 KB
/
Player.cs
File metadata and controls
117 lines (96 loc) · 3.01 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
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
111
112
113
114
115
116
117
using System;
using System.Collections.Generic;
using System.Linq;
namespace Player
{
class Point
{
public int X { get; set; }
public int Y { get; set; }
}
class Drone
{
public Point Position { get; set; }
}
class Zone
{
public const int Radius = 100;
public Point Center { get; set; }
public int OwnerId { get; set; } // -1 if no owner
}
class Team
{
public Team(int droneCount)
{
Drones = new List<Drone>(droneCount);
for (var droneId = 0; droneId < droneCount; droneId++)
Drones.Add(new Drone());
}
public IList<Drone> Drones { get; private set; }
}
class Game
{
List<Zone> zones; // all game zones
List<Team> teams; // all the team of drones. Array index = team's ID
int myTeamId; // index of my team in the array of teams
// read initial games data (one time at the beginning of the game: P I D Z...)
public void Init()
{
var pidz = ReadIntegers();
myTeamId = pidz[1];
zones = ReadZones(pidz[3]).ToList();
teams = ReadTeams(pidz[0], pidz[2]).ToList();
}
IEnumerable<Zone> ReadZones(int zoneCount)
{
for (var areaId = 0; areaId < zoneCount; areaId++)
yield return new Zone {Center = ReadPoint()};
}
IEnumerable<Team> ReadTeams(int teamCount, int dronesPerTeam)
{
for (var teamId = 0; teamId < teamCount; teamId++)
yield return new Team(dronesPerTeam);
}
public void ReadContext()
{
foreach (var zone in zones)
zone.OwnerId = ReadIntegers()[0];
foreach (var team in teams)
foreach (var drone in team.Drones)
drone.Position = ReadPoint();
}
// Compute logic here. This method is called for each game round.
public void Play()
{
var myDrones = teams[myTeamId].Drones;
// here I always ask my drones to reach the bottom right corner... stupid :-)
foreach (var drone in myDrones)
{
Console.WriteLine("3999 1799");
}
}
static int[] ReadIntegers()
{
// ReSharper disable once PossibleNullReferenceException
return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
static Point ReadPoint()
{
var xy = ReadIntegers();
return new Point { X = xy[0], Y = xy[1] };
}
}
static class Program
{
static void Main()
{
var game = new Game();
game.Init();
while (true)
{
game.ReadContext();
game.Play();
}
}
}
}