Exemplo n.º 1
0
 public bool CanPlay(Piece piece)
 {
     if (IsOutOfBounds(piece.Position) || IsOccupied(piece.Position))
     {
         return false;
     }
     
     return CapturesOpponentPiecesInAnyDirection(piece);
 }
Exemplo n.º 2
0
        public void Play(Piece piece)
        {
            if (!CanPlay(piece))
            {
                throw new InvalidOperationException($"Invalid move for {piece}");
            }

            pieces.Add(piece);
            foreach (var direction in Direction.All())
            {
                var line = new PiecesInLine(this, piece, direction);
                line.FlipOpponents();
            }
        }
Exemplo n.º 3
0
 public PiecesInLine(Board board, Piece piece, Direction direction)
 {
     this.board = board;
     this.piece = piece;
     this.direction = direction;
 }
Exemplo n.º 4
0
 private bool CapturesOpponentPiecesInAnyDirection(Piece piece)
 {
     return Direction.All()
         .Any(direction => new PiecesInLine(this, piece, direction).CapturesOpponentPieces());
 }
Exemplo n.º 5
0
 private Piece GetNextPiece(Piece thisPiece)
 {
     return board.GetPiece(direction.AwayFrom(thisPiece.Position));
 }