Ejemplo n.º 1
0
        public Board()
        {
            CurrentFEN          = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
            Turn                = 1;
            CastleRights        = "KQkq";
            Halfmove            = 0;
            FullMove            = 1;
            enPassant           = "-";
            checkStatus         = 0;
            checkMateStatus     = 0;
            PositionOfBlackKing = 25;
            PositionOfWhiteKing = 95;
            PieceCntOnBoard     = 32;
            GameOver            = false;
            PGN = new List <string>();
            #region initialize board
            //Initilaze a new Board...handles the initial positions of all the pieces
            //Handle the pawns
            for (int i = 30; i < 120; i++)
            {
                if (i > 30 && i < 39)
                {
                    Pieces[i]   = new Pawn("black", i); //first parameter: black pawn, second parameter: position
                    BitBoard[i] = -1;
                }
                if (i > 80 && i < 89)
                {
                    Pieces[i]   = new Pawn("white", i);
                    BitBoard[i] = 1;
                }
            }
            //Now handle the rest of the pieces individually
            //Rooks
            //black:
            Pieces[21]   = new Rook("black", 21);
            Pieces[28]   = new Rook("black", 28);
            BitBoard[21] = BitBoard[28] = -1;
            //white:
            Pieces[91]   = new Rook("white", 91);
            Pieces[98]   = new Rook("white", 98);
            BitBoard[91] = BitBoard[98] = 1;

            //Knights:
            //black:
            Pieces[22]   = new Knight("black", 22);
            Pieces[27]   = new Knight("black", 27);
            BitBoard[22] = BitBoard[27] = -1;
            //white:
            Pieces[92]   = new Knight("white", 92);
            Pieces[97]   = new Knight("white", 97);
            BitBoard[92] = BitBoard[97] = 1;

            //bishops
            //black
            Pieces[23]   = new Bishop("black", 23);
            Pieces[26]   = new Bishop("black", 26);
            BitBoard[23] = BitBoard[26] = -1;
            //white:
            Pieces[93]   = new Bishop("white", 93);
            Pieces[96]   = new Bishop("white", 96);
            BitBoard[93] = BitBoard[96] = 1;

            //Queens
            //black
            Pieces[24]   = new Queen("black", 24);
            BitBoard[24] = -1;
            //white
            Pieces[94]   = new Queen("white", 94);
            BitBoard[94] = 1;

            //King
            //black
            Pieces[25]   = new King("black", 25);
            BitBoard[25] = -1;
            //white
            Pieces[95]   = new King("white", 95);
            BitBoard[95] = 1;
            #endregion

            #region Initialize 120 mapping to 64
            //the following was created via SKYNET
            MapTo64.Add(21, 0);
            MapTo64.Add(22, 1);
            MapTo64.Add(23, 2);
            MapTo64.Add(24, 3);
            MapTo64.Add(25, 4);
            MapTo64.Add(26, 5);
            MapTo64.Add(27, 6);
            MapTo64.Add(28, 7);
            MapTo64.Add(31, 8);
            MapTo64.Add(32, 9);
            MapTo64.Add(33, 10);
            MapTo64.Add(34, 11);
            MapTo64.Add(35, 12);
            MapTo64.Add(36, 13);
            MapTo64.Add(37, 14);
            MapTo64.Add(38, 15);
            MapTo64.Add(41, 16);
            MapTo64.Add(42, 17);
            MapTo64.Add(43, 18);
            MapTo64.Add(44, 19);
            MapTo64.Add(45, 20);
            MapTo64.Add(46, 21);
            MapTo64.Add(47, 22);
            MapTo64.Add(48, 23);
            MapTo64.Add(51, 24);
            MapTo64.Add(52, 25);
            MapTo64.Add(53, 26);
            MapTo64.Add(54, 27);
            MapTo64.Add(55, 28);
            MapTo64.Add(56, 29);
            MapTo64.Add(57, 30);
            MapTo64.Add(58, 31);
            MapTo64.Add(61, 32);
            MapTo64.Add(62, 33);
            MapTo64.Add(63, 34);
            MapTo64.Add(64, 35);
            MapTo64.Add(65, 36);
            MapTo64.Add(66, 37);
            MapTo64.Add(67, 38);
            MapTo64.Add(68, 39);
            MapTo64.Add(71, 40);
            MapTo64.Add(72, 41);
            MapTo64.Add(73, 42);
            MapTo64.Add(74, 43);
            MapTo64.Add(75, 44);
            MapTo64.Add(76, 45);
            MapTo64.Add(77, 46);
            MapTo64.Add(78, 47);
            MapTo64.Add(81, 48);
            MapTo64.Add(82, 49);
            MapTo64.Add(83, 50);
            MapTo64.Add(84, 51);
            MapTo64.Add(85, 52);
            MapTo64.Add(86, 53);
            MapTo64.Add(87, 54);
            MapTo64.Add(88, 55);
            MapTo64.Add(91, 56);
            MapTo64.Add(92, 57);
            MapTo64.Add(93, 58);
            MapTo64.Add(94, 59);
            MapTo64.Add(95, 60);
            MapTo64.Add(96, 61);
            MapTo64.Add(97, 62);
            MapTo64.Add(98, 63);

            #endregion

            #region Initialize 64 mapping to 120

            MapTo120.Add(0, 21);
            MapTo120.Add(1, 22);
            MapTo120.Add(2, 23);
            MapTo120.Add(3, 24);
            MapTo120.Add(4, 25);
            MapTo120.Add(5, 26);
            MapTo120.Add(6, 27);
            MapTo120.Add(7, 28);
            MapTo120.Add(8, 31);
            MapTo120.Add(9, 32);
            MapTo120.Add(10, 33);
            MapTo120.Add(11, 34);
            MapTo120.Add(12, 35);
            MapTo120.Add(13, 36);
            MapTo120.Add(14, 37);
            MapTo120.Add(15, 38);
            MapTo120.Add(16, 41);
            MapTo120.Add(17, 42);
            MapTo120.Add(18, 43);
            MapTo120.Add(19, 44);
            MapTo120.Add(20, 45);
            MapTo120.Add(21, 46);
            MapTo120.Add(22, 47);
            MapTo120.Add(23, 48);
            MapTo120.Add(24, 51);
            MapTo120.Add(25, 52);
            MapTo120.Add(26, 53);
            MapTo120.Add(27, 54);
            MapTo120.Add(28, 55);
            MapTo120.Add(29, 56);
            MapTo120.Add(30, 57);
            MapTo120.Add(31, 58);
            MapTo120.Add(32, 61);
            MapTo120.Add(33, 62);
            MapTo120.Add(34, 63);
            MapTo120.Add(35, 64);
            MapTo120.Add(36, 65);
            MapTo120.Add(37, 66);
            MapTo120.Add(38, 67);
            MapTo120.Add(39, 68);
            MapTo120.Add(40, 71);
            MapTo120.Add(41, 72);
            MapTo120.Add(42, 73);
            MapTo120.Add(43, 74);
            MapTo120.Add(44, 75);
            MapTo120.Add(45, 76);
            MapTo120.Add(46, 77);
            MapTo120.Add(47, 78);
            MapTo120.Add(48, 81);
            MapTo120.Add(49, 82);
            MapTo120.Add(50, 83);
            MapTo120.Add(51, 84);
            MapTo120.Add(52, 85);
            MapTo120.Add(53, 86);
            MapTo120.Add(54, 87);
            MapTo120.Add(55, 88);
            MapTo120.Add(56, 91);
            MapTo120.Add(57, 92);
            MapTo120.Add(58, 93);
            MapTo120.Add(59, 94);
            MapTo120.Add(60, 95);
            MapTo120.Add(61, 96);
            MapTo120.Add(62, 97);
            MapTo120.Add(63, 98);

            #endregion
        }
