亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? searchagent.cpp

?? 一個人工智能的國際象棋游戲
?? CPP
字號:
/****************************************************
Author: S. Senthil kumar
File: SearchAgent.cpp
Purpose:    Implementation of The Game Engine

******************************************************/


#include "Global.h"
#include "OneMove.h"
#include "Moves.h"
#include "TransTableEntry.h"
#include "TranspositionTable.h"
#include "SearchAgent.h"


extern int CheckCheck(int board[8][8],int target,int whilethinking=0);
extern CString GetMusicDirectory();
extern int computer_color;
extern int end_of_game;
extern int debug;
extern int movecount;
extern TranspositionTable table;
extern int whiteking_stalemate;
extern int blackking_stalemate;
extern int pondering;
extern int WHITEBASE;	
extern int BLACKBASE;
extern CStatusBarCtrl statusbar;
extern int sndenable;

extern int BOARDSIZE;


	
	
	SearchAgent::SearchAgent(int color,int board[8][8],int depth,int alpha,int beta,int chformate)
	{

		maxval=3950;
		minval=0;
		checkmate=0;
		actualcolor=color;
		checking_for_mate=chformate;		
		actualdepth=depth; 
		RetVal=RealSearch(color,board,depth,alpha,beta);
	}
	
	
	

	int SearchAgent::RealSearch(int currentcolor,int cboard[8][8],int depth,int alpha,int beta)
	{
		
	
		int currentboard[8][8];
		int min,max;
		min=13850;max=-13850;
		static int count=0;
		static int mincount=0;
		OneMove tempbestwhitemove;
		OneMove tempbestblackmove;

		//Clone new board
		memcpy(currentboard,cboard,BOARDSIZE);
		if (depth==0)
		{
			//Evaluate current board	
			return eval(currentboard,currentcolor);
		}
		//Check for TransTable hit
		if (!checking_for_mate)
		{
			TransTableEntry entry=table.LookUp(cboard); 
			if (entry.valid)
			{
				
				if (((entry.move.piece<10 && entry.move.piece>0 && currentcolor==1) || (entry.move.piece>10 && entry.move.piece<17 && currentcolor==0)) && entry.depth>=depth)
				{
					
					if (depth==actualdepth)
					{
						
						
						player_bestmove=entry.move;
											
					}
					
				
					
					return entry.value;
				}
				
			}
		
		}
		
		
		Moves moves;
		int retval;
	
		int newboard[8][8];
			
		//Current color is WHITE
		if (currentcolor==1)
			{	
				
				int i;
				int checkcount=0;
				int currentalpha=alpha;	
				OneMove *temp;
				//Generate moves for current board		
				moves.GenerateAllMoves(currentboard,(currentcolor==1?WHITE:BLACK),depth,checking_for_mate);		
				if (moves.size==0) {return (28000);}
							
				temp=moves.head; 
				temp=temp->next;
				currentmove=*temp;
				//Iterate through moves generated
				for (i=0;temp!=NULL;i++)
				{
					memcpy(newboard,currentboard,BOARDSIZE);
					ApplyMove(newboard,temp);
					if (CheckCheck(newboard,WHITE_KING,1)) //Skip if it leads to check
					{
						if (i!=(moves.size) && temp!=0)
						{
							temp=temp->next;
							checkcount++;
						}
						else
							break;
						continue;
					}
		
					
					currentmove=*temp;
					//Recursive call to next level. Return value indicates black's best move value for current white move
					retval=RealSearch(!currentcolor,newboard,depth-1,currentalpha,beta);
					//retval indicates move value for best black move. To prevent choosing that move, we choose the max since black's move evaluations are negative.(For white, more positive move eval the better and vice versa for black)
					currentalpha=(currentalpha>retval?currentalpha:retval);
					
					
					if (i==0 && actualcolor==0)
					{
						max=retval;
						alpha=max;
					}
					
					//Value returned is greater than max so far. So must be good.
					if (retval>max)
					{
						max=retval;
						tempbestwhitemove=*temp;
						//If this is top level, it is candidate for best move.
						if (depth==actualdepth)						
						{
							player_bestmove=*temp;
						}
		 				//If value reaches cutoff (means save in Transtable and return)
						if (retval>=beta)
						{
							TransTableEntry t;
							t.depth=depth;t.move=*temp;t.value=max;
							table.AddEntry(cboard,t);
							moves.destroy();							
							return max;
						}
						
					}
					//Extra care to prevent going past end of linked list
					if (i!=(moves.size-1) && temp!=0)
						temp=temp->next;
					else
						break;
				}
				//Checking for stalemate and checkmate (If all moves are skipped as above)
				if (checkcount==moves.size && !pondering) 
				{	
					if (!checking_for_mate)
					{
						if (!CheckCheck(currentboard,WHITE_KING,1)) //Avoid stalemate. If black moves such that white king is not in check
						{
							moves.destroy();
							return 5000;
						}
					}
					else
					{
						//Encourage mate in closest depth
						if (depth==actualdepth-1)
						  {
								return -7000;
						  }
						  else if(depth==actualdepth-2)
						  {
								return -5000;
						  }
						  else if(depth==actualdepth-3)
						  {
							  return -3000;
						  }
						  else if(depth==actualdepth-4)
						  {
							  return -2000;
						  }
						  else
						  {
							  return -1000;
						  }
						
						
					}
					//If current level
					if (depth==actualdepth)
					{
						//If whiteking not in check and still can't move, means Stalemate else Checkmate.(Win for black)
						if (!whiteking_stalemate)
						{
							MessageBox(NULL,"Black Won",(computer_color==BLACK?"The Genius wins, as always":"The Genius is Defeated"),0);
							checkmate=1;
							if (sndenable)
							{
								if (computer_color==BLACK)
								{	
									PlaySound(GetMusicDirectory()+"\\Wav\\Applause.Wav",NULL,0);
									
								}
								else
								{
									PlaySound(GetMusicDirectory()+"\\Wav\\Oooh.Wav",NULL,0);
								}
							}
							statusbar.SetText("Game Over",0,0);
						}
						else
						{
							MessageBox(NULL,"Nobody wins","Stalemate",0);statusbar.SetText("Game Over",0,0);
						}
						end_of_game=1;
					}
				}
	
				else
				{
					//No cutoff. Returns best value found so far though less than beta.
					TransTableEntry t;
					t.depth=depth;t.move=tempbestwhitemove;t.value=max;
					table.AddEntry(cboard,t);
				}
				moves.destroy();
				return max;
			
			}
			else
			{
				//If currentcolor is black
				int i;
				int currentbeta=beta;
				int checkcount=0;
				OneMove *temp;
				
				//Generate Moves for current board
				moves.GenerateAllMoves(currentboard,(currentcolor==1?WHITE:BLACK),depth,checking_for_mate);		
				if (moves.size==0) {return (-28000);}
				temp=moves.head;
				temp=temp->next;
				
				currentmove=*temp;
				//Iterate through loop
				for (i=0;moves.size!=0 && temp!=NULL;i++)
				{
					//Clone new board
					int newboard[8][8];		
					memcpy(newboard,currentboard,BOARDSIZE);
					ApplyMove(newboard,temp);
			
					if (CheckCheck(newboard,BLACK_KING,1)) //Skip if it leads to check
					{
						
						if (i!=(moves.size) && temp!=0)
						{
							temp=temp->next;
							checkcount++;
							
						}
						else
							break;
						continue;
					}	
					currentmove=*temp;
					//Recursively goto next level (white's perspective)
					retval=RealSearch(!currentcolor,newboard,depth-1,alpha,currentbeta);
					//retval contains move value for best white move. So we shouldn't play that move and hence choose the minimum value(For white, more positive move eval the better and vice versa for black)
					currentbeta=(retval<currentbeta?retval:currentbeta);
		//			
					if (i==0 && actualcolor==1)
					{ 
						min=retval;
						beta=min;
					}
					tempbestblackmove=*temp;
					
					if (retval<min)
					{
						min=retval;
						//Min of moves so far and so candidate for best move.
						if (depth==actualdepth)						
						{
							player_bestmove=*temp;
						}
		 		
						if (min<=alpha)
						{
							//retval less than what was wanted. So very good move. No need to search any more. Return eval
							TransTableEntry t;
							t.depth=depth;t.move=*temp;t.value=min;
					
							table.AddEntry(cboard,t);
							
							  moves.destroy();
							return min;
						}
					}
					//Checking for end of linked list
					if ((i!=moves.size) && temp!=NULL)
					temp=temp->next;
					
				}
				//Checking for stalemate and checkmate
				if (checkcount==moves.size && !pondering) 
				{
					if (!checking_for_mate)
					{
						if (!CheckCheck(currentboard,BLACK_KING,1))
						{
							moves.destroy();
							return -5000;
						}
						else
						{
						  //Encourage mating moves by white by returning higher values for closer checkmates.
						  moves.destroy();
						  if (depth==actualdepth-1)
						  {
								return 7000;
						  }
						  else if(depth==actualdepth-2)
						  {
								return 5000;
						  }
						  else if(depth==actualdepth-3)
						  {
							  return 3000;
						  }
						  else if(depth==actualdepth-4)
						  {
							  return 2000;
						  }
						  else
						  {
							  return 1000;
						  }
							
						}
					}
					
					if (depth==actualdepth)
					{
						if (!blackking_stalemate)
						{
							MessageBox(NULL,"White won",(computer_color==WHITE?"The Genius wins, as always":"The Genius is Defeated"),0);checkmate=1;statusbar.SetText("Game Over",0,0);
							if (sndenable)
							{
								if (computer_color==WHITE)
								{
									PlaySound(GetMusicDirectory()+"\\Wav\\Applause.Wav",NULL,0);
								
								}
								else
								{
									PlaySound(GetMusicDirectory()+"\\Wav\\Oooh.Wav",NULL,0);
								}
							}
						}
						else
						{
							MessageBox(NULL,"Nobody wins","Stalemate",0);statusbar.SetText("Game Over",0,0);
						}
						end_of_game=1;
					}
				}
				else
				{
					//No cutoff. Store value in TransTable and return
					TransTableEntry t;
					t.depth=depth;t.move=tempbestblackmove;t.value=min;
					table.AddEntry(cboard,t);
					
				}
				
				moves.destroy();
				return min;			
				
	}
	
		
	
}

