Exemple #1
0
        /// <summary>
        /// 悔棋按钮的处理事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.routeListBox.SelectedIndex < 0)
            {
                MessageBox.Show("未选择悔棋的棋步", "出错咯~");
                return;
            }

            if ((Conf.CurrentTurn == ChessType.BLACK && this.routeListBox.SelectedItem.ToString().Contains(ChessType.WHITE.ToString())) || (Conf.CurrentTurn == ChessType.WHITE && this.routeListBox.SelectedItem.ToString().Contains(ChessType.BLACK.ToString())))
            {
                MessageBox.Show("只可以选择自己的棋子进行悔棋", "出错咯~");
                return;
            }

            //删除历史记录
            ChessRule.RegretPoint(this.routeListBox.SelectedIndex);

            //删除显示的列表的值
            int index = this.routeListBox.SelectedIndex;

            for (int i = this.routeListBox.Items.Count - 1; i >= index; i--)
            {
                this.routeListBox.Items.RemoveAt(i);
            }

            //重新选中最后一步
            this.routeListBox.SelectedIndex = routeListBox.Items.Count - 1;
        }
Exemple #2
0
        /// <summary>
        /// 计算单子威力
        /// </summary>
        /// <param name="point"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private int SinglePower(Point point, ChessType type)
        {
            //如果己方为黑子
            if (AIType == ChessType.BLACK && AIType == type)
            {
                //判断禁手
                if (ChessRule.CheckAbort3_3())
                {
                    return(int.MinValue);
                }

                if (ChessRule.CheckAbort4_4())
                {
                    return(int.MinValue);
                }

                if (ChessRule.CheckAbortLong())
                {
                    return(int.MinValue);
                }
            }
            //判断是否为5连
            if (AIRule.CheckFiveARow(point, type))
            {
                return((type == AIType) ? 100 : -100);
            }

            //判断是否为活4
            if (AIRule.IsActive(point, 4, type))
            {
                return((type == AIType) ? 100 : -100);
            }

            //判断是否为单4
            if (AIRule.IsSingle(point, 4, type))
            {
                return((type == AIType) ? 90 : -90);
            }

            //判断是否为单3
            if (AIRule.IsSingle(point, 3, type))
            {
                return((type == AIType) ? 9 : -9);
            }

            //判断是否为活3
            if (AIRule.IsActive(point, 3, type))
            {
                return((type == AIType) ? 90 : -90);
            }
            int commonPower = AIRule.CommonPower(point, type);

            return((type == AIType) ? commonPower : (commonPower * -1));
        }
Exemple #3
0
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="text"></param>
        public void AddRecordToList(String text)
        {
            this.routeListBox.Items.Add(text);
            this.routeListBox.SelectedIndex = routeListBox.Items.Count - 1;

            //如果棋盘下满,则平局
            if (this.routeListBox.Items.Count >= 125)
            {
                ChessRule.WinPeace();
            }
        }
Exemple #4
0
        /// <summary>
        /// 判断某个点是否为活N
        /// </summary>
        /// <param name="point">点坐标</param>
        /// <param name="count">活几</param>
        /// <param name="type">棋子类型</param>
        /// <returns></returns>
        public static Boolean IsActive(Point point, int count, ChessType type)
        {
            if (ChessRule.checkDirectOnChessForActive(point, Direction.Down, type) + ChessRule.checkDirectOnChessForActive(point, Direction.UP, type) + 1 == count)
            {
                return(true);
            }
            if (ChessRule.checkDirectOnChessForActive(point, Direction.DownLeft, type) + ChessRule.checkDirectOnChessForActive(point, Direction.UpRight, type) + 1 == count)
            {
                return(true);
            }
            if (ChessRule.checkDirectOnChessForActive(point, Direction.DownRight, type) + ChessRule.checkDirectOnChessForActive(point, Direction.UpLeft, type) + 1 == count)
            {
                return(true);
            }
            if (ChessRule.checkDirectOnChessForActive(point, Direction.Left, type) + ChessRule.checkDirectOnChessForActive(point, Direction.Right, type) + 1 == count)
            {
                return(true);
            }

            return(false);
        }
Exemple #5
0
        /// <summary>
        /// 判断是否为5连
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public static Boolean CheckFiveARow(Point point, ChessType type)
        {
            if (ChessRule.CheckDirectOnChess(point, Direction.Down, type) + ChessRule.CheckDirectOnChess(point, Direction.UP, type) + 1 == 5)
            {
                return(true);
            }
            if (ChessRule.CheckDirectOnChess(point, Direction.DownLeft, type) + ChessRule.CheckDirectOnChess(point, Direction.UpRight, type) + 1 == 5)
            {
                return(true);
            }
            if (ChessRule.CheckDirectOnChess(point, Direction.DownRight, type) + ChessRule.CheckDirectOnChess(point, Direction.UpLeft, type) + 1 == 5)
            {
                return(true);
            }
            if (ChessRule.CheckDirectOnChess(point, Direction.Left, type) + ChessRule.CheckDirectOnChess(point, Direction.Right, type) + 1 == 5)
            {
                return(true);
            }

            return(false);
        }
