mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-26 04:41:52 -08:00
32 lines
926 B
C#
32 lines
926 B
C#
namespace Salvo.Targetting;
|
|
|
|
internal abstract class ShotSelector
|
|
{
|
|
private readonly Fleet _source;
|
|
private readonly Dictionary<Position, int> _previousShots = new();
|
|
|
|
internal ShotSelector(Fleet source)
|
|
{
|
|
_source = source;
|
|
}
|
|
|
|
internal int NumberOfShots => _source.Ships.Sum(s => s.Shots);
|
|
internal bool CanTargetAllRemainingSquares => NumberOfShots >= 100 - _previousShots.Count;
|
|
|
|
internal bool WasSelectedPreviously(Position position) => _previousShots.ContainsKey(position);
|
|
|
|
internal bool WasSelectedPreviously(Position position, out int turn)
|
|
=> _previousShots.TryGetValue(position, out turn);
|
|
|
|
internal IEnumerable<Position> GetShots(int turnNumber)
|
|
{
|
|
foreach (var shot in GetShots())
|
|
{
|
|
_previousShots.Add(shot, turnNumber);
|
|
yield return shot;
|
|
}
|
|
}
|
|
|
|
protected abstract IEnumerable<Position> GetShots();
|
|
}
|