int score;           //剪枝分数
        /// <summary>
        ///开局加载方法
        /// </summary>
        public void Load()
        {
            ChessLoad.Load();
            //反射获取程序集内容
            rule         = ChessLoad.rule;
            SelectButton = new Button();
            depth        = ChessLoad.Depth;
            score        = ChessLoad.limit_Score;
            int chess_style; Grid gd; string img;

            foreach (int poistion in ChessLoad.DicMap.Keys)
            {
                ImageBrush berriesBrush = new ImageBrush();
                Button     bt           = new Button();
                chess_style = Convert.ToInt32(ChessLoad.DicMap[poistion]);
                img         = ChessLoad.DicImg[chess_style];
                berriesBrush.ImageSource =
                    new BitmapImage(
                        new Uri(img, UriKind.Relative)
                        );
                gd            = (Grid)this.GetType().GetField("po_" + poistion, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this);
                bt.Background = berriesBrush; bt.HorizontalAlignment = HorizontalAlignment.Left; bt.VerticalAlignment = VerticalAlignment.Top;
                bt.Height     = 65; bt.Width = 65; bt.Uid = chess_style.ToString(); bt.Name = "po_" + poistion;
                bt.Click     += bt_Click;
                gd.Children.Add(bt);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 装载最初棋盘和棋子对应图片
        /// </summary>
        public static void  Load()
        {
            same_action_state = new Queue <Struct_Simple_State>(2);
            //加载棋盘规则辅助数组
            //相
            arr_bishop_black = new int[7] {
                54, 84, 118, 88, 58, 92, 122
            };
            arr_bishop_red = new int[7] {
                198, 164, 134, 168, 202, 172, 138
            };
            //士
            arr_guard_black = new int[5] {
                55, 57, 72, 87, 89
            };
            arr_guard_red = new int[5] {
                167, 169, 184, 199, 201
            };
            //帅
            arr_king_black = new int[9] {
                55, 56, 57, 71, 72, 73, 87, 88, 89
            };
            arr_king_red = new int[9] {
                199, 200, 201, 183, 184, 185, 167, 168, 169
            };
            black_king = 56;
            red_king   = 200;
            //辅助数组加载棋盘
            Auxiliary_array = new int[256];
            DicImg          = new Dictionary <int, string>();
            XmlDocument doc = new XmlDocument();

            doc.Load("ChessImg.xml");
            int         index = 0; string url;
            XmlElement  rootElem = doc.DocumentElement;
            XmlNodeList Nodes    = rootElem.GetElementsByTagName("id_img");

            foreach (XmlNode node in Nodes)
            {
                index = Convert.ToInt32(((XmlElement)node).GetAttribute("id"));
                url   = ((XmlElement)node).GetAttribute("img");
                dicImg.Add(index, url);
            }
            dicMap = new Dictionary <int, string>();
            doc    = new XmlDocument();
            //加载开局信息
            doc.Load("Manual.xml");
            rootElem = doc.DocumentElement;
            diPiece  = new Dictionary <int, int>();
            Nodes    = rootElem.GetElementsByTagName("position");
            foreach (XmlNode node in Nodes)
            {
                index = Convert.ToInt32(((XmlElement)node).GetAttribute("id"));
                url   = ((XmlElement)node).GetAttribute("value");
                Auxiliary_array[index] = Convert.ToInt32(url);
                dicMap.Add(index, url);
                //加载棋子信息

                diPiece.Add(index, Convert.ToInt32(url));
            }
            diScore = new Dictionary <int, int>();
            doc     = new XmlDocument();
            //加载得分部分
            doc.Load("Score.xml");
            rootElem = doc.DocumentElement;
            Nodes    = rootElem.GetElementsByTagName("evaluate");
            foreach (XmlNode node in Nodes)
            {
                diScore.Add(Convert.ToInt32(((XmlElement)node).GetAttribute("id")), Convert.ToInt32(((XmlElement)node).GetAttribute("score")));
            }
            //兵进位辅助得分
            //红色
            doc.Load("Score.xml");
            Nodes      = rootElem.GetElementsByTagName("pawn_red");
            diPawn_Red = new Dictionary <int, int>();
            foreach (XmlNode node in Nodes)
            {
                diPawn_Red.Add(Convert.ToInt32(((XmlElement)node).GetAttribute("position")), Convert.ToInt32(((XmlElement)node).GetAttribute("score")) * 20);
            }
            //黑色
            Nodes        = rootElem.GetElementsByTagName("pawn_black");
            diPawn_Black = new Dictionary <int, int>();
            foreach (XmlNode node in Nodes)
            {
                diPawn_Black.Add(Convert.ToInt32(((XmlElement)node).GetAttribute("position")), Convert.ToInt32(((XmlElement)node).GetAttribute("score")) * 20);
            }
            //规则类加载
            string IRule_type = ConfigurationManager.ConnectionStrings["IRule"].ConnectionString;
            Type   type       = Type.GetType(IRule_type);

            rule = (Abstract_Rule)Activator.CreateInstance(type);
            //剪枝树限制
            depth       = Convert.ToInt32(ConfigurationManager.ConnectionStrings["depth"].ConnectionString);
            limit_score = Convert.ToInt32(ConfigurationManager.ConnectionStrings["score"].ConnectionString);
        }