Exemple #6
0
        /// <summary>
        /// 计算一个棋子的通用威力
        /// </summary>
        /// <param name="point"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static int CommonPower(Point point, ChessType type)
        {
            List <int> powerContainer = new List <int>();

            //计算棋子通用威力

            //单二
            if (checkDirectOnChessForSingle(point, Direction.UP, type) + 1 == 2)
            {
                powerContainer.Add(5);
            }
            if (checkDirectOnChessForSingle(point, Direction.UpLeft, type) + 1 == 2)
            {
                powerContainer.Add(5);
            }
            if (checkDirectOnChessForSingle(point, Direction.Left, type) + 1 == 2)
            {
                powerContainer.Add(5);
            }
            if (checkDirectOnChessForSingle(point, Direction.DownLeft, type) + 1 == 2)
            {
                powerContainer.Add(5);
            }
            if (checkDirectOnChessForSingle(point, Direction.Down, type) + 1 == 2)
            {
                powerContainer.Add(5);
            }
            if (checkDirectOnChessForSingle(point, Direction.DownRight, type) + 1 == 2)
            {
                powerContainer.Add(5);
            }
            if (checkDirectOnChessForSingle(point, Direction.Right, type) + 1 == 2)
            {
                powerContainer.Add(5);
            }
            if (checkDirectOnChessForSingle(point, Direction.UpRight, type) + 1 == 2)
            {
                powerContainer.Add(5);
            }

            //单一
            if (checkDirectOnChessForSingle(point, Direction.UP, type) + 1 == 1)
            {
                powerContainer.Add(1);
            }
            if (checkDirectOnChessForSingle(point, Direction.UpLeft, type) + 1 == 1)
            {
                powerContainer.Add(1);
            }
            if (checkDirectOnChessForSingle(point, Direction.Left, type) + 1 == 1)
            {
                powerContainer.Add(1);
            }
            if (checkDirectOnChessForSingle(point, Direction.DownLeft, type) + 1 == 1)
            {
                powerContainer.Add(1);
            }
            if (checkDirectOnChessForSingle(point, Direction.Down, type) + 1 == 1)
            {
                powerContainer.Add(1);
            }
            if (checkDirectOnChessForSingle(point, Direction.DownRight, type) + 1 == 1)
            {
                powerContainer.Add(1);
            }
            if (checkDirectOnChessForSingle(point, Direction.Right, type) + 1 == 1)
            {
                powerContainer.Add(1);
            }
            if (checkDirectOnChessForSingle(point, Direction.UpRight, type) + 1 == 1)
            {
                powerContainer.Add(1);
            }

            //活二
            if (ChessRule.checkDirectOnChessForActive(point, Direction.Down, type) + ChessRule.checkDirectOnChessForActive(point, Direction.UP, type) + 1 == 2)
            {
                powerContainer.Add(7);
            }
            if (ChessRule.checkDirectOnChessForActive(point, Direction.DownLeft, type) + ChessRule.checkDirectOnChessForActive(point, Direction.UpRight, type) + 1 == 2)
            {
                powerContainer.Add(7);
            }
            if (ChessRule.checkDirectOnChessForActive(point, Direction.DownRight, type) + ChessRule.checkDirectOnChessForActive(point, Direction.UpLeft, type) + 1 == 2)
            {
                powerContainer.Add(7);
            }
            if (ChessRule.checkDirectOnChessForActive(point, Direction.Left, type) + ChessRule.checkDirectOnChessForActive(point, Direction.Right, type) + 1 == 2)
            {
                powerContainer.Add(7);
            }

            //活一
            if (ChessRule.checkDirectOnChessForActive(point, Direction.Down, type) + ChessRule.checkDirectOnChessForActive(point, Direction.UP, type) + 1 == 1)
            {
                powerContainer.Add(3);
            }
            if (ChessRule.checkDirectOnChessForActive(point, Direction.DownLeft, type) + ChessRule.checkDirectOnChessForActive(point, Direction.UpRight, type) + 1 == 1)
            {
                powerContainer.Add(3);
            }
            if (ChessRule.checkDirectOnChessForActive(point, Direction.DownRight, type) + ChessRule.checkDirectOnChessForActive(point, Direction.UpLeft, type) + 1 == 1)
            {
                powerContainer.Add(3);
            }
            if (ChessRule.checkDirectOnChessForActive(point, Direction.Left, type) + ChessRule.checkDirectOnChessForActive(point, Direction.Right, type) + 1 == 1)
            {
                powerContainer.Add(3);
            }

            //排序
            powerContainer.Sort();

            //返回最大的两个值和
            return(powerContainer[powerContainer.Count - 2] + powerContainer[powerContainer.Count - 1]);
        }