110,534
社区成员
发帖
与我相关
我的任务
分享
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;
}