大家好,经过一段时间学习,网络军棋(两人陆战棋)终于基本完成了
想对工兵的走法进行修改。目前工兵和其它一样,只能直行,不能转弯。想让工兵可以转弯不知如何实现,用什么算法。好长时间没有一个思路。以下是现在部分代码,
主要是 T_Juge(int old_x, int old_y, int x, int y)//铁道线可以走否,如何修改才能达到目的呢??
 private bool Go_Juge(int old_x, int old_y, int x, int y)//判断走棋的位置是否适当
        {
            label1.Text = old_x.ToString() + "old_x:old_y" + old_y.ToString() + ":" + Map[old_x, old_y].ToString();
            label2.Text = x.ToString() + "x:y" + y.ToString() + Map[x, y].ToString();
            //是否是棋子区域
        
            if((x>11)||(y>5))
            return false;
            //目标位置和原位置是自己方的棋子 
            if ((IsmyChess(old_x,old_y)==false )||(IsmyChess(x, y) == true )) { return false ; }
          
            //到行营,行营是否有子
            if (Is_Home(x, y) && Map[x, y] != 101) {  return false; }            //如“士”斜线从行营中出来**********
            if (((Is_Home(old_x, old_y) && Map[x, y] == 101 && Math.Abs(x - old_x) * Math.Abs(y - old_y) == 1)) || ((Is_Home(old_x, old_y) && (IsmyChess(x, y) == false) && Math.Abs(x - old_x) * Math.Abs(y - old_y) == 1))) { return true; }            //如“士”斜线走入行营************
            if (Is_Home(x, y) && Map[x, y] == 101 && Math.Abs(x - old_x) * Math.Abs(y - old_y) == 1) {  return true; }
            //中间铁路线只有一个。
            if (((old_x == 5) && (old_y == 1) && (x == 6) && (y == 1)) || ((old_x == 6) && (old_y == 1) && (x == 5) && (y == 1)) || ((old_x == 6) && (old_y == 3) && (x == 5) && (y == 3)) || ((old_x == 5) && (old_y == 3) && (x == 6) && (y == 3))) { return false; }
            //移动一步
            if ((Math.Abs(x - old_x) == 1 && y == old_y || Math.Abs(y - old_y) == 1 && x == old_x) ) { return true; }
            //铁道线
            if (T_Juge(old_x, old_y, x, y)) 
            {
               
                return true;
            }
            
            
            return false;        }
        private bool T_Juge(int old_x, int old_y, int x, int y)//铁道线可以走否
        {
            //长垂直铁路线与弯道铁道线
            if ((old_x ==x)&&(old_x== 1))
            {
                if (y < 5 && y >= 0 && VLine_Juge(old_y, y, x)) { MessageBox.Show("上底线HLine_Juge:" + VLine_Juge(old_y, y, x).ToString()); return true; }//上底线
            }            if ((old_x ==x)&&(old_x== 5))
            {
                if (y < 5 && y >= 0 && VLine_Juge(old_y, y, x)) { MessageBox.Show("中上线HLine_Juge:" + VLine_Juge(old_y, y, x).ToString()); return true; }//中上线
            }
            if ((old_x ==x)&&(old_x== 6))
            {
                if (y < 5 && y >= 0 && VLine_Juge(old_y, y, x)) { MessageBox.Show("中下线HLine_Juge:" + VLine_Juge(old_y, y, x).ToString()); return true; }//中下线
            }
            if ((old_x == x) && (old_x ==10))
            {
                if (y < 5 && y >= 0 && VLine_Juge(old_y, y, x)) { MessageBox.Show("下底线HLine_Juge:" + VLine_Juge(old_y, y, x).ToString()); return true; }//下底线
            }
            if ((old_y == y) && (old_y == 0))
            {            
                if ((x < 11) && (x >= 1) && ((old_x != 0) || (old_x != 11)) && HLine_Juge(old_x, x, y)) { MessageBox.Show("左线VLine_Juge:" + HLine_Juge(old_y, y, x).ToString()); return true; }//左线            }
            if ((old_y == y) && (old_y == 4))
            {
                if ((x < 11) && (x >= 1) && ((old_x != 0) || (old_x != 11)) && HLine_Juge(old_x, x, y)) { MessageBox.Show("右线VLine_Juge:" + HLine_Juge(old_y, y, x).ToString()); return true; }//右线
            }
            return false;
        }
        //垂直方向判断是否有别的棋子挡路
        private bool VLine_Juge(int m, int n, int x)
        {
            int t = Math.Max(m, n);
            m = Math.Min(m, n);
            n = t;
            for (int i = m + 1; i < n; i++)
                if (Map[x, i] != 101) //有别的棋子
                    return false;
            return true;
        }
        //水平方向判断是否有别的棋子挡路
        private bool HLine_Juge(int m, int n, int y)
        {
            int t = Math.Max(m, n);
            m = Math.Min(m, n);
            n = t;
            for (int i = m + 1; i < n; i++)
                if (Map[i, y] != 101) //有别的棋子
                    return false;
            return true;
        }

解决方案 »

  1.   

    假设说A与B、A与C、B与D、B与F、C与F、C与E,有通路,那么到E有多少条路?从A出发走2步能够到达哪些位置?等等。而你写的什么“垂直方向、水平方向”之类的代码,在形式逻辑的解题基础方面,属于纯粹是“没有上到3年级”的。你靠自己业余时间瞎琢磨不行,你应该学点软件、或者数学、或者解题逻辑,等只有在正规大学的相关软件专业(或者其它工科、与工程计算有关的专业)学到的知识。
      

  2.   

    已经解决。采用A_satr算法实现