think i finally solved movement going into enemy territory

This commit is contained in:
2026-07-05 02:51:09 -04:00
parent dbafefd660
commit bfcd48e657
9 changed files with 14 additions and 38 deletions
+3 -18
View File
@@ -29,16 +29,7 @@ public partial class Peg : MapCellOccupant
}
public virtual PegAction SelectAction()
{
PegAction action = null;
for (int i = 0; i < _actions.Count; i++)
{
if (_actions[i].MeetsCriteria(this))
{
action = _actions[i];
break;
}
}
return action;
return _actions.FirstOrDefault(a => a.MeetsCriteria(this), null);
}
public virtual void CounterAct(Commander COMMANDER)
@@ -73,14 +64,8 @@ public partial class Peg : MapCellOccupant
public virtual MapCell Goal()
{
Map map = _pegController._playArea._map;
Dictionary<Vector2I, MapCell> visible = GetVisibleCells();
Dictionary<Vector2I, MapCell> unoccupied = visible.Where(c => !map._astar.IsPointSolid(c.Key)).ToDictionary();
Dictionary<Vector2I, MapCell> enemyTerritory = map._cells.Where(c => _map.GetCellDisposition(c.Value._address) == -(int)_disposition).ToDictionary();
Dictionary<Vector2I, MapCell> closest = enemyTerritory.OrderByDescending(c => c.Value._address.Y).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
// Dictionary<Vector2I, MapCell> closest = unoccupied.OrderByDescending(c => c.Value._address.Y * -(int)_disposition).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
// Dictionary<Vector2I, MapCell> closest = furthest.Where(c => _map.GetCellDisposition(c.Value._address) == -(int)_disposition).ToDictionary();
Dictionary<Vector2I, MapCell> enemyTerritory = _map._cells.Where(c => _map.GetCellDisposition(c.Value._address) == (_disposition == Disposition.FRIENDLY ? -1 : 1)).ToDictionary();
Dictionary<Vector2I, MapCell> closest = enemyTerritory.OrderByDescending(c => c.Value._address.Y).ThenBy(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
return closest.ElementAt(0).Value;
}