示例#1
0
        private Struct_State Select_Score_Max(Dictionary <Guid, Struct_Simple_State> Di_select_node)
        {
            Struct_State struct_state = new Struct_State();

            Di_select_node.Remove(new Guid());
            int temp_value = int.MinValue;

            foreach (Guid key in Di_select_node.Keys)
            {
                if (temp_value < Di_select_node[key].score)
                {
                    struct_state.id = key;
                    temp_value      = Di_select_node[key].score;
                }
            }
            struct_state.origin_position = Di_select_node[struct_state.id].origin_position;
            struct_state.category        = Di_select_node[struct_state.id].category;
            struct_state.parent_id       = Di_select_node[struct_state.id].parent_id;
            struct_state.score           = Di_select_node[struct_state.id].score;
            struct_state.target_position = Di_select_node[struct_state.id].target_position;
            if (Di_select_node[struct_state.id].category < 0)
            {
                struct_state.isRed = false;
            }
            else
            {
                struct_state.isRed = true;
            }
            return(struct_state);
        }
示例#2
0
 /// <summary>
 /// 需要修改的孩子节点
 /// </summary>
 /// <param name="new_state">修改后的状态</param>
 /// <param name="alter_tree">需要修改的节点</param>
 /// <returns></returns>
 public bool AlterChild(Struct_State new_state, ChessTree alter_tree)
 {
     if (new_state.category != 0)
     {
         alter_tree.State = new_state;//更新节点信息
         return(true);
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        /// 棋力评估函数
        /// </summary>
        /// <param name="state">棋子状态</param>
        /// <param name="di_position_score">引用数据字典 棋局状态ID-棋子简单状态信息</param>
        public void Design(Struct_State state, ref Dictionary <Guid, Struct_Simple_State> di_position_score)
        {
            int category = state.category;
            //记录当前分数字段
            int temp_score = 0;
            //Dictionary<int, int> di_position_score = new Dictionary<int, int>();
            //规则结构信息
            Str_ChessInfo chessinfo = new Str_ChessInfo();
            //简单记录结构信息,用于记录数据字典
            Struct_Simple_State simple_state = new Struct_Simple_State();

            //黑方走棋
            if (state.isRed == false)
            {
                //边界判断值,在边界内除16余数在4-12之间
                int judge_int = 0;
                for (int i = 52; i <= 204; i++)
                {
                    judge_int = i % size;
                    if (state.array_chess[i] >= 0 && judge_int >= 4 && judge_int <= 12)
                    {
                        chessinfo.category        = category;
                        chessinfo.origin_position = state.origin_position;
                        chessinfo.target          = i;
                        if (ChessLoad.rule.Rule_Judge(ref state.array_chess, chessinfo))
                        {
                            if (Math.Abs(chessinfo.category) >= 12 && Math.Abs(chessinfo.category) <= 16)
                            {
                                temp_score = ChessLoad.DiPawn_Black[chessinfo.target];
                            }

                            if (state.array_chess[chessinfo.target] > 0)
                            {
                                temp_score = ChessLoad.DiScore[state.array_chess[chessinfo.target]];
                            }

                            if (temp_score >= cut_size_score)
                            {
                                simple_state.target_position = chessinfo.target;
                                simple_state.score           = temp_score;
                                simple_state.origin_position = chessinfo.origin_position;
                                simple_state.id        = Guid.NewGuid();
                                simple_state.category  = chessinfo.category;
                                simple_state.parent_id = state.id;
                                di_position_score.Add(simple_state.id, simple_state);
                            }
                        }
                    }
                }
            }
            //红方走棋
            else
            {
                int judge_int = 0;
                for (int i = 52; i <= 204; i++)
                {
                    //if (state.array_chess[i] <= 0)
                    //{
                    judge_int = i % size;
                    if (state.array_chess[i] <= 0 && judge_int >= 4 && judge_int <= 12)
                    {
                        chessinfo.category        = category;
                        chessinfo.origin_position = state.origin_position;
                        chessinfo.target          = i;
                        if (ChessLoad.rule.Rule_Judge(ref state.array_chess, chessinfo))
                        {
                            if (Math.Abs(chessinfo.category) >= 12 && Math.Abs(chessinfo.category) <= 16)
                            {
                                temp_score = ChessLoad.DiPawn_Red[chessinfo.target];
                            }

                            if (state.array_chess[chessinfo.target] < 0)
                            {
                                temp_score = ChessLoad.DiScore[state.array_chess[chessinfo.target]];
                            }

                            if (temp_score >= cut_size_score)
                            {
                                simple_state.target_position = chessinfo.target;
                                simple_state.score           = temp_score;
                                simple_state.origin_position = chessinfo.origin_position;
                                simple_state.id        = Guid.NewGuid();
                                simple_state.category  = chessinfo.category;
                                simple_state.parent_id = state.id;
                                di_position_score.Add(simple_state.id, simple_state);
                            }
                        }
                    }
                }
            }
        }