예제 #1
0
        public ChessBoard(ChessPiece[,] state)
        {
            if (state == null)
                throw new ArgumentNullException("state");

            _boardState = state;
        }
예제 #2
0
 private static void PrintState(ChessPiece[,] board, HashSet<string> potentialMoves, int rank, char file)
 {
     string notation = file.ToString() + rank;
     var t = NotationHelper.Translate(notation);
     ChessPiece p = board[t.Item1, t.Item2];
     bool pm = potentialMoves.Contains(notation);
     Console.Write(p == null ? (pm ? "|- " : "|  ") : p.ToString() + (pm ? "-" : " "));
 }
예제 #3
0
 public void Set(string notation, ChessPiece value)
 {
     var rowColTuple = NotationHelper.Translate(notation);
     _boardState[rowColTuple.Item1, rowColTuple.Item2] = value;
 }
예제 #4
0
        public ChessPiece[,] CreateStateCopy()
        {
            ChessPiece[,] copy = new ChessPiece[8, 8];

            for (int row = 0; row < 8; row++)
            {
                for (int col = 0; col < 8; col++)
                {
                    ChessPiece o = _boardState[row, col];
                    copy[row, col] = o == null ? null : o.GetCopy();
                }
            }

            return copy;
        }
예제 #5
0
        private static ProjectResult _ProjectMovesOnToBoard(ChessPiece[,] boardState, string[] moves, string[] taken, string[] swaps)
        {
            if (moves == null)
                throw new ArgumentNullException("moves");

            if (moves.Length < 1)
                throw new InvalidOperationException("moves is empty");

            List<ChessPiece> takenPieces = null;

            if (taken != null)
            {
                takenPieces = new List<ChessPiece>();

                foreach (var takenNotation in taken)
                {
                    var takenTuple = NotationHelper.Translate(takenNotation);
                    var takenPiece = boardState[takenTuple.Item1, takenTuple.Item2];
                    boardState[takenTuple.Item1, takenTuple.Item2] = null;
                    takenPieces.Add(takenPiece);
                }
            }

            foreach (var moveNotation in moves)
            {
                var breakdown = NotationHelper.Breakdown(moveNotation);
                var sourceTuple = NotationHelper.Translate(breakdown.Item1);
                var sourcePiece = boardState[sourceTuple.Item1, sourceTuple.Item2];
                sourcePiece.Moves++;

                boardState[sourceTuple.Item1, sourceTuple.Item2] = null;

                var destinationTuple = NotationHelper.Translate(breakdown.Item2);
                boardState[destinationTuple.Item1, destinationTuple.Item2] = sourcePiece;
            }

            if (swaps != null)
            {
                foreach (var swap in swaps)
                {
                    var swapTuple = NotationHelper.Translate(swap);
                    var swappedPiece = boardState[swapTuple.Item1, swapTuple.Item2];

                    boardState[swapTuple.Item1, swapTuple.Item2] = new ChessPiece() { Player = swappedPiece.Player, Type = PieceTypeEnum.Queen };
                }
            }

            return new ProjectResult
            {
                TakenPieces = takenPieces,
            };
        }
예제 #6
0
 public PieceCapturedEventArgs(ChessPiece piece)
 {
     this.PieceCaptured = piece;
 }
예제 #7
0
 public PieceInsertedEventArgs(ChessPiece piece, ChessBoardCell destinationCell)
 {
     this.PieceInserted   = piece;
     this.DestinationCell = destinationCell;
 }
예제 #8
0
        public void PrintBoard(ChessPiece[,] board, PlayerTypeEnum player, HashSet<string> potentialMoves)
        {
            potentialMoves = potentialMoves ?? new HashSet<string>();
            if (player == PlayerTypeEnum.White)
            {
                for (int col = 0; col < 8; col++)
                {
                    string file = NotationHelper.TranslateToFile(col);
                    Console.Write("  {0}", file);
                }

                Console.WriteLine();

                for (int rank = 8; rank > 0; rank--)
                {
                    Console.Write(rank);

                    for (char file = 'a'; file <= 'h'; file++)
                    {
                        PrintState(board, potentialMoves, rank, file);
                    }

                    Console.WriteLine();
                }

                for (int col = 0; col < 8; col++)
                {
                    string file = NotationHelper.TranslateToFile(col);
                    Console.Write("  {0}", file);
                }
            }
            else if (player == PlayerTypeEnum.Black)
            {
                for (int col = 7; col >= 0; col--)
                {
                    string file = NotationHelper.TranslateToFile(col);
                    Console.Write("  {0}", file);
                }

                Console.WriteLine();

                for (int rank = 1; rank <= 8; rank++)
                {
                    Console.Write(rank);

                    for (char file = 'h'; file >= 'a'; file--)
                    {
                        PrintState(board, potentialMoves, rank, file);
                    }

                    Console.WriteLine();
                }

                for (int col = 7; col >= 0; col--)
                {
                    string file = NotationHelper.TranslateToFile(col);
                    Console.Write("  {0}", file);
                }
            }

            Console.WriteLine();
        }
예제 #9
0
 public void PrintBoard(ChessPiece[,] board, PlayerTypeEnum player)
 {
     PrintBoard(board, player, null);
 }
예제 #10
0
 /// <summary>
 /// Initializes the <see cref="BoardState"/> class.
 /// </summary>
 public BoardState(
     ChessPiece piece,
     ChessPiece pawnProm,
     (int, int) start,