Ejemplo n.º 1
0
        public static int GetPvLine(int depth, ref boardStruct brett)
        {
            Debug.Assert(depth < defs.MAXTIEFE && depth >= 1);

            int move  = ProbePvMove(ref brett);
            int count = 0;

            while (move != defs.NOMOVE && count < depth)
            {
                Debug.Assert(count < defs.MAXTIEFE);

                if (movegen.MoveExists(ref brett, move))
                {
                    makemove.MakeMove(move, ref brett);
                    brett.PvArray[count++] = move;
                }
                else
                {
                    break;
                }
                move = ProbePvMove(ref brett);
            }

            while (brett.ply > 0)
            {
                makemove.TakeMove(ref brett);
            }

            return(count);
        }
Ejemplo n.º 2
0
        static bool DrawMaterial(ref boardStruct brett)
        {
            Debug.Assert(board.CheckBoard(ref brett));

            if (brett.pceNum[(int)defs.Figuren.wB] != 0 || brett.pceNum[(int)defs.Figuren.sB] != 0)
            {
                return(false);
            }
            if (brett.pceNum[(int)defs.Figuren.wD] != 0 || brett.pceNum[(int)defs.Figuren.sD] != 0 || brett.pceNum[(int)defs.Figuren.wT] != 0 || brett.pceNum[(int)defs.Figuren.sT] != 0)
            {
                return(false);
            }
            if (brett.pceNum[(int)defs.Figuren.wL] > 1 || brett.pceNum[(int)defs.Figuren.wL] > 1)
            {
                return(false);
            }
            if (brett.pceNum[(int)defs.Figuren.wP] > 1 || brett.pceNum[(int)defs.Figuren.sP] > 1)
            {
                return(false);
            }
            if (brett.pceNum[(int)defs.Figuren.wP] != 0 && brett.pceNum[(int)defs.Figuren.wL] != 0)
            {
                return(false);
            }
            if (brett.pceNum[(int)defs.Figuren.sP] != 0 && brett.pceNum[(int)defs.Figuren.sL] != 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static void PerftTest(int depth, ref movelist list, ref boardStruct brett)
        {
            Debug.Assert(board.CheckBoard(ref brett));

            Console.Write("\nStarting Test To Depth:" + depth + "\n");
            leafNodes = 0;
            Stopwatch timer = new Stopwatch();

            timer.Start();
            movegen.GenerateAllMoves(ref list, ref brett);

            int move;
            int MoveNum = 0;

            for (MoveNum = 0; MoveNum < list.anzahlZüge; ++MoveNum)
            {
                move = list.zugliste[MoveNum].Zug;
                if (!makemove.MakeMove(move, ref brett))
                {
                    continue;
                }
                long newnodes = leafNodes;
                Perft(depth - 1, ref brett);
                makemove.TakeMove(ref brett);
                long oldnodes = leafNodes - newnodes;
                Console.Write(String.Format("move {0} : {1} : {2}\n", MoveNum + 1, io.PrMove(move), oldnodes));
            }

            timer.Stop();
            Console.Write(String.Format("\nTest Complete : {0} nodes visited in {1}ms\n", leafNodes, timer.ElapsedMilliseconds));
        }
Ejemplo n.º 4
0
        static int ConvertPolyMoveToInternalMove(ushort polyMove, ref boardStruct brett)
        {
            int ff = (polyMove >> 6) & 7;
            int fr = (polyMove >> 9) & 7;
            int tf = (polyMove >> 0) & 7;
            int tr = (polyMove >> 3) & 7;
            int pp = (polyMove >> 12) & 7;

            string ret;

            if (pp == 0)
            {
                ret = data.FileChar[ff].ToString() + data.RankChar[fr].ToString() + data.FileChar[tf].ToString() + data.RankChar[tr].ToString();
            }
            else
            {
                char promChar = 'q';
                switch (pp)
                {
                case 1: promChar = 'n'; break;

                case 2: promChar = 'b'; break;

                case 3: promChar = 'r'; break;
                }
                ret = data.FileChar[ff].ToString() + data.RankChar[fr].ToString() + data.FileChar[tf].ToString() + data.RankChar[tr].ToString() + promChar.ToString();
            }
            return(io.ParseMove(ret, ref brett));
        }
Ejemplo n.º 5
0
        public static bool HasPawnForCapture(ref boardStruct brett)
        {
            int sqWithPawn = 0;
            int targetPce  = (brett.seite == (int)defs.Farben.WEISS) ? (int)defs.Figuren.wB : (int)defs.Figuren.sB;

            if (brett.enPas != (int)defs.Felder.NO_SQ)
            {
                if (brett.seite == (int)defs.Farben.WEISS)
                {
                    sqWithPawn = brett.enPas - 10;
                }
                else
                {
                    sqWithPawn = brett.enPas + 10;
                }
                if (brett.figuren[sqWithPawn + 1] == targetPce)
                {
                    return(true);
                }
                else if (brett.figuren[sqWithPawn - 1] == targetPce)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Process.GetCurrentProcess().ProcessorAffinity = new IntPtr(2);
            Process.GetCurrentProcess().PriorityClass     = ProcessPriorityClass.High;
            Thread.CurrentThread.Priority = ThreadPriority.Highest;


            boardStruct brett = new boardStruct();
            movelist    list  = new movelist();
            suchInfo    info  = new suchInfo();

            init.AllInit(ref brett);

            bool loop = true;

            while (loop)
            {
                loop = false;
                Console.Write("\nGeben sie \"uci\" für den uci modus und \"vwa\" für den Konsolen modus ein: ");
                string input = Console.ReadLine();
                if (input.Length > 2 && string.Equals(input.Substring(0, 3), "uci", StringComparison.CurrentCultureIgnoreCase))
                {
                    uci.Uci_Loop(ref brett, ref info);
                }
                if (input.Length > 2 && string.Equals(input.Substring(0, 3), "vwa", StringComparison.CurrentCultureIgnoreCase))
                {
                    Console.Clear();
                    xboard.Console_Loop(ref brett, ref info);
                }
                else
                {
                    loop = true;
                }
            }
        }
Ejemplo n.º 7
0
Archivo: io.cs Proyecto: alang321/VWA
        public static string PrintBoard(ref boardStruct brett)
        {
            string ret = "";

            int sq, file, rank, piece;

            ret += "\nSpiel Brett:\n\n";

            for (rank = (int)defs.Zeilen.ZEILE_8; rank >= (int)defs.Zeilen.ZEILE_1; rank--)
            {
                ret += rank + 1 + "  ";
                for (file = (int)defs.Spalten.SPALTE_A; file <= (int)defs.Spalten.SPALTE_H; file++)
                {
                    sq    = makros.SZ2SQ(file, rank);
                    piece = brett.figuren[sq];
                    ret  += data.PceChar[piece].ToString().PadLeft(3);
                }
                ret += "\n";
            }

            ret += "\n     ";
            for (file = (int)defs.Spalten.SPALTE_A; file <= (int)defs.Spalten.SPALTE_H; file++)
            {
                ret += io.Number2String(file, true) + "  ";
            }
            ret += "\n\n";
            ret += "Seite: " + data.SideChar[brett.seite] + "\n";
            ret += "enPas: "******"Å101" ? PrSq(brett.enPas) : "-") + "\n";
            ret += "Rochade: " + ((brett.rochadePerm & (int)defs.Rochade.WKRC) == (int)defs.Rochade.WKRC ? "K" : "-") + ((brett.rochadePerm & (int)defs.Rochade.WDRC) == (int)defs.Rochade.WDRC ? "D" : "-") + ((brett.rochadePerm & (int)defs.Rochade.SKRC) == (int)defs.Rochade.SKRC ? "k" : "-") + ((brett.rochadePerm & (int)defs.Rochade.SDRC) == (int)defs.Rochade.SDRC ? "d" : "-") + "\n";
            ret += String.Format("PosKey: {0:X}", brett.posKey);

            return(ret);
        }
Ejemplo n.º 8
0
        public static void MakeNullMove(ref boardStruct brett)
        {
            Debug.Assert(board.CheckBoard(ref brett));
            Debug.Assert(!attack.SqAttacked(brett.KönigSq[brett.seite], brett.seite ^ 1, ref brett));

            brett.ply++;
            brett.history[brett.hisPly].PosKey = brett.posKey;

            if (brett.enPas != (int)defs.Felder.NO_SQ)
            {
                makros.HashInEnPassant(ref brett);
            }

            brett.history[brett.hisPly].Zug         = defs.NOMOVE;
            brett.history[brett.hisPly].FiftyMove   = brett.fiftyMove;
            brett.history[brett.hisPly].EnPas       = brett.enPas;
            brett.history[brett.hisPly].RochadePerm = brett.rochadePerm;
            brett.enPas = (int)defs.Felder.NO_SQ;

            brett.seite ^= 1;
            brett.hisPly++;
            makros.HashInSide(ref brett);

            Debug.Assert(board.CheckBoard(ref brett));
            Debug.Assert(brett.hisPly >= 0 && brett.hisPly < defs.MAXSPIELZÜGE);
            Debug.Assert(brett.ply >= 0 && brett.ply < defs.MAXTIEFE);

            return;
        }
Ejemplo n.º 9
0
        public static void MovePiece(int from, int to, ref boardStruct brett)
        {
            Debug.Assert(validate.SqOnBoard(from));
            Debug.Assert(validate.SqOnBoard(to));

            int index = 0;
            int pce   = brett.figuren[from];
            int col   = data.PieceCol[pce];

            Debug.Assert(validate.SideValid(col));
            Debug.Assert(validate.PieceValid(pce));

            makros.HashInPiece(pce, from, ref brett);
            brett.figuren[from] = (int)defs.Figuren.LEER;

            makros.HashInPiece(pce, to, ref brett);
            brett.figuren[to] = pce;

            if (!data.PieceBig[pce])
            {
                makros.ClearBit(ref brett.bauern[col], defs.Sq120ToSq64[from]);
                makros.ClearBit(ref brett.bauern[(int)defs.Farben.BEIDE], defs.Sq120ToSq64[from]);
                makros.SetBit(ref brett.bauern[col], defs.Sq120ToSq64[to]);
                makros.SetBit(ref brett.bauern[(int)defs.Farben.BEIDE], defs.Sq120ToSq64[to]);
            }

            for (index = 0; index < brett.pceNum[pce]; ++index)
            {
                if (brett.fListe[pce, index] == from)
                {
                    brett.fListe[pce, index] = to;
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        static void ClearForSearch(ref boardStruct brett, ref suchInfo info)
        {
            int index  = 0;
            int index2 = 0;

            for (index = 0; index < 13; ++index)
            {
                for (index2 = 0; index2 < defs.BRD_SQ_NUM; ++index2)
                {
                    brett.searchHistory[index, index2] = 0;
                }
            }

            for (index = 0; index < 2; ++index)
            {
                for (index2 = 0; index2 < defs.MAXTIEFE; ++index2)
                {
                    brett.searchKillers[index, index2] = 0;
                }
            }

            brett.PvTable.overWrite = 0;
            brett.PvTable.hit       = 0;
            brett.PvTable.cut       = 0;
            brett.ply = 0;

            PvTable.ClearPvTable(ref brett.PvTable);

            info.stopped = false;
            info.nodes   = 0;
            info.fh      = 0;
            info.fhf     = 0;
        }
Ejemplo n.º 11
0
        public static void TakeNullMove(ref boardStruct brett)
        {
            Debug.Assert(board.CheckBoard(ref brett));

            brett.hisPly--;
            brett.ply--;

            if (brett.enPas != (int)defs.Felder.NO_SQ)
            {
                makros.HashInEnPassant(ref brett);
            }

            brett.rochadePerm = brett.history[brett.hisPly].RochadePerm;
            brett.fiftyMove   = brett.history[brett.hisPly].FiftyMove;
            brett.enPas       = brett.history[brett.hisPly].EnPas;

            if (brett.enPas != (int)defs.Felder.NO_SQ)
            {
                makros.HashInEnPassant(ref brett);
            }
            brett.seite ^= 1;
            makros.HashInSide(ref brett);

            Debug.Assert(board.CheckBoard(ref brett));
            Debug.Assert(brett.hisPly >= 0 && brett.hisPly < defs.MAXSPIELZÜGE);
            Debug.Assert(brett.ply >= 0 && brett.ply < defs.MAXTIEFE);
        }
Ejemplo n.º 12
0
        public static void AddPiece(int sq, int pce, ref boardStruct brett)
        {
            Debug.Assert(validate.PieceValid(pce));
            Debug.Assert(validate.SqOnBoard(sq));

            int col = data.PieceCol[pce];

            Debug.Assert(validate.SideValid(col));

            makros.HashInPiece(pce, sq, ref brett);

            brett.figuren[sq] = pce;

            if (data.PieceBig[pce])
            {
                brett.bigPce[col]++;

                if (data.PieceMaj[pce])
                {
                    brett.majPce[col]++;
                }
                else
                {
                    brett.minPce[col]++;
                }
            }
            else
            {
                makros.SetBit(ref brett.bauern[col], defs.Sq120ToSq64[sq]);
                makros.SetBit(ref brett.bauern[(int)defs.Farben.BEIDE], defs.Sq120ToSq64[sq]);
            }

            brett.material[col] += data.PieceVal[pce];
            brett.fListe[pce, brett.pceNum[pce]++] = sq;
        }
Ejemplo n.º 13
0
        public static void Perft(int depth, ref boardStruct brett)
        {
            Debug.Assert(board.CheckBoard(ref brett));

            if (depth == 0)
            {
                leafNodes++;
                return;
            }

            movelist list = new movelist();

            movegen.GenerateAllMoves(ref list, ref brett);

            int MoveNum = 0;

            for (MoveNum = 0; MoveNum < list.anzahlZüge; ++MoveNum)
            {
                if (!makemove.MakeMove(list.zugliste[MoveNum].Zug, ref brett))
                {
                    continue;
                }
                Perft(depth - 1, ref brett);
                makemove.TakeMove(ref brett);
            }

            return;
        }
Ejemplo n.º 14
0
        public static ulong GeneratePosKey(ref boardStruct brett)
        {
            int   sq    = 0;
            ulong Key   = 0;
            int   piece = (int)defs.Figuren.LEER;

            // pieces
            for (sq = 0; sq < defs.BRD_SQ_NUM; ++sq)
            {
                piece = brett.figuren[sq];
                if (piece != (int)defs.Felder.NO_SQ && piece != (int)defs.Figuren.LEER && piece != (int)defs.Felder.OFFBOARD)
                {
                    Key ^= PieceKeys[piece, sq];
                }
            }

            if (brett.seite == (int)defs.Farben.WEISS)
            {
                Key ^= SideKey;
            }

            if (brett.enPas != (int)defs.Felder.NO_SQ)
            {
                Key ^= PieceKeys[(int)defs.Figuren.LEER, brett.enPas];
            }

            Key ^= CastleKeys[brett.rochadePerm];

            return(Key);
        }
Ejemplo n.º 15
0
        //zum kompletten umdrehen einer position damit man evaluierungsfunktion nur für weis schreiben muss
        public static void MirrorBoard(ref boardStruct brett)
        {
            int[] tempPiecesArray = new int [64];
            int   tempSide        = brett.seite ^ 1;

            int[] SwapPiece      = { (int)defs.Figuren.LEER, (int)defs.Figuren.sB, (int)defs.Figuren.sP, (int)defs.Figuren.sL, (int)defs.Figuren.sT, (int)defs.Figuren.sD, (int)defs.Figuren.sK, (int)defs.Figuren.wB, (int)defs.Figuren.wP, (int)defs.Figuren.wL, (int)defs.Figuren.wT, (int)defs.Figuren.wD, (int)defs.Figuren.wK };
            int   tempCastlePerm = 0;
            int   tempEnPas      = (int)defs.Felder.NO_SQ;

            int sq;
            int tp;

            if ((brett.rochadePerm & (int)defs.Rochade.WKRC) != 0)
            {
                tempCastlePerm |= (int)defs.Rochade.SKRC;
            }
            if ((brett.rochadePerm & (int)defs.Rochade.WDRC) != 0)
            {
                tempCastlePerm |= (int)defs.Rochade.SDRC;
            }

            if ((brett.rochadePerm & (int)defs.Rochade.SKRC) != 0)
            {
                tempCastlePerm |= (int)defs.Rochade.SKRC;
            }
            if ((brett.rochadePerm & (int)defs.Rochade.SDRC) != 0)
            {
                tempCastlePerm |= (int)defs.Rochade.SDRC;
            }

            if (brett.enPas != (int)defs.Felder.NO_SQ)
            {
                tempEnPas = defs.Sq64ToSq120[data.Mirror64[defs.Sq120ToSq64[brett.enPas]]];
            }

            for (sq = 0; sq < 64; sq++)
            {
                tempPiecesArray[sq] = brett.figuren[defs.Sq64ToSq120[data.Mirror64[sq]]];
            }

            ResetBoard(ref brett);

            for (sq = 0; sq < 64; sq++)
            {
                tp = SwapPiece[tempPiecesArray[sq]];
                brett.figuren[defs.Sq64ToSq120[sq]] = tp;
            }

            brett.seite       = tempSide;
            brett.rochadePerm = tempCastlePerm;
            brett.enPas       = tempEnPas;

            brett.posKey = hashkeys.GeneratePosKey(ref brett);

            UpdateListsMaterial(ref brett);

            Debug.Assert(CheckBoard(ref brett));
        }
Ejemplo n.º 16
0
        public static void ClearPiece(int sq, ref boardStruct brett)
        {
            Debug.Assert(validate.SqOnBoard(sq));
            Debug.Assert(board.CheckBoard(ref brett));

            int pce = brett.figuren[sq];

            Debug.Assert(validate.PieceValid(pce));

            int col      = data.PieceCol[pce];
            int index    = 0;
            int t_pceNum = -1;

            Debug.Assert(validate.SideValid(col));

            makros.HashInPiece(pce, sq, ref brett);

            brett.figuren[sq]    = (int)defs.Figuren.LEER;
            brett.material[col] -= data.PieceVal[pce];

            if (data.PieceBig[pce])
            {
                brett.bigPce[col]--;

                if (data.PieceMaj[pce])
                {
                    brett.majPce[col]--;
                }
                else
                {
                    brett.minPce[col]--;
                }
            }
            else
            {
                makros.ClearBit(ref brett.bauern[col], defs.Sq120ToSq64[sq]);
                makros.ClearBit(ref brett.bauern[(int)defs.Farben.BEIDE], defs.Sq120ToSq64[sq]);
            }

            for (index = 0; index < brett.pceNum[pce]; ++index)
            {
                if (brett.fListe[pce, index] == sq)
                {
                    t_pceNum = index;
                    break;
                }
            }

            Debug.Assert(t_pceNum != -1);
            Debug.Assert(t_pceNum >= 0 && t_pceNum < 10);

            brett.pceNum[pce]--;

            brett.fListe[pce, t_pceNum] = brett.fListe[pce, brett.pceNum[pce]];
        }
Ejemplo n.º 17
0
 public static void AllInit(ref boardStruct brett)
 {
     InitSq120To64();
     InitBitMasks();
     InitHashKeys();
     InitFilesRanksBrd();
     PvTable.InitHashTable(ref brett.PvTable, 500);
     movegen.InitMvvLva();
     InitEvaluationMasks();
     polybook.InitPolyBook();
 }
Ejemplo n.º 18
0
 public static bool IsRepetition(ref boardStruct brett)
 {
     for (int index = brett.hisPly - brett.fiftyMove; index < brett.hisPly - 1; ++index)
     {
         Debug.Assert(index >= 0 && index < defs.MAXSPIELZÜGE);
         if (brett.posKey == brett.history[index].PosKey)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 19
0
        public static void UpdateListsMaterial(ref boardStruct brett)
        {
            int piece, sq, index, colour;

            for (index = 0; index < defs.BRD_SQ_NUM; ++index)
            {
                sq    = index;
                piece = brett.figuren[index];
                if (piece != (int)defs.Felder.OFFBOARD && piece != (int)defs.Figuren.LEER)
                {
                    colour = data.PieceCol[piece];

                    if (data.PieceBig[piece])
                    {
                        brett.bigPce[colour]++;
                    }
                    if (data.PieceMin[piece])
                    {
                        brett.minPce[colour]++;
                    }
                    if (data.PieceMaj[piece])
                    {
                        brett.majPce[colour]++;
                    }

                    brett.material[colour] += data.PieceVal[piece];

                    brett.fListe[piece, brett.pceNum[piece]] = sq;
                    brett.pceNum[piece]++;

                    if (piece == (int)defs.Figuren.wK)
                    {
                        brett.KönigSq[(int)defs.Farben.WEISS] = sq;
                    }
                    if (piece == (int)defs.Figuren.sK)
                    {
                        brett.KönigSq[(int)defs.Farben.SCHWARZ] = sq;
                    }

                    if (piece == (int)defs.Figuren.wB)
                    {
                        makros.SetBit(ref brett.bauern[(int)defs.Farben.WEISS], defs.Sq120ToSq64[sq]);
                        makros.SetBit(ref brett.bauern[(int)defs.Farben.BEIDE], defs.Sq120ToSq64[sq]);
                    }

                    else if (piece == (int)defs.Figuren.sB)
                    {
                        makros.SetBit(ref brett.bauern[(int)defs.Farben.SCHWARZ], defs.Sq120ToSq64[sq]);
                        makros.SetBit(ref brett.bauern[(int)defs.Farben.BEIDE], defs.Sq120ToSq64[sq]);
                    }
                }
            }
        }
Ejemplo n.º 20
0
 static bool MaterialDraw(ref boardStruct brett)
 {
     if (brett.pceNum[(int)defs.Figuren.wT] == 0 && brett.pceNum[(int)defs.Figuren.sT] == 0 && brett.pceNum[(int)defs.Figuren.wD] == 0 && brett.pceNum[(int)defs.Figuren.sD] == 0)
     {
         if (brett.pceNum[(int)defs.Figuren.sL] == 0 && brett.pceNum[(int)defs.Figuren.wL] == 0)
         {
             if (brett.pceNum[(int)defs.Figuren.wP] < 3 && brett.pceNum[(int)defs.Figuren.sP] < 3)
             {
                 return(true);
             }
         }
         else if (brett.pceNum[(int)defs.Figuren.wP] == 0 && brett.pceNum[(int)defs.Figuren.sP] == 0)
         {
             if (Math.Abs(brett.pceNum[(int)defs.Figuren.wL] - brett.pceNum[(int)defs.Figuren.sL]) < 2)
             {
                 return(true);
             }
         }
         else if ((brett.pceNum[(int)defs.Figuren.wP] < 3 && brett.pceNum[(int)defs.Figuren.wL] == 0) || (brett.pceNum[(int)defs.Figuren.wL] == 1 && brett.pceNum[(int)defs.Figuren.wP] == 0))
         {
             if ((brett.pceNum[(int)defs.Figuren.sP] < 3 && brett.pceNum[(int)defs.Figuren.sL] == 0) || (brett.pceNum[(int)defs.Figuren.sL] == 1 && brett.pceNum[(int)defs.Figuren.sP] == 0))
             {
                 return(true);
             }
         }
     }
     else if (brett.pceNum[(int)defs.Figuren.wD] == 0 && brett.pceNum[(int)defs.Figuren.sD] == 0)
     {
         if (brett.pceNum[(int)defs.Figuren.wT] == 1 && brett.pceNum[(int)defs.Figuren.sT] == 1)
         {
             if ((brett.pceNum[(int)defs.Figuren.wP] + brett.pceNum[(int)defs.Figuren.wL]) < 2 && (brett.pceNum[(int)defs.Figuren.sP] + brett.pceNum[(int)defs.Figuren.sL]) < 2)
             {
                 return(true);
             }
         }
         else if (brett.pceNum[(int)defs.Figuren.wT] == 1 && brett.pceNum[(int)defs.Figuren.sT] == 0)
         {
             if ((brett.pceNum[(int)defs.Figuren.wP] + brett.pceNum[(int)defs.Figuren.wL] == 0) && (((brett.pceNum[(int)defs.Figuren.sP] + brett.pceNum[(int)defs.Figuren.sL]) == 1) || ((brett.pceNum[(int)defs.Figuren.sP] + brett.pceNum[(int)defs.Figuren.sL]) == 2)))
             {
                 return(true);
             }
         }
         else if (brett.pceNum[(int)defs.Figuren.sT] == 1 && brett.pceNum[(int)defs.Figuren.wT] == 0)
         {
             if ((brett.pceNum[(int)defs.Figuren.sP] + brett.pceNum[(int)defs.Figuren.sL] == 0) && (((brett.pceNum[(int)defs.Figuren.wP] + brett.pceNum[(int)defs.Figuren.wL]) == 1) || ((brett.pceNum[(int)defs.Figuren.wP] + brett.pceNum[(int)defs.Figuren.wL]) == 2)))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 21
0
 static void AddBlackPawnMove(int from, int to, ref movelist list, ref boardStruct brett)
 {
     if (defs.RanksBrd[from] == (int)defs.Zeilen.ZEILE_2)
     {
         AddQuietMove(makros.ZugGenerieren(from, to, (int)defs.Figuren.LEER, (int)defs.Figuren.sD, 0), ref list, ref brett);
         AddQuietMove(makros.ZugGenerieren(from, to, (int)defs.Figuren.LEER, (int)defs.Figuren.sT, 0), ref list, ref brett);
         AddQuietMove(makros.ZugGenerieren(from, to, (int)defs.Figuren.LEER, (int)defs.Figuren.sL, 0), ref list, ref brett);
         AddQuietMove(makros.ZugGenerieren(from, to, (int)defs.Figuren.LEER, (int)defs.Figuren.sP, 0), ref list, ref brett);
     }
     else
     {
         AddQuietMove(makros.ZugGenerieren(from, to, (int)defs.Figuren.LEER, (int)defs.Figuren.LEER, 0), ref list, ref brett);
     }
 }
Ejemplo n.º 22
0
        static int ThreeFoldRep(ref boardStruct brett)
        {
            Debug.Assert(board.CheckBoard(ref brett));
            int r = 0;

            for (int i = 0; i < brett.hisPly; ++i)
            {
                if (brett.history[i].PosKey == brett.posKey)
                {
                    r++;
                }
            }
            return(r);
        }
Ejemplo n.º 23
0
        public static void ResetBoard(ref boardStruct brett)
        {
            for (int index = 0; index < defs.BRD_SQ_NUM; ++index)
            {
                brett.figuren[index] = (int)defs.Felder.OFFBOARD;
            }

            for (int index = 0; index < 64; ++index)
            {
                brett.figuren[defs.Sq64ToSq120[index]] = (int)defs.Figuren.LEER;
            }

            for (int index = 0; index < 2; ++index)
            {
                brett.bigPce[index] = 0;
                brett.majPce[index] = 0;
                brett.minPce[index] = 0;
            }

            for (int index = 0; index < 3; ++index)
            {
                brett.bauern[index]   = 0UL;
                brett.material[index] = 0;
            }

            for (int index = 0; index < 13; ++index)
            {
                brett.pceNum[index] = 0;
            }

            brett.KönigSq[(int)defs.Farben.WEISS] = brett.KönigSq[(int)defs.Farben.SCHWARZ] = (int)defs.Felder.NO_SQ;

            brett.seite     = (int)defs.Farben.BEIDE;
            brett.enPas     = (int)defs.Felder.NO_SQ;
            brett.fiftyMove = 0;

            brett.ply    = 0;
            brett.hisPly = 0;

            brett.rochadePerm = 0;

            brett.posKey = 0UL;
        }
Ejemplo n.º 24
0
        static void AddQuietMove(int zug, ref movelist list, ref boardStruct brett)
        {
            list.zugliste[list.anzahlZüge].Zug = zug;

            if (brett.searchKillers[0, brett.ply] == zug)
            {
                list.zugliste[list.anzahlZüge].Wertung = 900000;
            }
            else if (brett.searchKillers[1, brett.ply] == zug)
            {
                list.zugliste[list.anzahlZüge].Wertung = 800000;
            }
            else
            {
                list.zugliste[list.anzahlZüge].Wertung = brett.searchHistory[brett.figuren[makros.FromSq(zug)], makros.ToSq(zug)];
            }

            list.anzahlZüge++;
        }
Ejemplo n.º 25
0
        public static bool MoveExists(ref boardStruct brett, int move)
        {
            movelist list = new movelist();

            GenerateAllMoves(ref list, ref brett);

            int MoveNum = 0;

            for (MoveNum = 0; MoveNum < list.anzahlZüge; ++MoveNum)
            {
                if (!makemove.MakeMove(list.zugliste[MoveNum].Zug, ref brett))
                {
                    continue;
                }
                makemove.TakeMove(ref brett);
                if (list.zugliste[MoveNum].Zug == move)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 26
0
        public static int GetBookMove(ref boardStruct brett)
        {
            ushort move;
            int    MAXBOOKMOVES = 32;

            int[] bookMoves = new int[MAXBOOKMOVES];
            int   tempMove  = defs.NOMOVE;
            int   count     = 0;
            ulong polyKey   = PolyKeyFromBoard(ref brett);

            for (int i = 0; i < entries.Length; i++)
            {
                if (polyKey == endian_swap_u64(entries[i].key))
                {
                    move     = endian_swap_u16(entries[i].move);
                    tempMove = ConvertPolyMoveToInternalMove(move, ref brett);
                    if (tempMove != defs.NOMOVE)
                    {
                        bookMoves[count++] = tempMove;
                        if (count > MAXBOOKMOVES)
                        {
                            break;
                        }
                    }
                }
            }

            if (count != 0)
            {
                Random rnd = new Random();
                int    i   = rnd.Next(0, count);
                return(bookMoves[i]);
            }
            else
            {
                return(defs.NOMOVE);
            }
        }
Ejemplo n.º 27
0
        public static int ProbePvMove(ref boardStruct brett)
        {
            int index = Convert.ToInt32(Convert.ToUInt64(brett.posKey) % Convert.ToUInt64(brett.PvTable.numEntries));

            try
            {
                if (brett.PvTable.hashTable[index].posKey == 0)
                {
                    ;
                }
            }
            catch
            {
                brett.PvTable.hashTable[index] = new hashEntry(0, 0, 0, 0, 0);
            }

            if (brett.PvTable.hashTable[index].posKey == brett.posKey)
            {
                return(brett.PvTable.hashTable[index].move);
            }

            return(defs.NOMOVE);
        }
Ejemplo n.º 28
0
        public static void ParsePosition(string input, ref boardStruct brett)
        {
            if (input.Substring(9, 8) == "startpos")
            {
                board.ParseFen(defs.START, ref brett);
            }
            else
            {
                board.ParseFen(input.Substring(13), ref brett);
            }

            int pointer = input.IndexOf("moves");
            int move;

            if (pointer != -1)
            {
                pointer += 6;

                while (pointer < input.Length)
                {
                    move = io.ParseMove(input.Substring(pointer), ref brett);
                    if (move == defs.NOMOVE)
                    {
                        break;
                    }
                    makemove.MakeMove(move, ref brett);
                    brett.ply = 0;
                    while (pointer < input.Length && input[pointer] != ' ')
                    {
                        pointer++;
                    }
                    pointer++;
                }
            }

            Console.WriteLine(io.PrintBoard(ref brett));
        }
Ejemplo n.º 29
0
        public static void StoreHashEntry(int move, int score, int flags, int depth, ref boardStruct brett)
        {
            int index = Convert.ToInt32(Convert.ToUInt64(brett.posKey) % Convert.ToUInt64(brett.PvTable.numEntries));

            if (brett.PvTable.hashTable[index].posKey == 0)
            {
                brett.PvTable.newWrite++;
            }
            else
            {
                brett.PvTable.overWrite++;
            }

            if (score > defs.ISMATE)
            {
                score += brett.ply;
            }
            else if (score < -defs.ISMATE)
            {
                score -= brett.ply;
            }

            brett.PvTable.hashTable[index] = new hashEntry(brett.posKey, move, score, depth, flags);
        }
Ejemplo n.º 30
0
        public static int EvalPosition(ref boardStruct brett)
        {
            int pce;
            int pceNum;
            int sq;
            int score = brett.material[(int)defs.Farben.WEISS] - brett.material[(int)defs.Farben.SCHWARZ];

            if (brett.pceNum[(int)defs.Figuren.wB] == 0 && brett.pceNum[(int)defs.Figuren.sB] == 0 && MaterialDraw(ref brett))
            {
                return(0);
            }

            pce = (int)defs.Figuren.wB;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq     = brett.fListe[pce, pceNum];
                score += PawnTable[defs.Sq120ToSq64[sq]];

                if ((defs.IsolatedMask[defs.Sq120ToSq64[sq]] & brett.bauern[(int)defs.Farben.WEISS]) == 0)
                {
                    score += PawnIsolated;
                }

                if ((defs.WhitePassedMask[defs.Sq120ToSq64[sq]] & brett.bauern[(int)defs.Farben.SCHWARZ]) == 0)
                {
                    score += PawnPassed[defs.RanksBrd[sq]];
                }
            }

            pce = (int)defs.Figuren.sB;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq     = brett.fListe[pce, pceNum];
                score -= PawnTable[data.Mirror64[defs.Sq120ToSq64[sq]]];

                if ((defs.IsolatedMask[defs.Sq120ToSq64[sq]] & brett.bauern[(int)defs.Farben.SCHWARZ]) == 0)
                {
                    //Console.WriteLine("bP Iso:" + io.PrSq(sq));
                    score -= PawnIsolated;
                }

                if ((defs.BlackPassedMask[defs.Sq120ToSq64[sq]] & brett.bauern[(int)defs.Farben.WEISS]) == 0)
                {
                    //Console.WriteLine("bP Passed:" + io.PrSq(sq));
                    score -= PawnPassed[7 - defs.RanksBrd[sq]];
                }
            }


            pce = (int)defs.Figuren.wP;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq = brett.fListe[pce, pceNum];
                Debug.Assert(validate.SqOnBoard(sq));
                score += KnightTable[defs.Sq120ToSq64[sq]];
            }

            pce = (int)defs.Figuren.sP;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq = brett.fListe[pce, pceNum];
                Debug.Assert(validate.SqOnBoard(sq));
                score -= KnightTable[data.Mirror64[defs.Sq120ToSq64[sq]]];
            }

            pce = (int)defs.Figuren.wL;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq = brett.fListe[pce, pceNum];
                Debug.Assert(validate.SqOnBoard(sq));
                score += BishopTable[defs.Sq120ToSq64[sq]];
            }

            pce = (int)defs.Figuren.sL;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq = brett.fListe[pce, pceNum];
                Debug.Assert(validate.SqOnBoard(sq));
                score -= BishopTable[data.Mirror64[defs.Sq120ToSq64[sq]]];
            }

            pce = (int)defs.Figuren.wT;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq = brett.fListe[pce, pceNum];
                Debug.Assert(validate.SqOnBoard(sq));
                score += RookTable[defs.Sq120ToSq64[sq]];

                if ((brett.bauern[(int)defs.Farben.BEIDE] & defs.FileMask[defs.FilesBrd[sq]]) == 0)
                {
                    score += RookOpenFile;
                }
                else if ((brett.bauern[(int)defs.Farben.WEISS] & defs.FileMask[defs.FilesBrd[sq]]) == 0)
                {
                    score += RookSemiOpenFile;
                }
            }

            pce = (int)defs.Figuren.sT;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq = brett.fListe[pce, pceNum];
                Debug.Assert(validate.SqOnBoard(sq));
                score -= RookTable[data.Mirror64[defs.Sq120ToSq64[sq]]];

                if ((brett.bauern[(int)defs.Farben.BEIDE] & defs.FileMask[defs.FilesBrd[sq]]) == 0)
                {
                    score -= RookOpenFile;
                }
                else if ((brett.bauern[(int)defs.Farben.SCHWARZ] & defs.FileMask[defs.FilesBrd[sq]]) == 0)
                {
                    score -= RookSemiOpenFile;
                }
            }

            pce = (int)defs.Figuren.wD;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq = brett.fListe[pce, pceNum];
                if ((brett.bauern[(int)defs.Farben.BEIDE] & defs.FileMask[defs.FilesBrd[sq]]) == 0)
                {
                    score += QueenOpenFile;
                }
                else if ((brett.bauern[(int)defs.Farben.WEISS] & defs.FileMask[defs.FilesBrd[sq]]) == 0)
                {
                    score += QueenSemiOpenFile;
                }
            }

            pce = (int)defs.Figuren.sD;
            for (pceNum = 0; pceNum < brett.pceNum[pce]; ++pceNum)
            {
                sq = brett.fListe[pce, pceNum];
                if ((brett.bauern[(int)defs.Farben.BEIDE] & defs.FileMask[defs.FilesBrd[sq]]) == 0)
                {
                    score -= QueenOpenFile;
                }
                else if ((brett.bauern[(int)defs.Farben.SCHWARZ] & defs.FileMask[defs.FilesBrd[sq]]) == 0)
                {
                    score -= QueenSemiOpenFile;
                }
            }

            pce = (int)defs.Figuren.wK;
            sq  = brett.fListe[pce, 0];

            if ((brett.material[(int)defs.Farben.SCHWARZ] <= (1 * data.PieceVal[(int)defs.Figuren.wT] + 2 * data.PieceVal[(int)defs.Figuren.wP] + 2 * data.PieceVal[(int)defs.Figuren.wB] + data.PieceVal[(int)defs.Figuren.wK])))
            {
                score += KingE[defs.Sq120ToSq64[sq]];
            }
            else
            {
                score += KingO[defs.Sq120ToSq64[sq]];
            }

            pce = (int)defs.Figuren.sK;
            sq  = brett.fListe[pce, 0];

            if ((brett.material[(int)defs.Farben.WEISS] <= (1 * data.PieceVal[(int)defs.Figuren.wT] + 2 * data.PieceVal[(int)defs.Figuren.wP] + 2 * data.PieceVal[(int)defs.Figuren.wB] + data.PieceVal[(int)defs.Figuren.wK])))
            {
                score -= KingE[data.Mirror64[defs.Sq120ToSq64[sq]]];
            }
            else
            {
                score -= KingO[data.Mirror64[defs.Sq120ToSq64[sq]]];
            }

            if (brett.pceNum[(int)defs.Figuren.wL] >= 2)
            {
                score += BishopPair;
            }
            if (brett.pceNum[(int)defs.Figuren.sL] >= 2)
            {
                score -= BishopPair;
            }

            if (brett.seite == (int)defs.Farben.WEISS)
            {
                return(score);
            }
            else
            {
                return(-score);
            }
        }