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

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

?? evaluation.java

?? Java五子棋 支持本地游戲
?? JAVA
字號:
/**
 * 
 * This class evaluates the situation of the board 
 *
 */
class Evaluation
{
	int size;

	static final int sTwo = 0;
	static final int sThree = 1;
	static final int sFour = 2;
	static final int two = 3;
	static final int three= 4;
	static final int four = 5;
	static final int five = 6;
	
	//array records the count of the above kind
	int[] blackTypeCount = new int[8];
	int[] whiteTypeCount = new int[8];
	//the two dimension array records the position weight
	public static int[][] posValue;
	
	/**
	 * 
	 * @param mapSize	the size of the board
	 */
	Evaluation(int mapSize)
	{
		size = mapSize;
		posValue = new int[mapSize][mapSize];
		
		//initialize the position weight
		int edge = size - 1;
		for(int i = 0; i < size; i++)
			for(int j = 0; j < size; j++)
			{
				int a = (i > edge - i)?(edge - i):i;
				int b = (j > edge - j)?(edge - j):j;
				posValue[i][j] = (a > b)?b:a;
			}
		
		return;
	}
	
	/**
	 *This method evaluate the board and return a score, if it's a white turn, it'll return
	 *-score, else return score. score will be large if the situation is better for the black
	 *and vice versa
	 * 
	 * @param board				the board information
	 * @param isWhiteTurn		whether the next turn is white
	 * @return 					the score of the board
	 */
	int evaluate(ChessMan[][] board, boolean isWhiteTurn)
	{
		for(int i = 0; i < 8; i++)
		{	
			blackTypeCount[i] = 0;
			whiteTypeCount[i] = 0;
		}
		this.analysisBoard(board);
		int score = 0;
		
		//多個沖四相當與一個活四
		if (whiteTypeCount[sFour] > 1)
			whiteTypeCount[four]++;

		if (blackTypeCount[sFour] > 1)
			blackTypeCount[four]++;

		//computes the white value and the black value
		int WValue = 0, BValue = 0;
		if (isWhiteTurn)
		{
			if (blackTypeCount[five] > 0)
			{	
				BValue = 9999;
			}
			else if (whiteTypeCount[five] > 0)
			{	
				WValue = 9999;
			}
			//white wins
			else if (whiteTypeCount[four] > 0 || whiteTypeCount[sFour] > 0)
			{
				WValue = 9990;
			}
			//black wins
			else if (blackTypeCount[four] > 0)
			{
				BValue = 9970;
			}
			//black wins
			else if (blackTypeCount[sFour] > 0 && blackTypeCount[three] > 0)
			{
				BValue = 9960;
			}
			//white wins
			else if (whiteTypeCount[three] > 0 && blackTypeCount[sFour] == 0)
			{
				WValue = 9950;
			}
			//black wins
			else if (blackTypeCount[three] > 1 && 
				whiteTypeCount[three] == 0 &&
				whiteTypeCount[sThree] == 0)
			{
				BValue = 9940;
			}
			else {
			//calculates the respective value of black and white
			if (whiteTypeCount[three] > 1)
				WValue += 2000;
			else
			{
				if (whiteTypeCount[three] > 0)
					WValue += 200;
			}

			if (blackTypeCount[three] > 1)
				BValue += 1000;
			else
			{
				if (blackTypeCount[three] > 0)
					BValue += 100;
			}

			if (whiteTypeCount[sThree] > 0)
				WValue += whiteTypeCount[sThree]*10;

			if (blackTypeCount[sThree] > 0)
				BValue += blackTypeCount[sThree]*10;

			if (whiteTypeCount[two] > 0)
				WValue += whiteTypeCount[two]*4;

			if (blackTypeCount[two] > 0)
				BValue += blackTypeCount[two]*4;

			if (whiteTypeCount[sTwo] > 0)
				WValue += whiteTypeCount[sTwo];

			if (blackTypeCount[sTwo] > 0)
				BValue += blackTypeCount[sTwo];
			}
		}
		else
		{
			//the following is similar to the above
			if (whiteTypeCount[five] > 0)
			{	
				WValue = 9999;
			}
			else if(blackTypeCount[five] > 0)
			{	
				BValue = 9999;
			}
			else if (blackTypeCount[four] > 0 || blackTypeCount[sFour] > 0)
			{
				BValue = 9990;
			}

			else if (whiteTypeCount[four] > 0)
			{
				WValue = 9970;
			}
			else if (whiteTypeCount[sFour] > 0 && whiteTypeCount[three] > 0)
			{
				WValue = 9960;
			}
			else if (blackTypeCount[three] > 0 && whiteTypeCount[sFour] == 0)
			{
				BValue = 9950;
			}
			else if (whiteTypeCount[three] > 1 && 
				blackTypeCount[three] == 0 &&
				blackTypeCount[sThree] == 0)
			{
				WValue = 9940;
			}
			else {

			if (blackTypeCount[three] > 1)
				BValue += 2000;
			else{
				if (blackTypeCount[three] > 0)
					BValue += 200;
			}

			if (whiteTypeCount[three] > 1)
				WValue += 1000;
			else{
				if (whiteTypeCount[three] > 0)
					WValue += 100;
			}

			if (whiteTypeCount[sThree] > 0)
				WValue += whiteTypeCount[sThree]*10;

			if (blackTypeCount[sThree] > 0)
				BValue += blackTypeCount[sThree]*10;

			if (whiteTypeCount[two] > 0)
				WValue += whiteTypeCount[two]*4;

			if (blackTypeCount[two] > 0)
				BValue += blackTypeCount[two]*4;

			if (whiteTypeCount[sTwo] > 0)
				WValue += whiteTypeCount[sTwo];

			if (blackTypeCount[sTwo] > 0)
				BValue += blackTypeCount[sTwo];
			}
		}
		for (int i = 0; i < size; i++)
			for (int j = 0; j < size; j++)
			{
				ChessMan tmp = board[i][j];
				if (tmp != ChessMan.Empty)
				{
					if (tmp == ChessMan.Black)
						 BValue += posValue[i][j];
					else
						 WValue += posValue[i][j];
				}
			}			
		score = BValue - WValue;
		
		return score;
	}
	
