Ejemplo n.º 1
0
	/// <summary>
	/// 
	/// </summary>
	/// <param name="n"></param>
	/// <param name="min"></param>
	/// <param name="a"></param>
	/// <param name="b"></param>
	/// <returns></returns>
	private int minimaxAB( Node n,  bool min,  int a,int b) {

		int alpha = a;
		int beta = b;

		if (n.isLeaf()) {
			return n.value(this._player);
		}

        if (alpha > beta)
            return min ? beta : alpha;
		//Node child;
        //

		if (min) {
			foreach (var child in n.Successors(null)){
				 int val = minimaxAB(child, false, alpha, beta);
				if (val < beta) {
					beta = val;
				}
			}
			return beta;
		} else {
			foreach (var child in n.Successors(null)){
				 int val = minimaxAB(child, true, alpha, beta);
				if (val > alpha) {
					alpha = val;
				}
			}
			return alpha;
		}
	}
	// Implementation of mimimax with alpha-beta pruning.
	private int minimaxAB( Node n,  bool min,  int a,
			 int b) {

		int alpha = a;
		int beta = b;

		if (n.isLeaf()) {
			return n.value(this._player);
		}

		Node child;

		if (min) {
			while (((child = n.getChild()) != null) && !(alpha > beta)) {
				 int val = minimaxAB(child, false, alpha, beta);
				if (val < beta) {
					beta = val;
				}
			}
			return beta;
		} else {
			while (((child = n.getChild()) != null) && !(alpha > beta)) {
				 int val = minimaxAB(child, true, alpha, beta);
				if (val > alpha) {
					alpha = val;
				}
			}
			return alpha;
		}
	}
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="n"></param>
        /// <param name="min"></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        private int minimaxAB(Node n, bool min, int a, int b)
        {
            int alpha = a;
            int beta  = b;

            if (n.isLeaf())
            {
                return(n.value(this._player));
            }

            if (alpha > beta)
            {
                return(min ? beta : alpha);
            }
            //Node child;
            //

            if (min)
            {
                foreach (var child in n.Successors(null))
                {
                    int val = minimaxAB(child, false, alpha, beta);
                    if (val < beta)
                    {
                        beta = val;
                    }
                }
                return(beta);
            }
            else
            {
                foreach (var child in n.Successors(null))
                {
                    int val = minimaxAB(child, true, alpha, beta);
                    if (val > alpha)
                    {
                        alpha = val;
                    }
                }
                return(alpha);
            }
        }
        // Implementation of mimimax with alpha-beta pruning.
        private int minimaxAB(Node n, bool min, int a,
                              int b)
        {
            int alpha = a;
            int beta  = b;

            if (n.isLeaf())
            {
                return(n.value(this._player));
            }

            Node child;

            if (min)
            {
                while (((child = n.getChild()) != null) && !(alpha > beta))
                {
                    int val = minimaxAB(child, false, alpha, beta);
                    if (val < beta)
                    {
                        beta = val;
                    }
                }
                return(beta);
            }
            else
            {
                while (((child = n.getChild()) != null) && !(alpha > beta))
                {
                    int val = minimaxAB(child, true, alpha, beta);
                    if (val > alpha)
                    {
                        alpha = val;
                    }
                }
                return(alpha);
            }
        }