예제 #1
0
        private AlphaBetaResult AlphaBeta(BoardState state, int alpha, int beta, GameState parent)
        {
            var result         = new AlphaBetaResult(state.StartEstimate, alpha, beta);
            var estimatedCells = EstimateCells(state);

            //double enumeration doesn't happen - we parallelize only non-terminal states
            if (state.AllowParallelize(estimatedCells) && !AnalyzeModeOn)
            {
                Parallel.ForEach(estimatedCells, (estimatedCell, parallelLoopState) =>
                {
                    if (ProcessCell(state, parent, estimatedCell, result))
                    {
                        parallelLoopState.Stop();
                    }
                });
            }
            else
            {
                foreach (var estimatedCell in estimatedCells)
                {
                    if (ProcessCell(state, parent, estimatedCell, result))
                    {
                        break;
                    }
                }
            }
            return(result);
        }