	/**
	 * this method analysis the board and find out the FIVEs, FOURs and THREEs and etc
	 * 
	 * @param board		the board to be analysised
	 */
	void analysisBoard(ChessMan[][] board)
	{
		ChessMan[] line = new ChessMan[size];
		
		//the horizontal direction
		for(int i = 0; i < size; i++)
			analysisLine(board[i], size);
		
/*		System.out.println("水平");
		for(int i = 0; i < 8; i++)
			System.out.print(blackTypeCount[i] + " ");
		
		System.out.println();
		for(int i = 0; i < 8; i++)
			System.out.print(whiteTypeCount[i] + " ");		
		System.out.println();*/
		
		//the vertical direction
		for(int i = 0; i < size; i++)
		{
			for(int j = 0; j < size; j++)
				line[j] = board[j][i];
			analysisLine(line, size);
		}
		
		
/*		System.out.println();
		for(int i = 0; i < 8; i++)
			System.out.print(blackTypeCount[i] + " ");
		
		System.out.println("豎直");
		for(int i = 0; i < 8; i++)
			System.out.print(whiteTypeCount[i] + " ");	
		System.out.println();*/
		
		//the north east direction
		for(int k = 0; k <= 2 * size - 2; k++)
		{
			int n = 0;
			for(int i = 0; i <= k; i++)
			{
				int j = k - i;
				if(j >= size || i >= size)
					continue;
				line[n++] = board[i][j];
			}
			analysisLine(line, size);
		}
		
/*		System.out.println("右上");
		for(int i = 0; i < 8; i++)
			System.out.print(blackTypeCount[i] + " ");
		
		System.out.println();
		for(int i = 0; i < 8; i++)
			System.out.print(whiteTypeCount[i] + " ");	
		System.out.println();
*/		
		//the north west direction
		for(int k = 0; k < size; k++)
		{
			int n = 0;
			for(int i = 0; i < size - k; i++)
			{	
				line[n++] = board[i][i + k];
			}
			analysisLine(line, n);
		}
		
		for(int k = 1; k < size; k++)
		{
			int n = 0;
			for(int i = k; i < size; i++)
			{	
				line[n++] = board[i][i - k];
			}
			
			analysisLine(line, n);
		}		
		
/*		System.out.println("右下");
		for(int i = 0; i < 8; i++)
			System.out.print(blackTypeCount[i] + " ");
		
		System.out.println();
		for(int i = 0; i < 8; i++)
			System.out.print(whiteTypeCount[i] + " ");
*/
	}
	
