⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.htm

📁 中国象棋人工智能
💻 HTM
📖 第 1 页 / 共 5 页
字号:

    </script>

</body>
</html>
using System;
using System.Data;

using System.IO;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI;

using System.Collections.Generic;
namespace SuperDullWolfChess
{
    public class BasePage : System.Web.UI.Page
    {
        public BasePage()
        {
        }

        protected override void OnPreInit(EventArgs e)
        {

            if (Convert.ToInt32(HttpContext.Current.Request["ISAJAXREQUEST"]) == 1)
            {
                ExecuteAjaxRequest(HttpContext.Current.Request["AJAXREQUESTFUNNAME"], HttpContext.Current);
            }

 

            base.OnPreInit(e);
        }

 


        public void ExecuteAjaxRequest(string function, HttpContext context)
        {
            Response.Clear();

            int formFieldCount = context.Request.Form.Count;

            object[] arguments;

            if (formFieldCount > 0)
                arguments = new object[formFieldCount];
            else
                arguments = null;

            Type cls = this.GetType().BaseType;

            MethodInfo methodInfo = cls.GetMethod(function, BindingFlags.Public | BindingFlags.Static);

            if (methodInfo == null)
            {
                cls = this.GetType().BaseType.BaseType;

                methodInfo = cls.GetMethod(function, BindingFlags.Public | BindingFlags.Static);
            }

            ParameterInfo[] pars = methodInfo.GetParameters();

            for (int i = 0; i < formFieldCount; i++)
            {
                switch (pars[i].ParameterType.FullName)
                {
                    case "System.Int32":
                        arguments[i] = Convert.ToInt32(context.Request.Form[i]);
                        break;
                    case "System.Decimal":
                        arguments[i] = Convert.ToDecimal(context.Request.Form[i]);
                        break;
                    case "System.String":
                        arguments[i] = context.Request.Form[i].ToString();
                        break;
                    default:
                        arguments[i] = context.Request.Form[i].ToString();
                        break;
                }
            }

            //禁止使用.ToString()进行转换
            string response = (string)cls.InvokeMember(function,
                BindingFlags.Default | BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public,
                null, null, arguments);

            Response.Write(response);

            Response.End();
        }


        /// <summary>
        /// 读取根目录路径
        /// </summary>
        public string ApplicationRoot
        {
            get
            {
                return HttpContext.Current.Request.ApplicationPath;
            }
        }
        protected string description = string.Empty;

