Example #1
0
        private void InitializePieceSet()
        {
            this.ClearPieceSet();

            PieceFactory pieceFactory = new PieceFactory();
            /*PEDONI*/
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.White), 8);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.White), 9);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.White), 10);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.White), 11);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.White), 12);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.White), 13);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.White), 14);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.White), 15);
            //
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.Black), 48);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.Black), 49);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.Black), 50);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.Black), 51);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.Black), 52);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.Black), 53);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.Black), 54);
            this.AddPiece(pieceFactory.Create(PieceType.Pawn, PieceColor.Black), 55);

            /*TORRI*/
            this.AddPiece(pieceFactory.Create(PieceType.Rook, PieceColor.White), 0);
            this.AddPiece(pieceFactory.Create(PieceType.Rook, PieceColor.White), 7);
            //
            this.AddPiece(pieceFactory.Create(PieceType.Rook, PieceColor.Black), 56);
            this.AddPiece(pieceFactory.Create(PieceType.Rook, PieceColor.Black), 63);

            /*CAVALLI*/
            this.AddPiece(pieceFactory.Create(PieceType.Knight, PieceColor.White), 1);
            this.AddPiece(pieceFactory.Create(PieceType.Knight, PieceColor.White), 6);
            //
            this.AddPiece(pieceFactory.Create(PieceType.Knight, PieceColor.Black), 57);
            this.AddPiece(pieceFactory.Create(PieceType.Knight, PieceColor.Black), 62);

            /*ALFIERI*/
            this.AddPiece(pieceFactory.Create(PieceType.Bishop, PieceColor.White), 2);
            this.AddPiece(pieceFactory.Create(PieceType.Bishop, PieceColor.White), 5);
            //
            this.AddPiece(pieceFactory.Create(PieceType.Bishop, PieceColor.Black), 58);
            this.AddPiece(pieceFactory.Create(PieceType.Bishop, PieceColor.Black), 61);

            /*RE*/
            this.AddPiece(pieceFactory.Create(PieceType.King, PieceColor.White), 4);
            //
            this.AddPiece(pieceFactory.Create(PieceType.King, PieceColor.Black), 60);

            /*REGINE*/
            this.AddPiece(pieceFactory.Create(PieceType.Queen, PieceColor.White), 3);
            //
            this.AddPiece(pieceFactory.Create(PieceType.Queen, PieceColor.Black), 59);
        }
Example #2
0
        private void ParsePiecePlacement(string field)
        {
            Board.ClearPieceSet(ref this.PiecePlacement);

            string[] ranks = field.Split('/');
            PieceFactory factory = new PieceFactory();

            for (int i = 0; i < ranks.Length; i++)
            {
                int empty = 0;
                for (int l = 0; l < ranks[i].Length; l++)
                {
                    #region pieceCreation

                    switch (ranks[i][l])
                    {
                        case 'P':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Pawn, PieceColor.White);
                            break;
                        case 'p':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Pawn, PieceColor.Black);
                            break;
                        case 'N':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Knight, PieceColor.White);
                            break;
                        case 'n':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Knight, PieceColor.Black);
                            break;
                        case 'B':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Bishop, PieceColor.White);
                            break;
                        case 'b':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Bishop, PieceColor.Black);
                            break;
                        case 'R':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Rook, PieceColor.White);
                            break;
                        case 'r':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Rook, PieceColor.Black);
                            break;
                        case 'Q':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Queen, PieceColor.White);
                            break;
                        case 'q':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.Queen, PieceColor.Black);
                            break;
                        case 'K':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.King, PieceColor.White);
                            break;
                        case 'k':
                            this.PiecePlacement[Square.GetSquareIndex(l + empty, 7 - i)] = factory.Create(PieceType.King, PieceColor.Black);
                            break;
                        default:
                            empty += (int)char.GetNumericValue(ranks[i][l]) - 1;
                            break;
                    }

                    #endregion
                }
            }
        }