如何使用括号[i]调用决策树的深度,如数组 [英] How can call the depth of decision tree like the array using brackets [i]

查看:76
本文介绍了如何使用括号[i]调用决策树的深度,如数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在为我的项目设计一个国际象棋引擎而不是随机播放: http://www.youtube.com/watch?v=8EKKTMPFY8g [ ^ ]



i计划使用贪婪的MinMax算法,所以我首先开始编写数据结构



Hello everyone,
I am designing a chess engine for my project instead of playing random: http://www.youtube.com/watch?v=8EKKTMPFY8g[^]

i am planning to use greedy MinMax algorithm, so i first started with writing the data structure

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AI
{
    class Node
    {
        #region Constructor

        public Node(object data)
        {
            this.Data = data;
        }

        #endregion

        #region Properties

        private int _order;
        private object _data;
        private Node _parent;
        private List<Node> _childern = new List<Node>();

        public object Data
        {
            get { return _data; }
            set { _data = value; }
        }

        public Node Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }

        public List<Node> Children
        {
            get { return _childern; }
            set { _childern = value; }
        }

        public int Order
        {
            get { return _order; }
            set { _order = value; }
        }

        #endregion

        #region Methods

        public void AddChild(Node next_node)
        {
            next_node._order = this.Order + 1;
            next_node.Parent = this;
            this.Children.Add(next_node);
        }

        public void AddChild(object next_node_data)
        {
            Node next_node = new Node(next_node_data);
            AddChild(next_node);
        }

        #endregion
    }

    class Tree
    {
        #region Constructor

        public Tree(object root_data)
        {
            this.Root = new Node(root_data);
            this.Root.Order = 0;
            this.length = 1;
        }

        public Tree(Node root_node)
        {
            Root = root_node;
        }

        #endregion

        #region Properties

        private Node _root;
        private int _length;

        public Node Root
        {
            get { return _root; }
            set { _root = value; }
        }

        public int length
        {
            get { return _length; }
            set { _length = value; }
        }

        #endregion
    }
}





我有一个问题,一旦我对树进行了评估,并希望比较看哪个是最好的移动,怎么能回到一阶节点而没有使用递归方法,例如数组使用 [i] ,但 i 不是长度 i 树的深度



提前致谢,

z3ngew



I have a problem, once i have a evaluated the tree, and want to compare to see which is the best move, how can return to 1st order node without using a recursive method for example like array use [i] but i is no the length i is the depth if the tree

Thanks in advance,
z3ngew

推荐答案

由于你的节点有一个Parent属性,你可以向上移动,直到你到达订单为1.这样的东西。



Since your nodes have a Parent property you can just move up until you reach the one with order 1. Something like this.

Node primary = (currentNode.Order <= 1 ? currentNode : currentNode.Parent);
while (primary.Order > 1)
    primary = primary.Parent;


这篇关于如何使用括号[i]调用决策树的深度,如数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