        protected string keywords = string.Empty;

 

    }

}
using System;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Diagnostics;
namespace SuperDullWolfChess
{
    public class Chess
    {
        public Chess(string name)
        { }
        public string Name;
        public int X;
        public int Y;
    }
    public partial class _Default : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

 

        }

        public static string isDead(string fen)
        {
            //判断是否可以将死对方,车马炮兵将5种可能,因为将同车,故4种可能。
            //rnbak1bnr/4a4/4c4/p1p3p1C/4c4/9/P1P3P1P/7C1/9/RNBAKABNR
            //rnbak1bnr/4a4/4c4/p1p3p1C/4c4/9/P1P3P1P/7C1/9/RNBAKABNR
            string[] Arr1 = fen.Split(@"/".ToCharArray());
            string[] Arr2 = new string[Arr1.Length];

            for (int y = 0; y < Arr1.Length; y++)
            {
                string tempStr = "";
                for (int x = 0; x < Arr1[y].Length; x++)
                {
                    char currentChar = Arr1[y].ToCharArray()[x];
                    int ascii = (int)(currentChar);

                    if (ascii < 58 && ascii > 48)
                    {
                        //1-9的数字
                        tempStr += makeString(Convert.ToInt32(currentChar.ToString()));
                    }
                    else
                    {
                        tempStr += currentChar;
                    }

                }
                Arr2[y] = tempStr;
            }
            //车马炮兵4种可能
            List<Chess> Listr = new List<Chess>();
            List<Chess> Listn = new List<Chess>();
            List<Chess> Listc = new List<Chess>();
            List<Chess> Listp = new List<Chess>();
            Chess cheesK = new Chess("K");
            string[,] Board = new string[9, 10];
            for (int y = 0; y < Arr2.Length; y++)
            {
                for (int x = 0; x < Arr2[y].Length; x++)
                {
                    string currentStr = Arr2[y].Substring(x, 1);
                    Board[x, 9 - y] = currentStr;
                    if (currentStr != "0")
                    {
                        Chess C = new Chess(currentStr);
                        C.X = x + 1;
                        C.Y = 9 - y;

                        switch (currentStr)
                        {
                            case "r": Listr.Add(C);
                                break;
                            case "k": Listr.Add(C);
                                break;
                            case "n": Listn.Add(C);
                                break;
                            case "c": Listc.Add(C);
                                break;
                            case "p": Listp.Add(C);
                                break;

                            case "K":
                                cheesK = C;
                                break;
                        }

                    }
                    else
                    {
                        Board[x, 9 - y] = "";
                    }
                }
            }
            Chess currentChess;
            string bestMove = "";
            //自此得到了棋盘和棋子状态
            //检查车和笑面杀
            for (int i = 0; i < Listr.Count; i++)
            {
                //面积为0
                currentChess = Listr[i];
                int x1 = currentChess.X;
                int y1 = currentChess.Y;
                int x2 = cheesK.X;
                int y2 = cheesK.Y;
                if (ruleChe(x1, y1, x2, y2, Board))
                {
                    bestMove = getBestmove(currentChess, cheesK);
                    return bestMove;
                }

            }
            //检查马
            for (int i = 0; i < Listn.Count; i++)
            {
                currentChess = Listn[i];
                int x1 = currentChess.X;
                int y1 = currentChess.Y;
                int x2 = cheesK.X;
                int y2 = cheesK.Y;
                //面积为2
                if (ruleMa(x1, y1, x2, y2, Board))
                {
                    //         rtn=true;
                    bestMove = getBestmove(currentChess, cheesK);
                    return bestMove;

                }

            }
            //检查炮
            for (int i = 0; i < Listc.Count; i++)
            {
                currentChess = Listc[i];
                int x1 = currentChess.X;
                int y1 = currentChess.Y;
                int x2 = cheesK.X;
                int y2 = cheesK.Y;
                //面积为2
                if (rulePao(x1, y1, x2, y2, Board))
                {
                    //         rtn=true;
                    bestMove = getBestmove(currentChess, cheesK);
                    return bestMove;

                }

            }
            //检查兵
            for (int i = 0; i < Listc.Count; i++)
            {
                currentChess = Listc[i];
                int x1 = currentChess.X;
                int y1 = currentChess.Y;
                int x2 = cheesK.X;
                int y2 = cheesK.Y;
                //面积为2
                if (ruleBing(x1, y1, x2, y2))
                {
                    //         rtn=true;
                    bestMove = getBestmove(currentChess, cheesK);
                    return bestMove;

                }

            }
            return "0000";
        }
        //兵的走法
        public static bool ruleBing(int x1, int y1, int x2, int y2)
        {
            bool rtn = false;
            //1,不能后退
            if (y1 <= y2)
            {
                //2,只走一格
                if (isSingle(x1, y1, x2, y2))
                {
                    //3,过河前竖走
                    if (y1 <= 5 && (!isX(x1, y1, x2, y2)))
                    {
                        rtn = true;
                    }
                    //4,过河后随便
                    if (y1 > 5)
                    {
                        rtn = true;
                    }

                }
            }
            return (rtn);
        }
        public static bool isSingle(int x1, int y1, int x2, int y2)
        {
            //是否某方向只动了一格
            bool rtn = false;
            //1,面积是0
            int area = getArea(x1, y1, x2, y2);
            if (area == 0)
            {
                //两面只能一格
                if (((!isX(x1, y1, x2, y2)) && Math.Abs(y1 - y2) == 1) || (isX(x1, y1, x2, y2) && Math.Abs(x1 - x2) == 1))
                {
                    rtn = true;
                }
            }
            return (rtn);
        }
        public static int getArea(int x1, int y1, int x2, int y2)
        {
            int rtn = 0;
            rtn = Math.Abs((x1 - x2) * (y1 - y2));
            return (rtn);
        }
        public static bool ruleMa(int x1, int y1, int x2, int y2, string[,] Board)
        {

            bool rtn = false;
            //1,面积是2
            var area = getArea(x1, y1, x2, y2);
            if (area == 2)
            {
                //2,长轴上无子getQ_xy(int x, int y, string[,] Board)
          

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -