Exemple #1
0
        }//public

        #endregion

        #region 2 返回点(m,n)形成双方的八方图案
        /// <summary>
        /// 返回点(m,n)形成双方的八方图案
        /// </summary>
        /// <param name="m">位置 X</param>
        /// <param name="n">位置 Y</param>
        /// <param name="arrchessboard">位置(M,N)的权值</param>
        /// <returns>点(m,n)的权植</returns>
        private string ReckonPointState(int m, int n, int[,] arrchessboard)
        {
            string strState = string.Empty;

            //如果该位置下我方的子
            if (Const.FirstPlayer == Player.Computer)
            {
                arrchessboard[m, n] = 1;//我方黑子
            }
            else
            {
                arrchessboard[m, n] = 2;//我方白子
            }
            //表示获取m,n点正东正西方向(X轴的方向)的连子个数;
            strState += ChessRule.strTheEastNorthWestSouthStr(m, n, arrchessboard) + ",";
            strState += ChessRule.strTheEastWestStr(m, n, arrchessboard) + ",";
            strState += ChessRule.strTheSouthNorthStr(m, n, arrchessboard) + ",";
            strState += ChessRule.strTheWestNorthEastSouthStr(m, n, arrchessboard) + ",";
            //如果该位置下对方的子
            if (Const.FirstPlayer == Player.Computer)
            {
                arrchessboard[m, n] = 2;//对方白子
            }
            else
            {
                arrchessboard[m, n] = 1;//对方黑子
            }
            strState           += ChessRule.strTheEastNorthWestSouthStr(m, n, arrchessboard) + ",";
            strState           += ChessRule.strTheEastWestStr(m, n, arrchessboard) + ",";
            strState           += ChessRule.strTheSouthNorthStr(m, n, arrchessboard) + ",";
            strState           += ChessRule.strTheWestNorthEastSouthStr(m, n, arrchessboard);
            arrchessboard[m, n] = 0;//0表示此处无子//数组是引用传递,探测完后恢复到默认值
            return(strState);
        }
Exemple #2
0
        }//public

        #endregion

        #region  计算点(m,n)的权植,计算后恢复点(x,y)为无棋状态  private int ReckonPointQZ(int m, int n, int[,] arrchessboard)
        /// <summary>
        /// 计算点(m,n)的权植,计算后恢复点(x,y)为无棋状态
        /// </summary>
        /// <param name="m">位置 X</param>
        /// <param name="n">位置 Y</param>
        /// <param name="arrchessboard">位置(M,N)的权值</param>
        /// <returns>点(m,n)的权植</returns>
        private double ReckonPointQZ(int m, int n, int[,] arrchessboard)
        {
            double qz = 0;

            //如果该位置下我方的子
            if (Const.FirstPlayer == Player.Computer)
            {
                arrchessboard[m, n] = 1;//我方黑子
            }
            else
            {
                arrchessboard[m, n] = 2;//我方白子
            }
            //表示获取m,n点正东正西方向(X轴的方向)的连子个数;
            qz += ChessRule.TheEastNorthWestSouth(m, n, arrchessboard, true);
            qz += ChessRule.TheEastWest(m, n, arrchessboard, true);
            qz += ChessRule.TheSouthNorth(m, n, arrchessboard, true);
            qz += ChessRule.TheWestNorthEastSouth(m, n, arrchessboard, true);

            //如果该位置下对方的子
            if (Const.FirstPlayer == Player.Computer)
            {
                arrchessboard[m, n] = 2;//对方白子
            }
            else
            {
                arrchessboard[m, n] = 1;//对方黑子
            }
            qz += ChessRule.TheEastNorthWestSouth(m, n, arrchessboard, false);
            qz += ChessRule.TheEastWest(m, n, arrchessboard, false);
            qz += ChessRule.TheSouthNorth(m, n, arrchessboard, false);
            qz += ChessRule.TheWestNorthEastSouth(m, n, arrchessboard, false);
            arrchessboard[m, n] = 0;//0表示此处无子//数组是引用传递,探测完后恢复到默认值
            return(qz);
        }
Exemple #3
0
 /// <summary>
 /// 人下棋
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public void ManPlayChess(int m, int n, bool displaystep, Graphics mGraphics)
 {
     if (!ChessRule.IsExistChess(m, n, arrchessboard))
     {
         PlayChess(m, n, displaystep, mGraphics);
     }
     if (Const.bGameOver)
     {
         return;
     }
 }
