public void SetPlayerSymbol(Position position, PlayerSymbol value) { EnsurePositionIsCorrect(position); if (_busyCells.ContainsKey(position)) { throw new InvalidOperationException($"Position {position} is already busy"); } _busyCells[position] = value; }
public PlayerSymbol? GetPlayerSymbol(Position position) { EnsurePositionIsCorrect(position); PlayerSymbol result; if (_busyCells.TryGetValue(position, out result)) { return result; } return null; }
private void EnsurePositionIsCorrect(Position position) { if (!Size.HasValue) return; Ensure.That(position.X, () => position.X).IsInRange(0, Size.Value.Width - 1); Ensure.That(position.Y, () => position.Y).IsInRange(0, Size.Value.Height - 1); }