void SearchAgent::ApplyMove(int currentboard[8][8],OneMove *temp)
	{
		currentboard[temp->desty][temp->destx]=currentboard[temp->sourcey][temp->sourcex];
		currentboard[temp->sourcey][temp->sourcex]=0;
	}
		
		
	
OneMove SearchAgent::getBestMove()
	{
		return player_bestmove;
	}
	

int SearchAgent::eval(int currentboard[8][8],int color)
	{

		int value=0;
		int oppplayer_value=0;
			for (int i=0;i<8;i++)
			{
				for (int j=0;j<8;j++)
				{
					
					if (currentboard[i][j]<10 && currentboard[i][j]!=0)
					{
						switch (currentboard[i][j]%10)
						{
							case 1:
							{
		
								//Pawn promotion Considered as queen
								if ((WHITEBASE==0 && i==7) || (WHITEBASE==7 && i==0))
								{
									value+=900;
								}
								else
								{
									value+=100;
								}
							}
							break;
							case 2:
							{
								
								value+=10000;
								
								
							}
							break;
							case 3:
							{
								value+=900;
							}
							break;
							case 4:
							{
								value+=325;
							}
							break;
							case 5:
							{
								value+=300;
							}break;
							case 6:
							{
								value+=500;
							}
							break;
						}
					}
					else
					{
						switch(currentboard[i][j]%10)
						{
							case 1:
							{
								if ((BLACKBASE==0 && i==7) || (BLACKBASE==7 && i==0))
								{
									oppplayer_value+=900;
								}
								else
								{
									oppplayer_value+=100;
								}
								
							}
							break;
							case 2:
							{
								oppplayer_value+=10000;
								
							}break;
							case 3:
							{
								oppplayer_value+=900;
							}break;
							case 4:
							{
								oppplayer_value+=325;
							}
							break;
							case 5:
							{
								oppplayer_value+=300;
							}break;
							case 6:
							{
								oppplayer_value+=500;
							}
					
						}
					}
				}
			}
		
		
		//Statistical advantages.
		int base=0;
		if (actualcolor==1)
		{
			if (WHITEBASE==0) 
			{
				base=0;
			}
			else
			{
				base=7;
			}
		}
		else
		{
			if (BLACKBASE==0)
			{
				base=0;
			}
			else
			{
				base=7;
			}
		}
		if (movecount<11) //Encourage horse movements in initial stages.
		{
			if (currentboard[base][1]==0 || currentboard[base][6]==0 || currentboard[base][2]==0 || currentboard[base][5]==0)
			{
				if (actualcolor==1)
				{
					value+=10;
				}
				else
				{
					oppplayer_value+=10;
				}
			}
		}
		if (color==1) return value-oppplayer_value; //For white, more positive the better
		 else return -((oppplayer_value-value));	//For black, more negative, the better.

	}

	
	
