Exemple #4
0
        /// <summary>
        /// 当前棋盘的状态,形成五连已分胜负
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <param name="arrchessboard"></param>
        /// <returns></returns>
        public static CurrChessBoardState Result(int m, int n, int[,] arrchessboard)
        {//(m,n)点已经下棋了m,n点四个方向的连子数,依次正东正西,正南正北方,西北东南,西南东北
            string strTemp = string.Empty;

            //A
            strTemp = ChessRule.strTheEastWest(m, n, arrchessboard);
            if (arrchessboard[m, n] == 1 && strTemp.IndexOf(Const.S1_FiveLink) > -1)
            {
                return(CurrChessBoardState.GameOver);
            }
            else if (arrchessboard[m, n] == 2 && strTemp.IndexOf(Const.S2_FiveLink) > -1)
            {
                return(CurrChessBoardState.GameOver);
            }
            //B
            strTemp = ChessRule.strTheSouthNorth(m, n, arrchessboard);
            if (arrchessboard[m, n] == 1 && strTemp.IndexOf(Const.S1_FiveLink) > -1)
            {
                return(CurrChessBoardState.GameOver);
            }
            else if (arrchessboard[m, n] == 2 && strTemp.IndexOf(Const.S2_FiveLink) > -1)
            {
                return(CurrChessBoardState.GameOver);
            }
            //C
            strTemp = ChessRule.strTheEastNorthWestSouth(m, n, arrchessboard);
            if (arrchessboard[m, n] == 1 && strTemp.IndexOf(Const.S1_FiveLink) > -1)
            {
                return(CurrChessBoardState.GameOver);
            }
            else if (arrchessboard[m, n] == 2 && strTemp.IndexOf(Const.S2_FiveLink) > -1)
            {
                return(CurrChessBoardState.GameOver);
            }
            //D
            strTemp = ChessRule.strTheWestNorthEastSouth(m, n, arrchessboard);
            if (arrchessboard[m, n] == 1 && strTemp.IndexOf(Const.S1_FiveLink) > -1)
            {
                return(CurrChessBoardState.GameOver);
            }
            else if (arrchessboard[m, n] == 2 && strTemp.IndexOf(Const.S2_FiveLink) > -1)
            {
                return(CurrChessBoardState.GameOver);
            }

            return(CheckTie(arrchessboard));
        }
Exemple #5
0
        /// <summary>
        /// 当前棋子(m,n)落下,是已分胜负还是继续对局 (确定位置后,人和电脑是一样的下棋)
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        private void PlayChess(int m, int n, bool displaystep, Graphics mGraphics)
        {
            if (Const.bGameOver)
            {
                return;
            }
            int lm = -1, ln = -1;               //上一落子点

            if ((CurrChessColor == ChessColor.Black))
            {//记录下棋情况和历史记录
                arrchessboard[m, n] = 1;
                mStarckHistory.Push("● " + m.ToString() + "," + n.ToString());
            }
            else
            {
                arrchessboard[m, n] = 2;
                mStarckHistory.Push("○ " + m.ToString() + "," + n.ToString());
            }
            //先记录再分析最后下棋位置
            if (mStarckHistory.Count > 0)
            {//分解最后下棋位置
                string   lstr = mStarckHistory.Peek().ToString().Replace("● ", string.Empty).Replace("○ ", string.Empty);
                string[] arr  = lstr.Split(',');
                lm = Convert.ToInt32(arr[0]);
                ln = Convert.ToInt32(arr[1]);
            }
            //判断结果返回结果(0:胜利  1:平局   2:继续)
            Const.iPlayedChessCount++;
            ArrayStep[m, n] = Const.iPlayedChessCount;

            #region 更新虚构棋盘大小
            Const.Xmax = m + Const.ChessBoardCellCount > Const.Xmax ? m + Const.ChessBoardCellCount : Const.Xmax;
            Const.Xmax = Const.Xmax > 14 ? 14 : Const.Xmax;

            Const.Xmin = m - Const.ChessBoardCellCount < Const.Xmin ? m - Const.ChessBoardCellCount : Const.Xmin;
            Const.Xmin = Const.Xmin < 0 ? 0 : Const.Xmin;

            Const.Ymax = n + Const.ChessBoardCellCount > Const.Ymax ? n + Const.ChessBoardCellCount : Const.Ymax;
            Const.Ymax = Const.Ymax > 14 ? 14 : Const.Ymax;

            Const.Ymin = n - Const.ChessBoardCellCount < Const.Ymin ? n - Const.ChessBoardCellCount : Const.Ymin;
            Const.Ymin = Const.Ymin < 0 ? 0 : Const.Ymin;
            #endregion
            //"1黑棋胜利!"  "2白棋胜利!" "3平局!"
            Const.Result = ChessRule.Result(m, n, arrchessboard);
            if (Const.Result == CurrChessBoardState.ContinuePlayChess)
            {
                if (CurrChessColor == ChessColor.Black)
                {
                    CurrChessColor = ChessColor.White;
                }
                else
                {
                    CurrChessColor = ChessColor.Black;
                }
            }
            else
            {
                switch (Const.Result)
                {
                case CurrChessBoardState.GameOver:
                    if ((CurrChessColor == ChessColor.Black))
                    {
                        Const.GameOverResult = GameResult.BlackVictory;
                    }
                    else
                    {
                        Const.GameOverResult = GameResult.WhiteVictory;
                    }

                    if (CurrChessColor == ChessColor.Black)
                    {
                        CurrChessColor = ChessColor.White;
                    }
                    else
                    {
                        CurrChessColor = ChessColor.Black;
                    }

                    Const.Result = CurrChessBoardState.None;
                    break;

                case CurrChessBoardState.Dogfall:
                    Const.GameOverResult = GameResult.Nogfall;

                    if (CurrChessColor == ChessColor.Black)
                    {
                        CurrChessColor = ChessColor.White;
                    }
                    else
                    {
                        CurrChessColor = ChessColor.Black;
                    }

                    Const.Result = CurrChessBoardState.None;
                    break;
                }
                GameOverEventArgs game = new GameOverEventArgs();
                game.Result         = Const.Result;
                game.ChessColorFlag = CurrChessColor;
                this.OnGameOver(null, game);
                //重新开始!
                new SoundPlayer(Const.Runpath() + "Sound\\GameOver.wav").Play();
                Const.bGameOver = true;
            }
        }