	/**
	 * this method analysis one line, and finds out how many FIVEs FOURs THREEs of each side 
	 * 
	 * @param line		array stores the line
	 * @param end		the length of the array
	 */
	void analysisLine(ChessMan[] line, int end)
	{
		int i = 0;
		int j = 0;
		int k = 0;
		int bitLine = 0;
		ChessMan oldChess = ChessMan.Empty;
		ChessMan lastChess = ChessMan.Empty;
		
		//divide this line into several segments of different chess color
		//and analysis them respectively 
		while(i < end)
		{
			ChessMan curChess = line[i];
			boolean isOldEmpty = (oldChess == ChessMan.Empty);
			boolean isCurEmpty = (curChess == ChessMan.Empty);
			boolean isCurEqOld = (oldChess == curChess);
			
			//finds out the latest change in chess
			if(!isOldEmpty && curChess != lastChess && lastChess == oldChess)
			{
				k = i;
				//System.out.println("k:" + k);
			}
			
			if(!isCurEmpty)
				bitLine |=  1<<i;
			
			if(isOldEmpty)
			{
				if(!isCurEmpty)
					oldChess = curChess;
			}
			else if(!isCurEqOld && !isCurEmpty)
			{
				analysisChess(bitLine, j, i, oldChess);
				oldChess = curChess;
				j = k;
			}
			lastChess = curChess;
			i++;
		}
		//analysis the last segment
		analysisChess(bitLine, j, size, oldChess);		
		
	}
	
