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

📄 thinker.cs

📁 Visual studio 2005,C#开发 具有人工智能
💻 CS
📖 第 1 页 / 共 3 页
字号:
					if(!flag)	CV(n,x,j)
				}
				else
				{
					if(!flag)flag=true;
					else 
					{
						CV(n,x,j)
						break;
					}
				}
				j--;
			}
			break;
		case 11:
		case 12:
		case 13:
		case 14:
		case 15:
			j=y-1;
			if(j>=1 )	CV(n,x,j)
			if(y<=5)
			{
				i=x+1;if(i<=9 )	CV(n,i,y)
				i=x-1;if(i>=1 )	CV(n,i,y)
			}
			break;

		case 27:
		case 28:
		case 29:
		case 30:
		case 31:
			j=y+1;
			if(j<=10 )	CV(n,x,j)
			if(y>=6)
			{
				i=x+1;if(i<=9 )	CV(n,i,y)
				i=x-1;if(i>=1 )	CV(n,i,y)
			}
			break;
		default :
			break;
		}
	}
}

int SubThink(int man, int tx, int ty)
{
	int ate,i,j,cur,maxvalue,curvalue,xs,ys;
	char *bman,*btox,*btoy;
	int *pcount;

	ate=32;
	tdeep++;
	//
	//移动棋子:
	xs=tmanx[man];ys=tmany[man];				//原坐标
	if (SideOfMan[tmap[tx][ty]]==!tside)	//目标点有对方的棋子
	{
		ate=tmap[tx][ty];					//记录下被吃掉的棋子
		if(ate==0 || ate==16)
		{
			tdeep--;
			return 9999;
		}
		tmanx[ate]=0;						//目标点的棋子被吃掉
	}
	tmap[tx][ty]=man;						//这两行是:
	tmap[xs][ys]=32;							//在map上的移动
	tmanx[man]=tx;							//这两行是:
	tmany[man]=ty;							//在face上的移动
	tside=!tside;

	if(tdeep != tlevel)
	{

		//初始化:
		bman=tman[tdeep];
		btox=ttox[tdeep];
		btoy=ttoy[tdeep];
		pcount=& tcount[tdeep];
		*pcount=0;

		cur=0;

		if(EnumList())
		{
			maxvalue=-10000;
			i=*pcount;
			while(cur< i)
			{
				curvalue=SubThink(bman[cur],btox[cur],btoy[cur]);
				if(curvalue>maxvalue)maxvalue=curvalue;
				cur ++;
			}
		}
		else maxvalue=9800;
	}
	else
	{
		memset(v2,0,sizeof(int)<<10);
		memset(v1,0,sizeof(int)<<5);
		memset(v3,0,sizeof(int)<<5);
		memset(v4,0,sizeof(int)<<5);

		maxvalue=0;
		ContactV();
//己方将军			
		for(i=FistOfSide[tside];i<=LastOfSide[tside];i++)
		{
			if(v2[i][FistOfSide[!tside]])
			{
				maxvalue=9700;
				goto _ENDSUB;
			}
		}

		for(int i=0;i<32;i++)
		{
			k=ManToType7[i];
			v1[i]=BV1[k]+v1[i]*BV2[k];
			if(k==6)		v1[i]+=BV3[ BA[SideOfMan[i]][tmany[i]][tmanx[i]] ];
		}
		for(int i=0;i<32;i++)
		{
			for(j=0;j<32;j++)
			{
				if(v2[i][j])
				{
					if(SideOfMan[i]==SideOfMan[j])
					{
						v3[i]+=v1[j]>>5;//己方
						v4[j]++;
					}
					else
					{
						v3[i]+=v1[j]>>3;//对方
						v4[j]--;
					}
				}
			}
		}
		for(i=FistOfSide[tside];i<=LastOfSide[tside];i++)
		{
			if(tmanx[i])maxvalue+=v1[i]+v3[i];			
		}
		static bool flag;
		flag=false;k=32;		
		for(i=FistOfSide[!tside];i<=LastOfSide[!tside];i++)
		{
			if(tmanx[i])maxvalue-=v1[i]+v3[i];			
//对方将军
			if(v2[i][FistOfSide[tside]])
			{
				flag=true;
				k=i;
				break;
			}
		}

		if(flag)//被将
		{
			if(v4[k]>=0)//所将军的棋子不能被吃掉
			{
				j=0;
				for(i=FistOfSide[tside];i<=LastOfSide[tside];i++)
				{
					if(v4[i]<0 && v1[i]>j)	j=v1[i];
				}
				maxvalue -=j;
			}
		}
		else
		{
			j=0;
			for(i=FistOfSide[!tside];i<=LastOfSide[!tside];i++)
			{
				if(v4[i]<0 && v1[i]>j)
					j=v1[i];
			}
			maxvalue +=j;
		}
	}


_ENDSUB:	tmanx[man]=xs;							//这两行是:
	tmany[man]=ys;							//在face上的恢复
	tmap[xs][ys]=man;						//在map上的恢复
	if(ate!=32)
	{
		tmanx[ate]=tx;
		tmany[ate]=ty;
		tmap[tx][ty]=ate;
	}
	else tmap[tx][ty]=32;

	tside=!tside;

	tdeep--;
	return -maxvalue;
}

