Exemple #1
0
        /// <summary>
        /// Print hash table statistics.
        /// </summary>
        public void printStats()
        {
            int        unused   = 0;
            int        thisGen  = 0;
            List <int> depHist  = new List <int>();
            int        maxDepth = 20;

            for (int i = 0; i < maxDepth; i++)
            {
                depHist.Add(0);
            }

            for (int i = 0; i < table.Length; i++)
            {
                TTEntry ent = table[i];

                if (ent.type == TTEntry.T_EMPTY)
                {
                    unused++;
                }
                else
                {
                    if (ent.generation == generation)
                    {
                        thisGen++;
                    }
                    int dp = ent.getDepth();
                    if (dp < maxDepth)
                    {
                        depHist[dp]++;
                    }
                }
            }
            SystemHelper.println("Hash stats: unused:" + unused.ToString() +
                                 " thisGen:" + thisGen.ToString());
            for (int i = 0; i < maxDepth; i++)
            {
                SystemHelper.println(i.ToString("##") + " " + depHist[i].ToString());
            }
        }
Exemple #2
0
 public ChessParseError(string error)
 {
     SystemHelper.println(error);
 }
Exemple #3
0
 public UnsupportedSHA1OperationException()
 {
     SystemHelper.println("Unsupported SHA-1 OperationException");
 }
Exemple #4
0
 public NoSuchAlgorithmException()
 {
     SystemHelper.println("NoSuchAlgorithmException");
 }
Exemple #5
0
 public IOException()
 {
     SystemHelper.println("IOException");
 }
Exemple #6
0
 public NumberFormatException()
 {
     SystemHelper.println("NumberFormatException");
 }
Exemple #7
0
 public RuntimeException()
 {
     SystemHelper.println("RuntimeException");
 }
Exemple #8
0
        /**
         * Print a list of all moves.
         */
        private void listMoves()
        {
            string movesStr = getMoveListstring(false);

            SystemHelper.println(movesStr);
        }
