Exemple #1
0
        private bool DownStone(StonePoint point)
        {
            #region 人机对弈,下子

            if (point.Type == StoneType.未落子)
            {
                return(false);
            }

            var arr = Chessboard.StonesArray;
            arr[(int)point.PointX, (int)point.PointY] = (int)point.Type;
            var jingShou = Rule.IsJinShou(arr, point.PointX, point.PointY);
            if (point.Type == StoneType.黑子 && jingShou == JinShou.双三禁手)
            {
                MessageBox.Show("黑子双三禁手!", "温馨提示", MessageBoxButtons.OK);
            }
            else if (point.Type == StoneType.黑子 && jingShou == JinShou.双四禁手)
            {
                MessageBox.Show("黑子双四禁手!", "温馨提示", MessageBoxButtons.OK);
            }
            else if (point.Type == StoneType.黑子 && jingShou == JinShou.长联禁手)
            {
                MessageBox.Show("黑子长联禁手!", "温馨提示", MessageBoxButtons.OK);
            }
            else
            {
                Chessboard.UpdateStones(point); //更新Stones
                stone.DrawStone(point);
                Common.MakeStoneSound();

                var txt = point.StepNum.ToString() + " " + point.Type.ToString() + " 横:" + point.PointXValue + " - " + "纵:" + point.PointYValue.Replace("No", "");
                ChessRecord.StackHistory.Push(txt); //StackHistory为了保存棋谱
                shower.DataSource = ChessRecord.StackHistory.ToArray();
                shower.Update();

                if (Rule.IsPing() && MessageBox.Show("平局!", "重新开始", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    Chessboard.Clear();
                    ChessRecord.StackHistory.Clear();
                    Draw();                                      //重绘清除落子
                    Start();                                     //开新一局
                }
                else if (Rule.IsWin(point.PointX, point.PointY)) //在该位置落子胜
                {
                    string txtStone = point.Type == StoneType.黑子 ? "黑子胜利" : "白子胜利";
                    if (MessageBox.Show(txtStone, "是否保存棋谱", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        ChessRecord.SaveQP();
                    }

                    Chessboard.Clear();
                    ChessRecord.StackHistory.Clear();
                    Draw();  //重绘清除落子
                    Start(); //开新一局
                }
                else
                {
                    return(true); //可以走下一步
                }
            }

            #endregion

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 计算落子位置的权重值
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <param name="arrchessboard"></param>
        /// <returns></returns>
        private int CheckQZ(int[,] arr, int m, int n)
        {
            //权重加入活和死的分别,活的表示两头没有落子即为活,两头只要有一头有子即为死,h表示活,s表示死
            int qz = 0;

            //我方获胜点 连成5个
            int w1 = 100000;
            //对方获胜点,连成5个
            int w2 = 50000;

            //4个
            int w3_h = 10000;
            int w3_s = 3000;
            int w4_h = 8000;
            int w4_s = 2000;

            //3个
            int w5_h = 1000;
            int w5_s = 500;
            int w6_h = 800;
            int w6_s = 300;

            //2个
            int w7_h = 100;
            int w7_s = 50;
            int w8_h = 80;
            int w8_s = 30;

            //黑子的禁手
            int w9 = -10000000;

            if (m == 7 && n == 7)
            {
                qz += 1;                   //最中间的位置
            }
            arr[m, n] = (int)Common.ComputerStoneType;
            var dict = Rule.GetDirect4Num(arr, m, n);

            foreach (var item in dict)
            {
                if (Math.Abs(item.LianziNum) == 5)
                {
                    qz += w1;
                }
                if (item.LianziNum == 4 && item.IsActive)
                {
                    qz += w3_h;
                }
                if (item.LianziNum == 4)
                {
                    qz += w3_s;
                }
                if (item.LianziNum == 3 && item.IsActive)
                {
                    qz += w5_h;
                }
                if (item.LianziNum == 3)
                {
                    qz += w5_s;
                }
                if (item.LianziNum == 2 && item.IsActive)
                {
                    qz += w7_h;
                }
                if (item.LianziNum == 2)
                {
                    qz += w7_s;
                }

                if (Common.ComputerStoneType == StoneType.黑子)
                {
                    if (Rule.IsJinShou(arr, m, n) != 0)
                    {
                        qz += w9;//黑子在判断是否禁手
                    }
                }
            }

            //如果该点下对方的子(对方相对电脑来说是人)
            arr[m, n] = Common.ComputerStoneType == StoneType.黑子 ?
                        (int)StoneType.白子 :
                        (int)StoneType.黑子;

            dict = Rule.GetDirect4Num(arr, m, n);
            foreach (var item in dict)
            {
                if (Math.Abs(item.LianziNum) == 5)
                {
                    qz += w2;
                }
                if (item.LianziNum == 4 && item.IsActive)
                {
                    qz += w4_h;
                }
                if (item.LianziNum == 4)
                {
                    qz += w4_s;
                }
                if (item.LianziNum == 3 && item.IsActive)
                {
                    qz += w6_h;
                }
                if (item.LianziNum == 3)
                {
                    qz += w6_s;
                }
                if (item.LianziNum == 2 && item.IsActive)
                {
                    qz += w8_h;
                }
                if (item.LianziNum == 2)
                {
                    qz += w8_s;
                }
            }

            return(qz);
        }