bool LoadThinkSetting()
{
	CFile file;
	if(file.Open( "Thinker.set",CFile::modeRead))
	{
		file.SeekToBegin();
		file.Read(BV1,7*sizeof(int));
		file.Read(BV2,7*sizeof(int));
		file.Read(BV3,5*sizeof(int));
		file.Close();

		if(BVIsNormal())return true;
		else
		{
			ResetBV();
			SaveThinkSetting();
			return false;
		}		
	}
	MessageBox(NULL, "没找到 Thinker.set 文件\n\n这个文件并不是必需的,但它记录了你的设置内容,\n\n请不要删掉\n\n你现在可以通过菜单 \"文件\" -> \"参数\" 重新设定.","提醒",MB_OK|MB_ICONINFORMATION);
	ResetBV();
	SaveThinkSetting();
	return false;

}

void ResetBV()
{
	BV1[0]=0;	BV2[0]=0;
	BV1[1]=250;	BV2[1]=1;
	BV1[2]=250;	BV2[2]=1;
	BV1[3]=300;	BV2[3]=12;
	BV1[4]=400;	BV2[4]=6;
	BV1[5]=300;	BV2[5]=6;
	BV1[6]=100;	BV2[6]=15;
	BV3[0]=0;
	BV3[1]=70;
	BV3[2]=90;
	BV3[3]=110;
	BV3[4]=120;
}

bool BVIsNormal()
{
	int i;
	for(int i=0;i<=6;i++)
	{
		if(BV1[i]<0||BV1[i]>1000||BV2[i]<0||BV2[i]>1000)return false;
	}
	for(int i=0;i<=4;i++)
	{
		if(BV3[i]<0||BV3[i]>1000)return false;
	}
	return true;
}