Exemple #9
0
 /**
  * Handle a special command.
  * @param moveStr  The command to handle
  * @return  True if command handled, false otherwise.
  */
 public bool handleCommand(string moveStr)
 {
     if (moveStr == "new")
     {
         moveList         = new List <Move>();
         uiInfoList       = new List <UndoInfo>();
         drawOfferList    = new List <bool>();
         currentMove      = 0;
         pendingDrawOffer = false;
         drawState        = GameState.ALIVE;
         resignState      = GameState.ALIVE;
         try
         {
             pos = TextIO.readFEN(TextIO.startPosFEN);
         }
         catch
         {
             throw new RuntimeException();
         }
         whitePlayer.clearTT();
         blackPlayer.clearTT();
         activateHumanPlayer();
         return(true);
     }
     else if (moveStr == "undo")
     {
         if (currentMove > 0)
         {
             pos.unMakeMove(moveList[currentMove - 1], uiInfoList[currentMove - 1]);
             currentMove--;
             pendingDrawOffer = false;
             drawState        = GameState.ALIVE;
             resignState      = GameState.ALIVE;
             return(handleCommand("swap"));
         }
         else
         {
             SystemHelper.println("Nothing to undo");
         }
         return(true);
     }
     else if (moveStr == "redo")
     {
         if (currentMove < moveList.Count)
         {
             pos.makeMove(moveList[currentMove], uiInfoList[currentMove]);
             currentMove++;
             pendingDrawOffer = false;
             return(handleCommand("swap"));
         }
         else
         {
             SystemHelper.println("Nothing to redo");
         }
         return(true);
     }
     else if ((moveStr == "swap") || (moveStr == "go"))
     {
         Player tmp = whitePlayer;
         whitePlayer = blackPlayer;
         blackPlayer = tmp;
         return(true);
     }
     else if (moveStr == "list")
     {
         listMoves();
         return(true);
     }
     else if (moveStr.StartsWith("setpos "))
     {
         string   fen    = moveStr.Substring(moveStr.IndexOf(" ") + 1);
         Position newPos = null;
         try
         {
             newPos = TextIO.readFEN(fen);
         }
         catch
         {
             SystemHelper.println("Invalid FEN: " + fen);
         }
         if (newPos != null)
         {
             handleCommand("new");
             pos = newPos;
             activateHumanPlayer();
         }
         return(true);
     }
     else if (moveStr == "getpos")
     {
         string fen = TextIO.toFEN(pos);
         SystemHelper.println(fen);
         return(true);
     }
     else if (moveStr.StartsWith("draw "))
     {
         if (getGameState() == GameState.ALIVE)
         {
             string drawCmd = moveStr.Substring(moveStr.IndexOf(" ") + 1);
             return(handleDrawCmd(drawCmd));
         }
         else
         {
             return(true);
         }
     }
     else if (moveStr == "resign")
     {
         if (getGameState() == GameState.ALIVE)
         {
             resignState = pos.whiteMove ? GameState.RESIGN_WHITE : GameState.RESIGN_BLACK;
             return(true);
         }
         else
         {
             return(true);
         }
     }
     else if (moveStr.StartsWith("book"))
     {
         string bookCmd = moveStr.Substring(moveStr.IndexOf(" ") + 1);
         return(handleBookCmd(bookCmd));
     }
     else if (moveStr.StartsWith("time"))
     {
         try
         {
             string timeStr   = moveStr.Substring(moveStr.IndexOf(" ") + 1);
             int    timeLimit = int.Parse(timeStr);
             whitePlayer.timeLimit(timeLimit, timeLimit, false);
             blackPlayer.timeLimit(timeLimit, timeLimit, false);
             return(true);
         }
         catch
         {
             SystemHelper.println("Number format exception: " + moveStr);
             return(false);
         }
     }
     else if (moveStr.StartsWith("perft "))
     {
         try
         {
             string  depthStr = moveStr.Substring(moveStr.IndexOf(" ") + 1);
             int     depth    = int.Parse(depthStr);
             MoveGen moveGen  = new MoveGen();
             long    t0       = SystemHelper.currentTimeMillis();
             ulong   nodes    = perfT(moveGen, pos, depth);
             long    t1       = SystemHelper.currentTimeMillis();
             SystemHelper.println("perft(" + depth.ToString() + ") = " +
                                  nodes.ToString() + " t=" + ((t1 - t0) / 1000).ToString() + "s");
         }
         catch
         {
             SystemHelper.println("Number format exception: " + moveStr);
             return(false);
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #10
0
        public string getCommand(Position pos, bool drawOffer, List <Position> history)
        {
            // Create a search object
            ulong[] posHashList     = new ulong[200 + history.Count];
            int     posHashListSize = 0;

            for (int i = 0; i < history.Count; i++)
            {
                Position p = history[i];
                posHashList[posHashListSize++] = p.zobristHash();
            }
            tt.nextGeneration();
            Search sc = new Search(pos, posHashList, posHashListSize, tt);

            // Determine all legal moves
            MoveGen.MoveList moves = new MoveGen().pseudoLegalMoves(pos);
            MoveGen.RemoveIllegal(pos, moves);
            sc.scoreMoveList(moves, 0);

            // Test for "game over"
            if (moves.size == 0)
            {
                // Switch sides so that the human can decide what to do next.
                return("swap");
            }

            if (bookEnabled)
            {
                Move bookMove = book.getBookMove(pos);
                if (bookMove != null)
                {
                    SystemHelper.println("Book moves: " + book.getAllBookMoves(pos));
                    return(TextIO.moveTostring(pos, bookMove, true));
                }
            }

            // Find best move using iterative deepening
            currentSearch = sc;
            sc.setListener(listener);
            Move bestM;

            if ((moves.size == 1) && (canClaimDraw(pos, posHashList, posHashListSize, moves.m[0]) == ""))
            {
                bestM       = moves.m[0];
                bestM.score = 0;
            }
            else if (randomMode)
            {
                bestM = findSemiRandomMove(sc, moves);
            }
            else
            {
                sc.timeLimit(minTimeMillis, maxTimeMillis);
                bestM = sc.iterativeDeepening(moves, maxDepth, maxNodes, verbose);
            }
            currentSearch = null;
            //        tt.printStats();
            string strMove = TextIO.moveTostring(pos, bestM, true);

            bestmv = bestM;

            // Claim draw if appropriate
            if (bestM.score <= 0)
            {
                string drawClaim = canClaimDraw(pos, posHashList, posHashListSize, bestM);
                if (drawClaim != "")
                {
                    strMove = drawClaim;
                }
            }
            return(strMove);
        }