Ejemplo n.º 1
0
        protected int MaxValue(GameState state, AlphaBeta ab)
        {
            int v = Int32.MinValue;

            if (this.TerminalTest(state))
            {
                return(this.ComputeUtility(state));
            }
            else
            {
                var successorList = this.GetSuccessorStates(state);
                for (var i = 0; i < successorList.Count; i++)
                {
                    var successor = (GameState)successorList[i];
                    var minimumValueOfSuccessor = this.MinValue(successor, ab.Copy());
                    if (minimumValueOfSuccessor > v)
                    {
                        v             = minimumValueOfSuccessor;
                        state["next"] = successor;
                    }
                    if (v >= ab.Beta)
                    {
                        // System.out.println("pruning from max");
                        return(v);
                    }
                    ab.Alpha = Util.Util.Max(ab.Alpha, v);
                }
                return(v);
            }
        }
Ejemplo n.º 2
0
        public int MinValue(GameState state, AlphaBeta ab)
        {
            var v = Int32.MaxValue;

            if (this.TerminalTest(state))
            {
                return(this.ComputeUtility(state));
            }
            else
            {
                var successorList = this.GetSuccessorStates(state);
                foreach (var successor in successorList)
                {
                    var maximumValueOfSuccessor = this.MaxValue(successor, ab.Copy());
                    if (maximumValueOfSuccessor < v)
                    {
                        v             = maximumValueOfSuccessor;
                        state["next"] = successor;
                    }
                    if (v <= ab.Alpha)
                    {
                        // System.out.println("pruning from min");
                        return(v);
                    }
                    ab.Beta = Util.Util.Min(ab.Beta, v);
                }
                return(v);
            }
        }