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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? searchagent.cpp

?? EVC4.0開發的國際象棋的元代碼
?? 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.

	}

	
	
























?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲国产综合91精品麻豆| 欧洲视频一区二区| 2024国产精品| 激情久久久久久久久久久久久久久久| 欧美蜜桃一区二区三区| 日韩成人一区二区三区在线观看| 欧美蜜桃一区二区三区| 亚欧色一区w666天堂| 欧美一区二区三区在线观看视频| 天天av天天翘天天综合网| 欧美色老头old∨ideo| 中文字幕欧美区| 色哟哟一区二区在线观看| 亚洲美女在线一区| 欧美日韩一区二区三区高清 | thepron国产精品| 国产三级一区二区| 北条麻妃一区二区三区| 亚洲一二三四在线观看| 欧美日本一区二区| 麻豆一区二区在线| 亚洲欧美自拍偷拍色图| 色婷婷精品久久二区二区蜜臀av| 一区二区三区中文在线观看| 欧美日韩精品综合在线| 国产精品自拍在线| 欧美国产日韩精品免费观看| yourporn久久国产精品| 亚洲欧美日韩电影| 日韩精品在线一区| 国产成人免费xxxxxxxx| 日韩美女视频一区| 精品国产乱码久久久久久牛牛| 国产在线视频精品一区| 国产精品蜜臀在线观看| 欧美影院一区二区三区| 国产精品综合在线视频| 亚洲视频中文字幕| 日韩一区二区三区电影在线观看| 美女看a上一区| 亚洲欧美日韩系列| 日韩午夜av电影| 成人丝袜视频网| 日本不卡一二三区黄网| 欧美极品xxx| 欧美色国产精品| 国产在线视频一区二区三区| 五月天中文字幕一区二区| 精品免费一区二区三区| 9i看片成人免费高清| 亚洲欧美一区二区三区极速播放| 日韩女优视频免费观看| 色综合久久久久综合体桃花网| 亚洲成人综合网站| 久久久99精品免费观看| 91精品国产欧美一区二区| 成人午夜在线免费| 蜜臀av亚洲一区中文字幕| 国产亚洲福利社区一区| 欧美日韩免费一区二区三区| 懂色av一区二区夜夜嗨| 日本一道高清亚洲日美韩| 一级做a爱片久久| 欧美极品aⅴ影院| 91精品国产入口| 国产成人高清视频| 国产伦精品一区二区三区视频青涩 | 一区二区三区四区视频精品免费 | 国产激情精品久久久第一区二区 | 日韩欧美高清一区| 在线亚洲一区观看| 色综合天天综合在线视频| 久久国产婷婷国产香蕉| 亚洲成人免费观看| 亚洲四区在线观看| 亚洲区小说区图片区qvod| 欧美国产日韩亚洲一区| 久久这里只精品最新地址| 91成人网在线| 欧美亚洲国产一区二区三区va| aaa亚洲精品| 国产精品1区二区.| 蜜臀久久久99精品久久久久久| 美腿丝袜亚洲色图| 奇米精品一区二区三区在线观看 | 欧美一区二区三区小说| 欧美中文字幕不卡| 91香蕉视频在线| 国产精品18久久久久| 国内外成人在线| 国产又黄又大久久| 老司机免费视频一区二区| 视频在线在亚洲| 五月天网站亚洲| 亚洲国产你懂的| 亚洲成在人线免费| 日韩精品一卡二卡三卡四卡无卡| 亚洲国产欧美一区二区三区丁香婷| 亚洲一区二区三区免费视频| 一区二区三区在线免费播放| 亚洲精品videosex极品| 亚洲视频你懂的| 一区二区三区在线观看动漫| 亚洲尤物视频在线| 亚洲第一狼人社区| 精品无人区卡一卡二卡三乱码免费卡 | 91精品久久久久久蜜臀| 日本丰满少妇一区二区三区| 91黄色激情网站| 精品视频在线免费观看| 欧美日韩卡一卡二| 欧美一卡二卡三卡| 久久影院视频免费| 亚洲人成精品久久久久久 | 亚洲激情av在线| 午夜精品在线看| 久草精品在线观看| 国产成人在线观看免费网站| av电影在线观看一区| 欧美岛国在线观看| 亚洲欧美影音先锋| 日韩电影在线观看网站| 成人三级在线视频| 欧美精品123区| 国产欧美日韩精品在线| 亚洲国产wwwccc36天堂| 国产老肥熟一区二区三区| 欧美日韩一区不卡| 国产欧美日韩在线| 欧美aaaaaa午夜精品| 91欧美一区二区| 久久久久亚洲蜜桃| 石原莉奈在线亚洲二区| 91亚洲精华国产精华精华液| 日韩三级视频中文字幕| 亚洲欧美日韩在线| 国产精品亚洲视频| 日韩一区二区在线观看视频 | 欧美猛男超大videosgay| 国产日韩精品一区| 蜜桃精品视频在线观看| 91成人在线免费观看| 中国色在线观看另类| 老司机午夜精品| 91精选在线观看| 亚洲一级在线观看| 99精品黄色片免费大全| 久久久久久久久久久电影| 天堂久久久久va久久久久| 色呦呦一区二区三区| 国产精品每日更新在线播放网址| 久久精品二区亚洲w码| 欧美美女喷水视频| 亚洲裸体在线观看| caoporm超碰国产精品| 国产亚洲一区二区在线观看| 麻豆国产欧美日韩综合精品二区| 欧美亚洲丝袜传媒另类| 亚洲一区在线看| 日本高清不卡aⅴ免费网站| 亚洲柠檬福利资源导航| 成人国产精品免费观看| 国产精品理伦片| 99久久伊人久久99| 国产精品麻豆一区二区| 成人国产在线观看| 国产精品久久久久久久久久久免费看 | 欧美精品在欧美一区二区少妇| 一区二区三区四区乱视频| 一本大道久久a久久精品综合| 日韩理论在线观看| 91亚洲大成网污www| 玉足女爽爽91| 欧美日韩免费一区二区三区视频| 一区二区三区电影在线播| 欧洲中文字幕精品| 亚洲成a人v欧美综合天堂下载| 欧美欧美欧美欧美| 蜜臀av性久久久久蜜臀av麻豆| 精品蜜桃在线看| 国产成人精品午夜视频免费| 欧美国产日本韩| 99精品久久只有精品| 亚洲国产精品麻豆| 欧美一区二区在线播放| 久久97超碰国产精品超碰| 精品av久久707| 不卡在线观看av| 亚洲尤物视频在线| 日韩一区二区高清| 国产精品123| 亚洲一区二区欧美激情| 91精品黄色片免费大全| 国产在线不卡视频| 亚洲激情一二三区| 日韩视频一区二区在线观看| 成人一区二区视频| 香蕉乱码成人久久天堂爱免费| 精品久久国产老人久久综合| va亚洲va日韩不卡在线观看|