?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品综合av一区二区国产馆| 欧美大片在线观看一区| 国产亚洲一二三区| 青青草成人在线观看| 欧美伦理电影网| 亚洲18色成人| 亚洲欧美中日韩| 不卡的av中国片| 一区二区不卡在线播放| 色狠狠色狠狠综合| 亚洲成av人片www| 91麻豆精品国产91久久久久久久久 | 日韩激情一二三区| 777午夜精品免费视频| 免费精品视频最新在线| 日韩女优制服丝袜电影| 国产精品正在播放| 亚洲欧洲精品一区二区三区不卡| kk眼镜猥琐国模调教系列一区二区| 国产精品美日韩| 欧美日韩日日摸| 国产精品一区二区久激情瑜伽| 亚洲国产精华液网站w| 欧美熟乱第一页| 国产一区二区三区蝌蚪| 综合分类小说区另类春色亚洲小说欧美| 99久久99久久久精品齐齐| 亚洲一区免费观看| 日本一区二区三区国色天香 | 91香蕉视频污| 日本不卡免费在线视频| 亚洲欧洲制服丝袜| 精品国产乱码久久久久久夜甘婷婷| 成人免费av在线| 狂野欧美性猛交blacked| 亚洲精品你懂的| 国产亚洲一区字幕| 亚洲精品在线电影| 91猫先生在线| 国产在线看一区| 亚洲va韩国va欧美va| 最近中文字幕一区二区三区| 欧美va天堂va视频va在线| 91国产福利在线| 日韩美女啊v在线免费观看| 国产精品久久久久久福利一牛影视 | 亚洲人午夜精品天堂一二香蕉| 欧美人动与zoxxxx乱| 在线精品视频小说1| 成人精品一区二区三区四区| 国产成人超碰人人澡人人澡| 精品综合久久久久久8888| 日韩黄色小视频| 青青草原综合久久大伊人精品优势 | 国产欧美日韩视频一区二区| 欧美精品一区二区三区四区| 欧美成人猛片aaaaaaa| 日韩色视频在线观看| 久久你懂得1024| 中文一区在线播放| 一区二区三区在线免费观看| 亚洲午夜精品网| 美女脱光内衣内裤视频久久网站| 免费视频一区二区| 国产精品亚洲午夜一区二区三区| 成人av在线影院| 欧美男人的天堂一二区| 欧美大片在线观看一区| 国产精品视频在线看| 一区二区三区在线播| 精品一区二区三区在线播放视频| 国产成人精品三级麻豆| 欧美在线免费观看视频| 日韩女优制服丝袜电影| 亚洲天堂中文字幕| 欧美a级一区二区| 欧美色综合久久| 久久影院电视剧免费观看| 亚洲精品乱码久久久久久| 久久99精品久久久久久动态图 | 中文字幕一区二区三区在线播放| 夜夜爽夜夜爽精品视频| 国产精品亚洲成人| 欧美日韩国产首页在线观看| 国产亚洲一区二区在线观看| 亚洲成人av电影在线| 99久久国产综合精品色伊| 精品夜夜嗨av一区二区三区| 欧美视频在线播放| 自拍偷自拍亚洲精品播放| 久久99精品国产| 欧美日韩aaaaaa| 一区二区三区毛片| 97se亚洲国产综合自在线观| 久久亚洲一级片| 蜜芽一区二区三区| 777午夜精品视频在线播放| 亚洲一区在线视频| 一本到不卡精品视频在线观看| 欧美国产精品v| 国产福利一区二区三区在线视频| 精品粉嫩超白一线天av| 久久成人羞羞网站| 久久久噜噜噜久久人人看| 国内偷窥港台综合视频在线播放| 2023国产精品| 成人一区二区三区中文字幕| 国产欧美日韩另类一区| 成人av资源下载| 亚洲综合色在线| 91麻豆精品国产91久久久久久| 亚洲成人动漫在线观看| 欧美一区二区黄| 国产一区欧美一区| 国产精品免费视频网站| 91原创在线视频| 免费成人在线观看视频| 久久奇米777| 欧美色综合久久| 日本韩国精品在线| 日韩影院免费视频| 日本一区二区三区四区在线视频 | 在线免费av一区| 麻豆91精品91久久久的内涵| 国产亚洲综合色| 欧美色倩网站大全免费| 精品一区二区三区的国产在线播放 | 欧美日韩亚洲另类| 久久国产精品99久久久久久老狼| 中文字幕一区av| 日韩精品一区二区三区中文精品| 成人蜜臀av电影| 美女视频黄久久| 亚洲成人激情社区| 国产精品久久久久久久久免费桃花| 欧美精品乱码久久久久久| 成人免费毛片app| 国产主播一区二区| 毛片av一区二区三区| 一区二区三区中文在线观看| 国产精品视频一二| 久久久综合精品| 久久色.com| 26uuu国产电影一区二区| 欧美一区二区三区免费| 欧美日韩国产天堂| 在线观看91av| 欧美一区二区三区免费观看视频 | 欧美一卡2卡三卡4卡5免费| 色8久久精品久久久久久蜜| 成人h版在线观看| 99久久国产免费看| 欧美男同性恋视频网站| 欧美三区免费完整视频在线观看| 欧美偷拍一区二区| 欧美精品日日鲁夜夜添| 91精品国产一区二区三区| 欧美精品黑人性xxxx| 精品久久久三级丝袜| 国产日韩欧美精品综合| 中文字幕永久在线不卡| 亚洲激情自拍视频| 久久99精品一区二区三区三区| 韩国成人精品a∨在线观看| 国产精品一区在线| 色婷婷亚洲一区二区三区| 8x8x8国产精品| 国产偷国产偷精品高清尤物| 亚洲色图色小说| 美女脱光内衣内裤视频久久网站 | 亚洲福利一区二区| 国产成人自拍网| 欧美又粗又大又爽| 国产精品国产三级国产普通话99| 亚洲欧美成人一区二区三区| 香蕉影视欧美成人| 成人免费视频播放| 日韩一区二区三区视频在线观看| 国产精品免费视频一区| 免费不卡在线观看| 欧美婷婷六月丁香综合色| 日本一区二区三区高清不卡| 石原莉奈一区二区三区在线观看 | 美女视频一区在线观看| 一本大道久久a久久综合婷婷| 精品久久久久一区二区国产| 亚洲午夜av在线| 91蜜桃视频在线| 国产精品拍天天在线| 国产一区二区看久久| 日韩一区二区在线看片| 亚洲高清免费视频| 在线观看欧美精品| 综合久久久久久| 91亚洲资源网| 蜜臀a∨国产成人精品| 欧美一卡二卡三卡| 日本在线不卡一区| 欧美一区二区私人影院日本| 日韩电影在线一区二区三区|