Пример #1
0
        public Board(Board board)
        {
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (board.IsOccupiedAt(i, j))
                    {
                        Piece piece = board.currentPosition[j, i];
                        switch (piece.TypeStr())
                        {
                        case "pawn":
                            currentPosition[j, i] = new Pawn(piece);
                            break;

                        case "rook":
                            currentPosition[j, i] = new Rook(piece);
                            break;

                        case "knight":
                            currentPosition[j, i] = new Knight(piece);
                            break;

                        case "bishop":
                            currentPosition[j, i] = new Bishop(piece);
                            break;

                        case "queen":
                            currentPosition[j, i] = new Queen(piece);
                            break;

                        case "king":
                            currentPosition[j, i] = new King(piece);
                            break;

                        default:
                            Console.WriteLine("Invalid piece type in Board.Board(board)");
                            break;
                        }
                    }
                }
            }
        }
Пример #2
0
        public Board(string str)
        {
            int i = 0;

            foreach (char c in str)
            {
                switch (c)
                {
                case 'r':
                    currentPosition[i / 8, i % 8] = new Rook(true, i % 8, i / 8);
                    break;

                case 'k':
                    currentPosition[i / 8, i % 8] = new Knight(true, i % 8, i / 8);
                    break;

                case 'b':
                    currentPosition[i / 8, i % 8] = new Bishop(true, i % 8, i / 8);
                    break;

                case 'q':
                    currentPosition[i / 8, i % 8] = new Queen(true, i % 8, i / 8);
                    break;

                case 'x':
                    currentPosition[i / 8, i % 8] = new King(true, i % 8, i / 8);
                    break;

                case 'p':
                    currentPosition[i / 8, i % 8] = new Pawn(true, i % 8, i / 8);
                    break;

                case 'R':
                    currentPosition[i / 8, i % 8] = new Rook(false, i % 8, i / 8);
                    break;

                case 'K':
                    currentPosition[i / 8, i % 8] = new Knight(false, i % 8, i / 8);
                    break;

                case 'B':
                    currentPosition[i / 8, i % 8] = new Bishop(false, i % 8, i / 8);
                    break;

                case 'Q':
                    currentPosition[i / 8, i % 8] = new Queen(false, i % 8, i / 8);
                    break;

                case 'X':
                    currentPosition[i / 8, i % 8] = new King(false, i % 8, i / 8);
                    break;

                case 'P':
                    currentPosition[i / 8, i % 8] = new Pawn(false, i % 8, i / 8);
                    break;

                case '.':
                    break;

                default:
                    Console.WriteLine("Invalid character detected while constructing new board.");
                    break;
                }
                i++;
            }
        }