⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classes.cs

📁 Visual studio 2005,C#开发 具有人工智能
💻 CS
📖 第 1 页 / 共 2 页
字号:
					&& ((situation[toX,toY] == null) 
					|| ((situation[toX,toY] != null)
					&&(situation[toX,toY].color != this.color))))
				{
					if (((Math.Abs(this.x-toX) == 1)
						&&(Math.Abs(this.y-toY) == 2))
						||((Math.Abs(this.x-toX) == 2)
						&&(Math.Abs(this.y-toY) == 1)))
					{
						int i = -1;
						int j = -1;
						if (toX-this.x == 2)
						{
							i = this.x + 1;
							j = this.y;
						}
						else if (this.x-toX == 2)
						{
							i = this.x - 1;
							j = this.y;
						}
						else if (toY-this.y == 2)
						{
							i = this.x;
							j = this.y + 1;
						}
						else if (this.y-toY == 2)
						{
							i = this.x;
							j = this.y - 1;
						}

						if (situation[i,j] == null)
						{
							return true;
						}
					}
				}

				return false;
			}

		}

		class Chariot:ChessMan
		{
			public Chariot(int color, int x, int y, int boardside) : base(color, CHARIOT, x, y, boardside) { }
			public Chariot(int color,int number,int boardside):base(color, CHARIOT, number,boardside)
			{
			}
			public bool isNormal(int posX,int posY)
			{
				return true;
			}

			public override bool canGo(int toX, int toY)
			{
				if (isNormal(toX, toY)
					&& ((situation[toX, toY] == null)
					|| ((situation[toX, toY] != null)
					&& (situation[toX, toY].color != this.color))))
				{
					if ((this.x != toX) && (this.y != toY))
					{
						return false;
					}
					else
					{
						if (this.y == toY)
						{
							if (this.x < toX)
							{
								for (int x = this.x + 1; x < toX; x++)
								{
									if ((situation[x, this.y] != null)
										&& (situation[x, this.y].color != GREY))
									{
										return false;
									}
								}
								return true;
							}

							if (this.x > toX)
							{
								for (int x = this.x - 1; x > toX; x--)
								{
									if ((situation[x, this.y] != null)
										&& (situation[x, this.y].color != GREY))
									{
										return false;
									}
								}
								return true;
							}
							return false;
						}
						else
						{
							if (this.y < toY)
							{
								for (int y = this.y + 1; y < toY; y++)
								{
									if ((situation[this.x, y] != null)
										&& (situation[this.x, y].color != GREY))
									{
										return false;
									}
								}
								return true;
							}

							if (this.y > toY)
							{
								for (int y = this.y - 1; y > toY; y--)
								{
									if ((situation[this.x, y] != null)
										&& (situation[this.x, y].color != GREY))
									{
										return false;
									}
								}
								return true;
							}
							return false;
						}
					}
				}
				else
				{
					return false;
				}
			}

		}

		class Cannon:ChessMan
		{
			public Cannon(int color, int x, int y, int boardside) : base(color, CANNON, x, y, boardside) { }
			public Cannon(int color,int number,int boardside):base(color, CANNON, number,boardside)
			{
			}
			public bool isNormal(int posX,int posY)
			{
				return true;
			}

			public override bool canGo(int toX, int toY)
			{
				if (isNormal(toX, toY)
					&& ((situation[toX,toY] == null) 
					|| ((situation[toX,toY] != null)
					&&(situation[toX,toY].color != this.color))))
				{
					if ((this.x!=toX) && (this.y!=toY))
					{
						return false;
					}
					else
					{
						if (situation[toX,toY] == null)
						{
							if (this.y == toY)
							{
								if (this.x < toX)
								{
									for (int x=this.x+1; x<toX; x++)
									{
										if ((situation[x,this.y] != null)
											&& (situation[x,this.y].color != GREY))
										{
											return false;
										}
									}
									return true;
								}

								if (this.x > toX)
								{
									for (int x=this.x-1; x>toX; x--)
									{
										if ((situation[x,this.y] != null)
											&& (situation[x,this.y].color != GREY))
										{
											return false;
										}
									}
									return true;
								}
							}
							else
							{
								if (this.y < toY)
								{
									for (int y=this.y+1; y<toY; y++)
									{
										if ((situation[this.x,y] != null)
											&& (situation[this.x,y].color != GREY))
										{
											return false;
										}
									}
									return true;
								}

								if (this.y > toY)
								{
									for (int y=this.y-1; y>toY; y--)
									{
										if ((situation[this.x,y] != null)
											&& (situation[this.x,y].color != GREY))
										{
											return false;
										}
									}
									return true;
								}
							}
						}
						else
						{
							int count = 0;
						
							if (this.y == toY)
							{
								if (this.x < toX)
								{
									for (int x=this.x+1; x<toX; x++)
									{
										if ((situation[x,this.y] != null)
											&& (situation[x,this.y].color != GREY))
										{
											count ++;
										}
									}
									if (count == 1)
									{
										return true;
									}
								}

								if (this.x > toX)
								{
									for (int x=this.x-1; x>toX; x--)
									{
										if ((situation[x,this.y] != null)
											&& (situation[x,this.y].color != GREY))
										{
											count ++;
										}
									}
									if (count == 1)
									{
										return true;
									}
								}
							}
							else
							{
								if (this.y < toY)
								{
									for (int y=this.y+1; y<toY; y++)
									{
										if ((situation[this.x,y] != null)
											&& (situation[this.x,y].color != GREY))
										{
											count ++;
										}
									}
									if (count == 1)
									{
										return true;
									}
								}

								if (this.y > toY)
								{
									for (int y=this.y-1; y>toY; y--)
									{
										if ((situation[this.x,y] != null)
											&& (situation[this.x,y].color != GREY))
										{
											count ++;
										}
									}
									if (count == 1)
									{
										return true;
									}
								}
							}
						}
					}
				}

				return false;
			}

		}

		class Soldier:ChessMan
		{
			public Soldier(int color,int x, int y, int boardside): base(color, SOLDIER, x, y, boardside){}
			public Soldier(int color,int number,int boardside):base(color, SOLDIER, number,boardside)
			{
			}
			public bool isNormal(int posX,int posY)
			{
				if (this.color == BLACK)
				{
					if ((posY < 3)
						|| ((posY < 5) && (posX % 2 == 1)))
					{
						return false;
					}
				}
		
				if (this.color == RED)
				{
					if ((posY > 6)
						|| ((posY > 4) && (posX % 2 == 1)))
					{
						return false;
					}
				}

				return true;
			}

			public override bool canGo(int toX, int toY)
			{
				if (isNormal(toX, toY)
					&& ((situation[toX,toY] == null) 
					|| ((situation[toX,toY] != null)
					&&(situation[toX,toY].color != this.color))))
				{
					if (this.color == BLACK)
					{
						if (toY < this.y)
						{
							return false;
						}
						else
						{
							if (Math.Abs(toX-this.x) + toY-this.y != 1)
							{
								return false;
							}
						}
					}
					if (this.color == RED)
					{
						if (toY > this.y)
						{
							return false;
						}
						else
						{
							if (Math.Abs(toX-this.x) + this.y-toY != 1)
							{
								return false;
							}
						}
					}
					return true;
				}
				return false;
			}

		}

		class Blank:ChessMan
		{
			public Blank(int x, int y, int boardside)
				: base(GREY, BLANK, x,  y, boardside)
			{
			}
			public override bool canGo(int toX, int toY)
			{
				return false;
			}
		}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -