Ejemplo n.º 1
0
 public void Capture(IPieceBag pieceBag, IPiece startingPiece, Direction direction)
 {
     foreach (var piece in GetCapturablePieces(pieceBag, startingPiece, direction))
     {
         piece.Flip();
     }
 }
Ejemplo n.º 2
0
 public Board(
     Position maximum, 
     IPieceBag pieceBag,
     IContiguousOpponentPieces contiguousOpponentPieces)
 {
     MaximumPosition = maximum;
     this.pieceBag = pieceBag;
     this.contiguousOpponentPieces = contiguousOpponentPieces;
 }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 private IPiece GetNextPieceFrom(IPieceBag pieceBag, IPiece piece, Direction direction)
 {
     return pieceBag.GetPiece(direction.AwayFrom(piece.Position));
 }
Ejemplo n.º 7
0
 public bool HasCapturablePieces(IPieceBag pieceBag, IPiece startingPiece, Direction direction)
 {
     return GetCapturablePieces(pieceBag, startingPiece, direction).Any();
 }