-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyStrategy.cs
50 lines (42 loc) · 1.99 KB
/
MyStrategy.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
using System.Collections.Generic;
using System.Linq;
using aicup2020.Common;
using Aicup2020.Model;
using Action = Aicup2020.Model.Action;
namespace Aicup2020
{
public class MyStrategy
{
public Action GetAction(PlayerView playerView, DebugInterface debugInterface)
{
PlayerView.Instance = playerView;
PathFinder.Refresh();
BuilderAnalyzer.Refresh();
var actions = new Dictionary<int, EntityAction>();
foreach (var builder in playerView.Entities.Where(i => i.EntityType == EntityType.BuilderUnit && i.PlayerId == playerView.MyId))
{
var resource = playerView.Entities.Where(i => i.EntityType == EntityType.Resource).OrderBy(i => i.Distance(builder)).First();
var path = builder.RouteTo(resource);
if (path != null && path.Count > 1)
{
actions.Add(builder.Id, new EntityAction(new MoveAction(path[1], true, true), null, new AttackAction(resource.Id, new AutoAttack(1, new[] { EntityType.Resource })), null));
}
else
{
actions.Add(builder.Id, new EntityAction(new MoveAction(resource.Position, true, true), null, new AttackAction(resource.Id, new AutoAttack(1, new[] { EntityType.Resource })), null));
}
}
var builderBase = playerView.Entities.First(i => i.EntityType == EntityType.BuilderBase && i.PlayerId == playerView.MyId);
if (EntityHelper.FindBestBuilderSpawnPosition(builderBase, out var spawn))
{
actions.Add(builderBase.Id, new EntityAction(null, new BuildAction(EntityType.BuilderUnit, spawn), null, null));
}
return new Action(actions);
}
public void DebugUpdate(PlayerView playerView, DebugInterface debugInterface)
{
debugInterface.Send(new DebugCommand.Clear());
debugInterface.GetState();
}
}
}