public OthelloAI(int depth, int color) { searchDepth = depth; selfColor = color; currentDepthMax = searchDepth; evaluator = new OthelloEvaluator(); transpositionTable = new Dictionary <string, TranspositionTableEntry>(); Debug.Log(string.Format("w1{0} w2{1} w3{2}", evaluator.w1, evaluator.w2, evaluator.w3)); }
// Quick sort using transposition table in ascending order List <int[, ]> SortByScore(List <int[, ]> list, int color) { if (list.Count <= 1) { return(list); } List <int[, ]> left = new List <int[, ]>(); List <int[, ]> center = new List <int[, ]>(); List <int[, ]> right = new List <int[, ]>(); int[,] refBoard = list[0]; string refBoardHash = BoardToHash(refBoard); double refScore; if (transpositionTable.ContainsKey(refBoardHash)) { refScore = transpositionTable[refBoardHash].Score; } else { OthelloEvaluator tmpEvaluator = new OthelloEvaluator(); tmpEvaluator.SetBoard(refBoard); refScore = tmpEvaluator.Evaluate(selfColor); transpositionTable[refBoardHash] = new TranspositionTableEntry(refBoard, currentDepthMax, refScore, "TEMP"); } center.Add(refBoard); foreach (int[,] board in list) { sortAllCount += 1; string boardHash = BoardToHash(board); double boardScore; if (transpositionTable.ContainsKey(boardHash)) { boardScore = transpositionTable[boardHash].Score; } else { sortEvalCount += 1; OthelloEvaluator tmpEvaluator = new OthelloEvaluator(); tmpEvaluator.SetBoard(board); boardScore = tmpEvaluator.Evaluate(selfColor); transpositionTable[boardHash] = new TranspositionTableEntry(board, currentDepthMax, boardScore, "TEMP"); } if (boardScore < refScore) { left.Add(board); } else if (boardScore > refScore) { right.Add(board); } else { center.Add(board); } } left = SortByScore(left, color); right = SortByScore(right, color); return(left.Concat(center).Concat(right).ToList()); }