	/**
	 * this method uses bit comparison to find how many FIVEs FOURs THREEs TWOs in a single
	 * segment
	 * 
	 * @param bitLine	one integer value records the bit information of the segment
	 * @param start		the start bit number
	 * @param end		the end bit number
	 * @param c			the chess color the this segment
	 */
	void analysisChess(int bitLine, int start, int end, ChessMan c)
	{
		//System.out.println("start:" + start + "  end:" + end + "  Line:" + bitLine);

		int length = end - start;		
		if(length < 5)
			return;

		int line = bitLine >> start;
		int[] typeCount;
		//System.out.println("line:" + line);
		
		if(c == ChessMan.Black)
			typeCount = blackTypeCount;
		else
			typeCount = whiteTypeCount;
		
		int tmpLine = line;
		for(int i = 0; i <= length - 5; i++)
		{
			int tmp = tmpLine & 0x1f;
			//System.out.println("tmp:" + tmp);

			switch(tmp)
			{
			//五連11111b
			case 0x1f: typeCount[five]++; return;
			//沖四11011b
			case 0x1b: typeCount[sFour]++; break;
			//眠三10011b, 10101b, 11001b
			case 0x13: case 0x15: case 0x19: typeCount[sThree]++; break;
			//眠二10001
			case 0x11: typeCount[sTwo]++; break;
			default: break;
			}
			
			tmpLine >>= 1;
		}
		
		tmpLine = line;
		for(int i = 0; i <= length - 6; i++)
		{
			int tmp = tmpLine & 0x3f;
			//System.out.println("tmp:" + tmp);

			switch(tmp)
			{
			//活四011110b
			case 0x1e: typeCount[four]++; break;
			//活三011010b, 010110b
			case 0x1a: case 0x16: typeCount[three]++; break;
			//活二010010b, 001100b
			case 0x12: case 0xc: typeCount[two]++; break;
			default: break;
			}
			
			tmpLine >>= 1;
		}
		
		tmpLine = line;
		for(int i = 0; i <= length - 7; i++)
		{
			//mask:0111110
			int tmp = tmpLine & 0x3e;
			//System.out.println("tmp:" + tmp);

			//活三:X01110Y
			if(tmp == 0x1c)
			{
				//活三:X 或 Y 等于 0
				if(((tmpLine & 0x1) == 0) || ((tmpLine & 0x40) == 0))
					typeCount[three]++;
			}
			
			//活二:X01010Y
			if(tmp == 0x14)
			{
				//活二:X 或 Y 等于 0
				if(((tmpLine & 0x1) == 0) || ((tmpLine & 0x40) == 0))
					typeCount[two]++;
			}
			
			//mask:0011100
			tmp = tmpLine & 0x1c;
			//沖四:XY101ZW
			if(tmp == 0x14)
			{
				//沖四:XY 等于 11 且 Z 等于 0 或 ZW 等于 11 且 Y 等于 0
				if(((tmpLine & 0x62) == 0x60) || ((tmpLine & 0x23) == 0x3))
					typeCount[sFour]++;
			}
			
			tmpLine >>= 1;
		}
		
		tmpLine = line;
		for(int i = 0; i <= length - 8; i++)
		{
			//mask:00111100
			int tmp = tmpLine & 0x3c;

			//活二:XY0110ZW
			if(tmp == 0x18)
			{
				//活二:XY 等于 0 且 ZW 不等于 0 或 ZW 等于 0 且 XY 不等于 0
				int XY = tmpLine & 0xc0;
				int ZW = tmpLine & 0x3;
				if(((XY == 0) && (ZW != 0)) || ((ZW == 0) && (XY != 0)))
					typeCount[two]++;
			}
			
			tmpLine >>= 1;
		}
		
		//取尾部五位
		int suffix = line & 0x1f;
		//System.out.println("suffix:" + suffix);
		
		switch(suffix)
		{
		//沖四01111, 11101
		case 0xf: case 0x1d: typeCount[sFour]++; break;
		//眠三01011,眠三01101,眠三00111
		case 0xb: case 0xd: case 0x7: typeCount[sThree]++; break;
		//眠二00011,00101,01001
		case 0x3: case 0x5: case 01001: typeCount[sTwo]++; break;
		default: break;
		}
		
		int prefix = (line >> (length - 5)) & 0x1f;
		//System.out.println("prefix:" + prefix);
		
		switch(prefix)
		{
		//沖四11110, 10111
		case 0x1e: case 0x17: typeCount[sFour]++; break;
		//眠三11010,眠三10110,眠三11100
		case 0x1a: case 0x16: case 0x1c: typeCount[sThree]++; break;
		//眠二11000,10100,10010
		case 0x18: case 0x14: case 0x12: typeCount[sTwo]++; break;
		default: break;
		}
		
		if(length >= 6)
		{
			//取尾部六位111111
			suffix = line & 0x3f;
			//System.out.println("suffix:" + suffix);
			
			switch(suffix)
			{
			//活三001110
			case 0xe: typeCount[three]++; break;
			//活二001010, 000110
			case 0xa: case 0x6: typeCount[two]++; break;
			default: break;
			}
			
			prefix = (line >> (length - 6)) & 0x3f;
			
			switch(prefix)
			{
			//活三011100
			case 0x1c: typeCount[three]++; break;
			//活二010100, 011000
			case 0x14: case 0x18: typeCount[two]++; break;
			default: break;
			}
		}
		
/*		for(int i = 0; i < 8; i++)
			System.out.print(typeCount[i] + " ");
		System.out.println();*/
	}
	
/*	public static void main(String[] args)
	{
		Evaluation e = new Evaluation(15);
		ChessMan[][] board = new ChessMan[15][15];
		
		e.analysisChess(52, 0, 15, ChessMan.Black);
		
		System.exit(0);
	}*/
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美电影免费观看高清完整版在线观看| 免费在线欧美视频| 成人黄页毛片网站| 亚洲欧美综合网| av在线不卡网| 亚洲综合色婷婷| 欧美视频完全免费看| 性感美女久久精品| 日韩亚洲电影在线| 国产精品一区三区| 国产精品久久福利| 在线观看免费成人| 日本不卡视频在线| 国产欧美日韩另类一区| 欧美日韩精品欧美日韩精品 | 中文在线资源观看网站视频免费不卡| 丰满亚洲少妇av| 最新热久久免费视频| 欧美艳星brazzers| 久久精品国产久精国产| 中文欧美字幕免费| 欧美天堂亚洲电影院在线播放| 日韩高清一区二区| 国产欧美一区视频| 欧美亚洲综合一区| 国产精品 欧美精品| 亚洲欧美偷拍卡通变态| 91麻豆精品国产自产在线| 国产麻豆欧美日韩一区| 亚洲中国最大av网站| 精品国产成人系列| 色天天综合久久久久综合片| 久久国产精品99精品国产| 国产精品第一页第二页第三页| 欧美精品第1页| 成人av资源站| 蜜臀av性久久久久蜜臀av麻豆| 国产精品久久久久久久久动漫| 欧美日韩国产精品自在自线| 国产精品亚洲人在线观看| 亚洲国产欧美一区二区三区丁香婷| 精品成人在线观看| 欧美色综合网站| 成人高清av在线| 麻豆精品新av中文字幕| 亚洲精品亚洲人成人网| 久久久一区二区三区| 欧美日本一区二区三区| av电影一区二区| 国产一区二区不卡在线 | 久久蜜桃av一区二区天堂| 欧美性受xxxx黑人xyx性爽| 国产成人精品免费视频网站| 视频一区免费在线观看| 亚洲欧美日韩中文播放| 久久久久久亚洲综合| 欧美精品一级二级三级| 色猫猫国产区一区二在线视频| 国产成人精品综合在线观看| 久久99久久久久| 日韩福利视频网| 亚洲国产综合色| 一区二区三区在线免费视频| 国产精品免费免费| 久久久久久久一区| 精品成人一区二区三区四区| 日韩欧美中文一区| 制服丝袜中文字幕一区| 欧美日韩另类一区| 欧美色图天堂网| 在线精品视频免费播放| 91啪亚洲精品| 色综合久久综合网97色综合| 97久久精品人人做人人爽| 成人理论电影网| 成人av中文字幕| 成人97人人超碰人人99| 日本道色综合久久| 色呦呦网站一区| 日本电影亚洲天堂一区| 在线观看免费亚洲| 欧美精品 日韩| 日韩欧美的一区二区| 欧美一级片在线看| 欧美r级电影在线观看| 欧美精品一区二区三区在线 | 亚洲国产cao| 视频在线观看91| 奇米888四色在线精品| 美女免费视频一区| 久久激五月天综合精品| 国产麻豆成人精品| av动漫一区二区| 欧美日韩夫妻久久| 日韩久久精品一区| 亚洲国产成人私人影院tom| 国产精品久久久久久户外露出 | 欧美国产欧美综合| 自拍偷拍国产亚洲| 亚洲1区2区3区视频| 日韩福利视频网| 国产成a人亚洲| 91视频一区二区三区| 在线视频一区二区三| 欧美一区二区三区视频免费播放| 日韩写真欧美这视频| 国产精品每日更新在线播放网址| 亚洲欧美一区二区三区久本道91| 亚洲一区二区av电影| 久久99国产乱子伦精品免费| 成人永久免费视频| 欧美日韩在线直播| 国产亚洲一区字幕| 亚洲线精品一区二区三区八戒| 蜜臀va亚洲va欧美va天堂| 国产宾馆实践打屁股91| 欧美日韩精品一区视频| 久久久精品tv| 亚洲一区欧美一区| 久久91精品久久久久久秒播| 成人av电影免费在线播放| 欧美一区二区三区不卡| 亚洲欧美综合另类在线卡通| 午夜视频在线观看一区二区三区 | 天堂成人国产精品一区| 国产一区二区不卡老阿姨| 欧美最猛性xxxxx直播| 日韩一区二区三区在线观看| 综合久久综合久久| 麻豆国产欧美一区二区三区| 91免费观看视频| 精品国产乱码久久久久久久久 | 欧美成人免费网站| 一区二区三区四区高清精品免费观看 | 欧美中文字幕久久| 久久久91精品国产一区二区精品| 亚洲小说春色综合另类电影| 国产.欧美.日韩| 日韩欧美在线影院| 亚洲成av人在线观看| 91色porny在线视频| 国产清纯美女被跳蛋高潮一区二区久久w | 91精品国产综合久久香蕉麻豆| 亚洲国产精华液网站w| 蜜桃一区二区三区在线| 欧洲一区二区三区在线| 国产精品私房写真福利视频| 久久精品国产第一区二区三区| 欧美性欧美巨大黑白大战| 亚洲人成精品久久久久久| 国产成人亚洲精品狼色在线| 日韩视频国产视频| 亚洲福利国产精品| 欧美日韩亚洲综合在线| 亚洲欧洲精品成人久久奇米网 | 国产成人av资源| 亚洲精品在线电影| 国产综合成人久久大片91| 欧美一区二区三区色| 日韩精品免费专区| 欧美久久久久免费| 亚洲国产成人av好男人在线观看| 欧美伊人久久久久久久久影院| 亚洲精品中文在线| 91九色最新地址| 亚洲一区欧美一区| 欧美午夜精品久久久久久孕妇 | 亚洲成精国产精品女| 色综合天天综合网天天狠天天| 国产精品三级视频| 国产91在线|亚洲| 国产精品色噜噜| hitomi一区二区三区精品| 中文字幕欧美区| 成人动漫精品一区二区| 中文字幕一区二区三区在线观看| 懂色av中文字幕一区二区三区| 欧美激情一二三区| 99久久综合国产精品| 亚洲免费观看高清在线观看| 91亚洲国产成人精品一区二三 | 欧美猛男gaygay网站| 亚洲成人免费视| 欧美一区二区三区公司| 激情文学综合网| 欧美经典三级视频一区二区三区| 国产成人av电影| 亚洲人精品一区| 91精品欧美福利在线观看| 麻豆国产精品一区二区三区| 亚洲精品一区二区三区精华液| 国产成人免费视频网站高清观看视频| 国产视频一区在线观看| 欧美日韩在线综合| 精品一区二区在线看| 亚洲国产成人一区二区三区| 色域天天综合网| 精品无人码麻豆乱码1区2区| 欧美激情一区在线观看| 精品视频资源站|