Beispiel #1
0
        int SearchDivide(int startDepth, int currentDepth)
        {
            var moves = moveGenerator.GenerateMoves(board);

            if (currentDepth == 1)
            {
                return(moves.Count);
            }

            int numLocalNodes = 0;

            for (int i = 0; i < moves.Count; i++)
            {
                board.MakeMove(moves[i]);
                int numMovesForThisNode = SearchDivide(startDepth, currentDepth - 1);
                numLocalNodes += numMovesForThisNode;
                board.UnmakeMove(moves[i]);

                if (currentDepth == startDepth)
                {
                    perftDivideResults.Add(PerftUtility.MoveName(moves[i]), numMovesForThisNode);
                }
            }
            return(numLocalNodes);
        }
Beispiel #2
0
        void ComparePerftDivideResults(string fen)
        {
            string[] expected = expectedResults.text.Split('\n');
            Dictionary <string, int> expectedPerftDResults = new Dictionary <string, int> ();

            foreach (string line in expected)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                string moveName  = line.Split(':') [0];
                string nodeCount = line.Split(':') [1].Trim();
                expectedPerftDResults.Add(moveName, int.Parse(nodeCount));
            }

            foreach (string move in expectedPerftDResults.Keys)
            {
                if (perftDivideResults.ContainsKey(move))
                {
                    int expectedValue = expectedPerftDResults[move];
                    int actualValue   = perftDivideResults[move];

                    if (expectedValue != actualValue)
                    {
                        board.LoadPosition(fen);
                        var movesFromPos = moveGenerator.GenerateMoves(board);
                        for (int i = 0; i < movesFromPos.Count; i++)
                        {
                            Move m = movesFromPos[i];
                            if (PerftUtility.MoveName(m) == move)
                            {
                                board.MakeMove(m);
                                break;
                            }
                        }

                        Debug.Log(string.Format("{0}: Expected {1} but had {2}", move, expectedValue, actualValue));
                        Debug.Log("Fen after this move: " + FenUtility.CurrentFen(board));
                    }
                }
                else
                {
                    Debug.Log("Expected move: " + move + ", but was not found.");
                }
            }
        }