コード例 #1
0
 /** Extract the PV starting from pos, using hash entries, both exact scores and bounds. */
 public string extractPV(Position pos)
 {
     string ret = "";
     pos = new Position(pos);    // To avoid modifying the input parameter
     bool first = true;
     TTEntry ent = probe(pos.historyHash());
     UndoInfo ui = new UndoInfo();
     List<ulong> hashHistory = new List<ulong>();
     bool repetition = false;
     while (ent.type != TTEntry.T_EMPTY) {
     string type = "";
     if (ent.type == TTEntry.T_LE) {
         type = "<";
     } else if (ent.type == TTEntry.T_GE) {
         type = ">";
     }
     Move m = new Move(0,0,0);
     ent.getMove(m);
     MoveGen MG = new MoveGen();
     MoveGen.MoveList moves = MG.pseudoLegalMoves(pos);
     MoveGen.RemoveIllegal(pos, moves);
     bool contains = false;
     for (int mi = 0; mi < moves.size; mi++)
         if (moves.m[mi].equals(m)) {
             contains = true;
             break;
         }
     if  (!contains)
         break;
     string moveStr = TextIO.moveTostring(pos, m, false);
     if (repetition)
         break;
     if (!first) {
         ret += " ";
     }
     ret += type + moveStr;
     pos.makeMove(m, ui);
     if (hashHistory.Contains(pos.zobristHash())) {
         repetition = true;
     }
     hashHistory.Add(pos.zobristHash());
     ent = probe(pos.historyHash());
     first = false;
     }
     return ret;
 }
コード例 #2
0
 /**
  * Extract a list of PV moves, starting from "rootPos" and first move "m".
  */
 public List<Move> extractPVMoves(Position rootPos, Move m)
 {
     Position pos = new Position(rootPos);
     m = new Move(m);
     List<Move> ret = new List<Move>();
     UndoInfo ui = new UndoInfo();
     List<ulong> hashHistory = new List<ulong>();
     MoveGen moveGen = new MoveGen();
     while (true) {
     ret.Add(m);
     pos.makeMove(m, ui);
     if (hashHistory.Contains(pos.zobristHash())) {
         break;
     }
     hashHistory.Add(pos.zobristHash());
     TTEntry ent = probe(pos.historyHash());
     if (ent.type == TTEntry.T_EMPTY) {
         break;
     }
     m = new Move(0,0,0);
     ent.getMove(m);
     MoveGen.MoveList moves = moveGen.pseudoLegalMoves(pos);
     MoveGen.RemoveIllegal(pos, moves);
     bool contains = false;
     for (int mi = 0; mi < moves.size; mi++)
         if (moves.m[mi].equals(m)) {
             contains = true;
             break;
         }
     if  (!contains)
         break;
     }
     return ret;
 }