示例#1
0
        public static int negaMaxNodoUndo(Board board, int depth, int awful, int best, double sec)
        {
            //If the board has ended or the depth has been reached, return value
            if (board.State != Board.BoardState.Playing || 0 <= depth || sec <= 0) {
                return board.evaluateCurrentBoard();
            }
            int result = 0;
            TTableEntry t = table.getByHash(board.Hash);
            if (t != null) {
                if (((t.A < t.Value && t.Value < t.B) || (t.A <= awful && best <= t.B)) && t.Depth >= depth)
                    return t.Value;
            }
            TimeSpan tleft = TimeSpan.FromSeconds(sec);
            List<Move> moves = board.getMoves(board.CurrentColor);
            int a0 = awful;
            int v = -100000;
            DateTime start = DateTime.Now;
            Board tmpBoard;
            foreach (Move m in moves) {
                if (DateTime.Now - start > tleft)
                    break;
                tmpBoard = new Board(board);
                if (tmpBoard.makeMove(m)) {
                    result = AI.negaMaxNodoUndo(tmpBoard, depth - 1, -best, -a0, (tleft - (DateTime.Now - start)).TotalSeconds);
                    v = Math.Max(v, -result);
                    a0 = Math.Max(a0, v);
                    if (v >= best) {
                        best = v;
                        break;
                    }
                }

            }
            TTableEntry tt = new TTableEntry(board.Hash, awful, best, v, depth);
            table.store(tt);
            return v;
        }