public void Capture(IPieceBag pieceBag, IPiece startingPiece, Direction direction) { foreach (var piece in GetCapturablePieces(pieceBag, startingPiece, direction)) { piece.Flip(); } }
public Board( Position maximum, IPieceBag pieceBag, IContiguousOpponentPieces contiguousOpponentPieces) { MaximumPosition = maximum; this.pieceBag = pieceBag; this.contiguousOpponentPieces = contiguousOpponentPieces; }
private IEnumerable<IPiece> GetContiguousOpponentPieces(IPieceBag pieceBag, IPiece startingPiece, Direction direction) { var piece = GetNextPieceFrom(pieceBag, startingPiece, direction); while (piece != null) { if (piece.Side == startingPiece.Side) { yield break; } yield return piece; piece = GetNextPieceFrom(pieceBag, piece, direction); } }
private IEnumerable<IPiece> GetCapturablePieces(IPieceBag pieceBag, IPiece startingPiece, Direction direction) { var opponents = GetContiguousOpponentPieces(pieceBag, startingPiece, direction) .ToArray(); if (!opponents.Any()) { return Enumerable.Empty<IPiece>(); } var nextPiece = GetNextPieceFrom(pieceBag, opponents.Last(), direction); if (nextPiece == null || nextPiece.Side != startingPiece.Side) { return Enumerable.Empty<IPiece>(); } return opponents; }
public Client(IFactory factory) { if (factory == null) throw new ArgumentNullException("factory"); _factory = factory; _actionQueue = factory.CreateActionQueue(); _clients = new List<ClientData>(); _gameClients = new List<ClientData>(); _games = new List<GameData>(); _pieceBag = factory.CreatePieceBag(32); _inventory = factory.CreateInventory(10); Assembly entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly != null) { Version version = entryAssembly.GetName().Version; Version = new Versioning { Major = version.Major, Minor = version.Minor, }; }// else, we suppose SetVersion will be called later, before connecting _state = States.Created; _clientId = Guid.Empty; _lastActionFromServer = DateTime.Now; _timeoutCount = 0; _pieceIndex = 0; _gameTimer = new System.Timers.Timer { Interval = GameTimerIntervalStartValue }; _gameTimer.Elapsed += GameTimerOnElapsed; _cancellationTokenSource = new CancellationTokenSource(); _timeoutTask = Task.Factory.StartNew(TimeoutTask, _cancellationTokenSource.Token); _actionQueue.Start(_cancellationTokenSource); }
private IPiece GetNextPieceFrom(IPieceBag pieceBag, IPiece piece, Direction direction) { return pieceBag.GetPiece(direction.AwayFrom(piece.Position)); }
public bool HasCapturablePieces(IPieceBag pieceBag, IPiece startingPiece, Direction direction) { return GetCapturablePieces(pieceBag, startingPiece, direction).Any(); }