示例#1
0
文件: Board.cs 项目: cncplyr/reversal
 public bool CanPlay(Piece piece)
 {
     if (IsOutOfBounds(piece.Position) || IsOccupied(piece.Position))
     {
         return false;
     }
     
     return CapturesOpponentPiecesInAnyDirection(piece);
 }
示例#2
0
文件: Board.cs 项目: cncplyr/reversal
        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();
            }
        }
示例#3
0
文件: Board.cs 项目: cncplyr/reversal
 public PiecesInLine(Board board, Piece piece, Direction direction)
 {
     this.board = board;
     this.piece = piece;
     this.direction = direction;
 }
示例#4
0
文件: Board.cs 项目: cncplyr/reversal
 private bool CapturesOpponentPiecesInAnyDirection(Piece piece)
 {
     return Direction.All()
         .Any(direction => new PiecesInLine(this, piece, direction).CapturesOpponentPieces());
 }
示例#5
0
文件: Board.cs 项目: cncplyr/reversal
 private Piece GetNextPiece(Piece thisPiece)
 {
     return board.GetPiece(direction.AwayFrom(thisPiece.Position));
 }