2021-04-27 16:44:44 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using MessagePack;
|
|
|
|
|
using Random = Unity.Mathematics.Random;
|
|
|
|
|
|
|
|
|
|
public abstract class ZoneSelector
|
|
|
|
|
{
|
2021-05-14 03:03:28 +01:00
|
|
|
public abstract GalaxyZone SelectZone(List<GalaxyZone> candidates);
|
2021-04-27 16:44:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract class OrderedZoneSelector : ZoneSelector
|
|
|
|
|
{
|
|
|
|
|
public bool Flip = false;
|
|
|
|
|
|
2021-05-14 03:03:28 +01:00
|
|
|
protected abstract Func<GalaxyZone, IComparable> Comparison { get; }
|
2021-04-27 16:44:44 +01:00
|
|
|
|
2021-05-14 03:03:28 +01:00
|
|
|
public override GalaxyZone SelectZone(List<GalaxyZone> candidates)
|
2021-04-27 16:44:44 +01:00
|
|
|
{
|
|
|
|
|
var sorted = candidates.OrderBy(Comparison);
|
|
|
|
|
return Flip ? sorted.Last() : sorted.First();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class DistanceSelector : OrderedZoneSelector
|
|
|
|
|
{
|
2021-05-14 03:03:28 +01:00
|
|
|
private GalaxyZone Target { get; }
|
2021-04-27 16:44:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public DistanceSelector(string[] args, IZoneResolver zoneResolver)
|
|
|
|
|
{
|
|
|
|
|
Target = zoneResolver.ResolveZone(args[0].Trim());
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-14 03:03:28 +01:00
|
|
|
protected override Func<GalaxyZone, IComparable> Comparison => zone => Target?.Distance[zone] ?? 0;
|
2021-04-27 16:44:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RandomSelector : ZoneSelector
|
|
|
|
|
{
|
|
|
|
|
private Random Random { get; }
|
|
|
|
|
|
|
|
|
|
public RandomSelector(ref Random random)
|
|
|
|
|
{
|
|
|
|
|
Random = random;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-14 03:03:28 +01:00
|
|
|
public override GalaxyZone SelectZone(List<GalaxyZone> candidates)
|
2021-04-27 16:44:44 +01:00
|
|
|
{
|
|
|
|
|
return candidates[Random.NextInt(candidates.Count)];
|
|
|
|
|
}
|
|
|
|
|
}
|