Ejemplo n.º 2
0
        public void SetGameFromFEN(string FEN)
        {
            CurrentFEN = FEN;
            FENHistory.Add(CurrentFEN);
            string[] ValidCharacters = { "p", "r", "n", "b", "q", "k" };
            int[]    EmptySquares    = { 1, 2, 3, 4, 5, 6, 7, 8 };
            int      Square          = 21;

            if (FEN.Length > 0)
            {
                Console.WriteLine(FEN.Substring(0, FEN.IndexOf(" ")).Length.ToString());
                for (int i = 0; i < FEN.Substring(0, FEN.IndexOf(" ")).Length; i++)
                {
                    if (ValidCharacters.Contains(FEN[i].ToString().ToLower()))
                    {
                        switch (FEN[i].ToString())
                        {
                        case "p":
                            Pieces[Square]   = new Pawn("black", Square);
                            BitBoard[Square] = -1;
                            Square           = Square + 1;
                            break;

                        case "P":
                            Pieces[Square]   = new Pawn("white", Square);
                            BitBoard[Square] = 1;
                            Square           = Square + 1;
                            break;

                        case "r":
                            Pieces[Square]   = new Rook("black", Square);
                            BitBoard[Square] = -1;
                            Square           = Square + 1;
                            break;

                        case "R":
                            Pieces[Square]   = new Rook("white", Square);
                            BitBoard[Square] = 1;
                            Square           = Square + 1;
                            break;

                        case "n":
                            Pieces[Square]   = new Knight("black", Square);
                            BitBoard[Square] = -1;
                            Square           = Square + 1;
                            break;

                        case "N":
                            Pieces[Square]   = new Knight("white", Square);
                            BitBoard[Square] = 1;
                            Square           = Square + 1;
                            break;

                        case "b":
                            Pieces[Square]   = new Bishop("black", Square);
                            BitBoard[Square] = -1;
                            Square           = Square + 1;
                            break;

                        case "B":
                            Pieces[Square]   = new Bishop("white", Square);
                            BitBoard[Square] = 1;
                            Square           = Square + 1;
                            break;

                        case "q":
                            Pieces[Square]   = new Queen("black", Square);
                            BitBoard[Square] = -1;
                            Square           = Square + 1;
                            break;

                        case "Q":
                            Pieces[Square]   = new Queen("white", Square);
                            BitBoard[Square] = 1;
                            Square           = Square + 1;
                            break;

                        case "k":
                            Pieces[Square]   = new King("black", Square);
                            BitBoard[Square] = -1;
                            Square           = Square + 1;
                            break;

                        case "K":
                            Pieces[Square]   = new King("white", Square);
                            BitBoard[Square] = 1;
                            Square           = Square + 1;
                            break;
                        }
                    }
                    //bool isNumber = Int32.TryParse(FEN[i].ToString(), out isNumber);
                    bool isNumber = Char.IsNumber(FEN[i]);
                    if (isNumber == true)
                    {
                        int spaces = (int)Char.GetNumericValue(FEN[i]);
                        for (int s = 0; s < spaces; s++)
                        {
                            Pieces[Square + s]   = null;
                            BitBoard[Square + s] = 0;
                        }
                        Square = Square + spaces;
                        //i = i + spaces;
                    }
                    //Is it end of rank?
                    if (FEN[i].ToString() == "/")
                    {
                        Square = Square + 2;
                    }
                }
            }
        }