bool SaveThinkSetting()
{
	CFile file;
	if(file.Open("Thinker.set",CFile::modeWrite|CFile::modeCreate))
	{
		file.SeekToBegin();
		file.Write(BV1,7*sizeof(int));
		file.Write(BV2,7*sizeof(int));
		file.Write(BV3,5*sizeof(int));
		file.Close();
		return true;
	}
	else return false;	

}
	}


	class CXY 	//X,Y各占一字节的点类
	{

		public byte x;
		public byte y;

		public CXY()
		{
			x = 0;
			y = 0;
		}

		public CXY(int xx, int yy)
		{
			x = (byte)xx;
			y = (byte)yy;
		}

		public CXY(CXY xy)
		{
			x = xy.x;
			y = xy.y;
		}

		public static bool operator ==(CXY xy, CXY xy2)
		{
			if (xy.x != xy2.x) return false;
			if (xy.y != xy2.y) return false;

			return true;
		}

		public static bool operator !=(CXY xy, CXY xy2)
		{
			if (xy.x != xy2.x) return true;
			if (xy.y != xy2.y) return true;

			return false;
		}
	}

	class CMove	//走法
	{
		public byte man;				//所走的子
		public byte x;
		public byte y;					//走到的位置

		public CMove()
		{
			man = 0;
			x = 0;
			y = 0;
		}
		public CMove(CMove move)
		{
			man = move.man;
			x = move.x;
			y = move.y;
		}
	}
	
	class CStep	//棋步
	{
		public byte man;				//所走的子
		public byte eaten;				//被吃的子
		public CXY from=new CXY();				//从 from 点
		public CXY to=new CXY();					//走到 to 点

	public CStep()
	{
		man=32;
		eaten=32;
		from.x=0;
		from.y=0;
		to.x=0;
		to.y=0;
	}
	};

	class CFace 			//棋局
	{
		public CXY[] man=new CXY[32];						//32棋子的位置(man[*].x==0则棋子已死)
		public int side;							//走的一方 RED|0-红;BLACK|1-黑

	public CFace()
	{
		Reset();
	}

	public CFace(CFace face)
	{
		for(int i=0;i<32;i++)man[i]=face.man[i];

		side=face.side;
	}

	public static bool operator==(CFace face,CFace face1)
	{
		for(int i=0;i<32;i++)
			if(face1.man[i]!=face.man[i])return false;

		if (face1.side!=face.side)return false;

		return true;
	}

	public static bool operator!=(CFace face,CFace face1)
	{
		for(int i=0;i<32;i++)
			if(face1.man[i]!=face.man[i])return true;

		if (face1.side!=face.side)return true;

		return false;
	}


	public void Reset()//设为标准棋局
	{
		//红
		man[0].x=5;man[0].y=10;	//帅
		man[1].x=4;man[1].y=10;	//士
		man[2].x=6;man[2].y=10;	
		man[3].x=3;man[3].y=10;	//相
		man[4].x=7;man[4].y=10;
		man[5].x=2;man[5].y=10;	//马
		man[6].x=8;man[6].y=10;
		man[7].x=1;man[7].y=10;	//车
		man[8].x=9;man[8].y=10;
		man[9].x=2;man[9].y=8;	//炮
		man[10].x=8;man[10].y=8;
		man[11].x=1;man[11].y=7;//兵
		man[12].x=3;man[12].y=7;
		man[13].x=5;man[13].y=7;
		man[14].x=7;man[14].y=7;
		man[15].x=9;man[15].y=7;
		//黑
		man[16].x=5;man[16].y=1;//将
		man[17].x=4;man[17].y=1;//士
		man[18].x=6;man[18].y=1;
		man[19].x=3;man[19].y=1;//相
		man[20].x=7;man[20].y=1;
		man[21].x=2;man[21].y=1;//马
		man[22].x=8;man[22].y=1;
		man[23].x=1;man[23].y=1;//车
		man[24].x=9;man[24].y=1;
		man[25].x=2;man[25].y=3;//炮
		man[26].x=8;man[26].y=3;
		man[27].x=1;man[27].y=4;//卒
		man[28].x=3;man[28].y=4;
		man[29].x=5;man[29].y=4;
		man[30].x=7;man[30].y=4;
		man[31].x=9;man[31].y=4;

		side=(int)SideColor.Red;
	}
/*
	public bool IsNormal()
	{
		if (side != SideColor.Red && side != SideColor.Black) return false;
	
		int[,] map=new int[10,11];//map数组用来判断是否有两个没死的棋子放在同一点

		for(int i=1;i<10;i++)		
			for(int j=1;j<11;j++)map[i,j]=0;	//初始化

		for(int i=0;i<32;i++)
		{
			if(man[i].x!=0)						//没死
			{
				if	( 
					man[i].x<1	||
					man[i].x>9	||
					man[i].y<1	||
					man[i].y>10
					)	return false;			//不在棋盘内
					
				if(map[man[i].x,man[i].y]!=0)	//这一点已有子
					return false;

				map[man[i].x,man[i].y]=1;		//记者一点已有棋子

				//棋子放的位置不对:
//				if( !::IsNormal(ManToType[i],man[i].x,man[i].y) )return false;//lyp暂时注释
			}
		}

		return true;
	}
 */ 
/*
	bool CFace::Save(LPCSTR filename)
	{
		CFile file;
		if(file.Open(filename,CFile::modeWrite|CFile::modeCreate))
		{
			file.SeekToBegin();
			file.Write(this,sizeof(CFace));
			file.Close();
			return true;
		}
		else return false;	
	}

	bool CFace::Open(LPCSTR filename)//从文件读取
	{
		CFile file;
		if(file.Open( filename,CFile::modeRead))
		{
			file.SeekToBegin();
			file.Read(this,sizeof(CFace));
			file.Close();
			return true;
		}
		return false;
	}
*/
	};
	
	/*
	class CSetting
	{
	public:
		bool IsNormal();
		void Reset();
		CSetting();
		bool Load();
		bool Save();
		UINT m_nCOrM[2];			//给出[player]得到是否电脑
		UINT m_nPlayer[2];			//给出[color/side]得到棋手号
		UINT m_nLevel;				//计算机的等级
		UINT m_nMode;				//轮换方式(谁执什么棋)

	CSetting::CSetting()
	{
		Reset();
	}

	bool CSetting::Save()
	{
		CFile file;
		if(file.Open("Setting.set",CFile::modeWrite|CFile::modeCreate))
		{
			file.SeekToBegin();
			file.Write(this,sizeof(CSetting));
			file.Close();
			return true;
		}
		else return false;	
	}


	bool CSetting::Load()
	{
		CFile file;
		if(file.Open( "Setting.set",CFile::modeRead))
		{
			file.SeekToBegin();
			file.Read(this,sizeof(CSetting));
			file.Close();

			if(IsNormal())return true;
			else
			{
				Reset();
				Save();
				return false;
			}		
		}
		MessageBox(NULL, "没找到 Setting.set 文件\n\n这个文件并不是必需的,但它记录了你的设置内容,\n\n请不要删掉\n\n你现在可以通过菜单 \"文件\" -> \"设置\" 重新设定.","提醒",MB_OK|MB_ICONINFORMATION);
		Reset();
		Save();
		return false;
	}


	void CSetting::Reset()
	{
		m_nMode=1;
		m_nLevel=3;
		m_nCOrM[0]=0;
		m_nCOrM[1]=1;
		m_nPlayer[0]=RED;
		m_nPlayer[1]=BLACK;
	}

	bool CSetting::IsNormal()
	{
			if(m_nCOrM[0]>1 || m_nCOrM[1]>1)	return false;
			if(m_nPlayer[0]>1 || m_nPlayer[1]>1)return false;
			if(m_nPlayer[1]	== m_nPlayer[0])	return false;
			if(m_nLevel<1 || m_nLevel>4)		return false;
			if(m_nMode>2)						return false;

			return true;
	}
	
	}
	*/
}

⌨️ 快捷键说明

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