Esempio n. 1
0
        public ChessBoard(ChessPiece[,] state)
        {
            if (state == null)
                throw new ArgumentNullException("state");

            _boardState = state;
        }
Esempio n. 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 ? "-" : " "));
 }
Esempio n. 3
0
 public void Set(string notation, ChessPiece value)
 {
     var rowColTuple = NotationHelper.Translate(notation);
     _boardState[rowColTuple.Item1, rowColTuple.Item2] = value;
 }
Esempio n. 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;
        }
Esempio n. 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,
            };
        }
Esempio n. 6
0
 public PieceCapturedEventArgs(ChessPiece piece)
 {
     this.PieceCaptured = piece;
 }
Esempio n. 7
0
 public PieceInsertedEventArgs(ChessPiece piece, ChessBoardCell destinationCell)
 {
     this.PieceInserted   = piece;
     this.DestinationCell = destinationCell;
 }
Esempio n. 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();
        }
Esempio n. 9
0
 public void PrintBoard(ChessPiece[,] board, PlayerTypeEnum player)
 {
     PrintBoard(board, player, null);
 }
Esempio n. 10
0
 /// <summary>
 /// Initializes the <see cref="BoardState"/> class.
 /// </summary>
 public BoardState(
     ChessPiece piece,
     ChessPiece pawnProm,
     (int, int) start,