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

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

?? c4board.java

?? source code about game desktop
?? JAVA
字號:
//C4Board.java


/** 
 *
 * @author  Sean Bridges
 * @version 1.0
 */

import java.util.Vector;

public final class C4Board implements Board 
{

//------------------------------------------
	//class variables
	public final static int NULL_PLAYER_NUMBER = -1;
	public final static int FIRST_PLAYER_NUMBER = 0;
	public final static int SECOND_PLAYER_NUMBER = 1;
	
	public static final int NUMBER_OF_ROWS = 6; //the height of the board
	public static final int NUMBER_OF_COLUMNS = 8;  //the width of the board
	public static final int NUMBER_OF_SLOTS = NUMBER_OF_ROWS * NUMBER_OF_COLUMNS;
	
	
//------------------------------------------
	//instance variables
	
	//slots are accessed by row * NUMBER_OF_COLUMNS + column,
	//where row and columnm start at 0
	private C4Slot[] slots;

	//store the number of chips in each column in an array.
	//this saves us from having to scan each column when making moves.
	//the max value for each column is NUMBER_OF_ROWS
	private int[] numberOfChipsInColumn = new int[NUMBER_OF_COLUMNS];

	//the move history, stored as an array of colummns
	//moveHistoryLength always points to the next free slot
	int moveHistoryLength = 0;
	int[] moveHistory = new int[NUMBER_OF_SLOTS];
	
	private C4Stats stats = new C4Stats();
	private Vector rows;

	
	//to avoid creating new arrays when getting all possible moves
	//we simply always return all the moves, instead of all the legal 
	//moves
	private Move[] firstPlayerMoves;
	private Move[] secondPlayerMoves;
	

//------------------------------------------
	//constructors
	
	/** Creates new C4Board */
	public C4Board(Player firstPlayer, Player secondPlayer) 
	{
		initSlots();
		
	    //create the moves arrays, these are all the possible moves
		firstPlayerMoves = new Move[NUMBER_OF_COLUMNS];
		secondPlayerMoves = new Move[NUMBER_OF_COLUMNS];
		
		for(int i = 0; i < NUMBER_OF_COLUMNS; i++)
		{
			firstPlayerMoves[i] = new C4Move(firstPlayer, i);
			secondPlayerMoves[i] = new C4Move(secondPlayer, i);
		}
		
		
		
	}//end constructor
  
//--------------------------------------
	//instance methods

//--------------------------------------
	//initializing

	/**
	 * Create the slots and organize them into rows
	 */
	private void initSlots()
	{
		slots = new C4Slot[NUMBER_OF_SLOTS];
		
		//create the slots
		for(int i = 0; i < NUMBER_OF_SLOTS; i++)
		{
			slots[i] = new C4Slot();
		}
		
		//create the rows
	
		rows = new Vector(84);	
		
		/*
		* choose all possible groups of 4 slots
		* a group of four is determined by 2 things, its starting position, and its slope.
		* the starting position is writen as (row,column), where row exists in the 
		* set {0,1,... numberOfRows - 1} and column lies in the set {0,1, ...number of columns -1}
		* the slope is written as <delRow, delColumn> where delRow and delColumn exist in the set {-1,0,1}
		*
		*
		* a group of four is valid and not repeated if 
		*   1) its starting and ending positions both lie inside the board.
		*   2) the slope is one of <1,0>, <1,1>, <0,1>, <-1, 1>
		*      ie it occupies the range 90 to -45 degrees.
		*	
		*
		* iterate for all possible groups of four, choose the valid ones
		* that are not repeated
		*/
		int totalNumber = 0;
		
		
		for(int row = 0; row <NUMBER_OF_ROWS; row++)
		{
			for(int column = 0; column < NUMBER_OF_COLUMNS; column++)
			{
				for(int delRow = -1; delRow <= 1; delRow++)
				{
					for(int delColumn = -1; delColumn <= 1; delColumn++)
					{
						if(
							( 
							((delRow == 1) && (delColumn == 0)) ||
							((delRow == 1) && (delColumn == 1)) ||
							((delRow == 0) && (delColumn == 1)) ||
							((delRow == -1) && (delColumn == 1))
							) &&
							(inbounds( row + (3*delRow), column + (3*delColumn) )) &&
							(inbounds(row,column))
						   
						   )
						{
							C4Row newRow = new C4Row(
												  getSlot(row,column),
												  getSlot(row + delRow,column + delColumn),
												  getSlot(row + (2 *delRow), column + (2 * delColumn)),
												  getSlot(row + (3 *delRow), column + (3 * delColumn)),
												  stats
												  );	
							rows.addElement(newRow);				
							
						}
						   
					}//end for delColumn
					
				}//end for delRow
														
				
			}//end for column
		}//end for row
	
	}
	
//--------------------------------------
	//slot access

	/**
	 * Returns the number of slots in a given column.
	 * column should be in 0..NUMBER_OF_COLUMNS -1 inclusive.
	 */
	public int numerOfChipsInColumn(int column)
	{
		return numberOfChipsInColumn[column];
	}
	
	/**
	 * Return wether or not the given row,column pair exists on the board.
	 * Row and columns are numbered starting at 0.
	 */
	private boolean inbounds(int row, int column)
	{
		return ((row >= 0) &&
			   (column >= 0) &&
			   (row < NUMBER_OF_ROWS) &&
			   (column < NUMBER_OF_COLUMNS));
	}
	
	/**
	 * Return the slot at the specified row and column.
	 */
	private C4Slot getSlot(int row, int column)
	{
		return getSlot((row * NUMBER_OF_COLUMNS) + column);
	}
	
	/**
	 * Access a slot by its row.
	 * the index should be equal to row * NUMBER_OF_COLUMNS + column,
	 * where row and column both start at 0
	 */
	private C4Slot getSlot(int index)
	{
		return slots[index];
	}

//--------------------------------------
	//restarting the game
	private void resetGame()
	{
		for(int i = 0; i < NUMBER_OF_SLOTS; i++)
		{
			if(slots[i].getContents() != NULL_PLAYER_NUMBER )
			{
				slots[i].setContents(NULL_PLAYER_NUMBER);
			}
		}
		
		for(int i = 0; i < NUMBER_OF_COLUMNS; i++)
		{
			numberOfChipsInColumn[i] = 0;
		}
		
		moveHistoryLength = 0;
	}
	
//-----------------------------------------
	//Board methods
	
	/**
	 * Return an object which can be interrogated to discover the current
	 * state of the game
	 */
	public BoardStats getBoardStats() 
	{
		return stats;
	}
	
	/**
	 * Try and make a move.
	 * Returns wether or not the move attempt was successful.
	 *
	 * m.toInt() should equal the column the player wants to move in.
	 * starting at 0.
	 */
	public boolean move(Move m) 
	{
		//System.out.println(m);
		int column = m.toInt();
		int columnCount = numberOfChipsInColumn[column];
		
		if(columnCount < NUMBER_OF_ROWS)
		{
			//make the move
			slots[(columnCount * NUMBER_OF_COLUMNS) + column].setContents(m.maker().getNumber());
			numberOfChipsInColumn[column] = columnCount + 1;
			
			//update the history
			moveHistory[moveHistoryLength] = column;
			moveHistoryLength++;
			return true;
		}
		else
		{
			return false;
		}
	}
	
	
	
	/** Undo the last move made.
	 */
	public void undoLastMove() 
	{
		//System.out.println("undoing last move");
		moveHistoryLength --;
		int column = moveHistory[moveHistoryLength];
		
		numberOfChipsInColumn[column]--;
		int row = numberOfChipsInColumn[column];
		
		slots[(row * NUMBER_OF_COLUMNS) + column].setContents(NULL_PLAYER_NUMBER);
		
	}
	
	/**
	 * Get the list of moves that are possible for the given
	 * player.
	 * For the C4Board this always returns the same array for each player.
	 * Some of the moves may not be legal, but the legal moves is a subset
	 * of the moves returned.
	 */
	public Move[] getPossibleMoves(Player aPlayer) 
	{
		/*
		 * We want to avoid creating new objects when communicating what moves 
		 * are allowed.
		 * To solve this we simply always return the same array when asked what
		 * moves are possible for a player.  Some of these moves may
		 * cause move() to return false.
		 */
		
		if(aPlayer.getNumber() == FIRST_PLAYER_NUMBER )
		{
			return firstPlayerMoves;
		}
		else
		{
			return secondPlayerMoves;
		}
	}
	
	/** Whether or not the game is over.
	 */
	public boolean isGameOver() 
	{
		//game over if someone has won or if all the slots are full.
		return( (moveHistoryLength == NUMBER_OF_SLOTS ) || stats.hasSomeoneWon());
		
	}
	
	/** Called by the game master when the game is started.
	 */
	public void gameStarted() 
	{
		resetGame();
	}
	/** Called by the game master when the game is restarted.
	 */
	public void gameRestarted() 
	{
		resetGame();
	}
	/** Called by the game master when the game is stopped.
	 */
	public void gameStoped() 
	{
		resetGame();
	}
	/** A board must be cloneable since a copy of it is sent
	 * to players when we ask them for their move.
	 */
	public Object clone() 
	{
		C4Board clone = null;
		
		try
		{
			clone = (C4Board) super.clone();
		}
		catch(CloneNotSupportedException e)
		{
			//we should never get here
			System.out.println(e);
		}

		
		clone.stats = new C4Stats();
		clone.numberOfChipsInColumn = (int[]) numberOfChipsInColumn.clone();		
		clone.moveHistory = (int[]) moveHistory.clone();
		
		clone.initSlots();

		for(int i = 0; i < NUMBER_OF_SLOTS; i++)
		{
			clone.slots[i].setContents( this.slots[i].getContents() );
		}
		
		return clone;
		
	}

//-------------------------------------------
	//printing
	
	public String toString()
	{
		StringBuffer buf = new StringBuffer();
		buf.append("|0|1|2|3|4|5|6|7|");
		for(int row = NUMBER_OF_ROWS - 1; row >= 0; row--)
		{
			buf.append("\n|");
			
			for(int column = 0; column < NUMBER_OF_COLUMNS; column++)
			{
				if( getSlot(row,column).getContents() == NULL_PLAYER_NUMBER)
				{
					buf.append(" ");
				}
				else
				{
					buf.append(getSlot(row,column).getContents() );
				}
				buf.append("|");
			}//end for column
		}//end for row
		
				
		
		return buf.toString();
	}

}//end class C4Board

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
...中文天堂在线一区| 亚洲一区二区三区不卡国产欧美| 99视频精品全部免费在线| 亚洲成a人v欧美综合天堂| 久久精品夜色噜噜亚洲aⅴ| 91论坛在线播放| 国产精品一二一区| 亚洲福中文字幕伊人影院| 国产欧美一区二区三区在线老狼| 精品视频一区 二区 三区| 不卡区在线中文字幕| 卡一卡二国产精品| 亚洲国产日韩在线一区模特| 久久精品亚洲国产奇米99| 6080日韩午夜伦伦午夜伦| 在线观看精品一区| 高清国产一区二区三区| 美女被吸乳得到大胸91| 午夜电影网一区| 亚洲精品高清视频在线观看| 国产精品美女久久久久aⅴ| 日韩亚洲欧美在线| 7777精品伊人久久久大香线蕉经典版下载 | 欧洲日韩一区二区三区| 国产·精品毛片| 精品一区二区综合| 免费人成黄页网站在线一区二区| 一区二区三区中文免费| 国产精品女人毛片| 国产精品网曝门| 国产欧美日韩视频一区二区| 欧美一区二区性放荡片| 欧美日本一区二区| 欧美三级电影一区| 色播五月激情综合网| 一本久久a久久免费精品不卡| 99综合影院在线| www.欧美色图| 99综合电影在线视频| 成人av动漫网站| 97se亚洲国产综合自在线观| a4yy欧美一区二区三区| eeuss影院一区二区三区| 99天天综合性| 色久优优欧美色久优优| 一本一道久久a久久精品综合蜜臀| 99精品久久99久久久久| 色吊一区二区三区| 欧美日韩成人综合天天影院| 在线91免费看| 欧美xxx久久| 国产亚洲自拍一区| 国产精品第一页第二页第三页| 中文字幕av一区 二区| 最好看的中文字幕久久| 亚洲精品欧美激情| 三级欧美在线一区| 美女视频黄久久| 国产精品一级二级三级| 99re热这里只有精品视频| 色妞www精品视频| 欧美裸体一区二区三区| 精品美女被调教视频大全网站| 久久欧美一区二区| 日韩一区日韩二区| 亚洲高清视频的网址| 麻豆91免费看| 从欧美一区二区三区| 色综合视频一区二区三区高清| 欧美日韩aaaaa| 国产日韩欧美高清| 亚洲一二三四在线观看| 麻豆免费看一区二区三区| 成人美女视频在线看| 欧美日韩中文另类| 精品国产sm最大网站| 亚洲精品免费在线| 日本不卡中文字幕| 成人性生交大合| 欧美日韩国产一二三| 久久蜜桃av一区精品变态类天堂| 亚洲精品久久久蜜桃| 激情综合网最新| 91久久精品一区二区二区| 精品国产乱子伦一区| 一区在线观看免费| 毛片不卡一区二区| 色综合天天综合网国产成人综合天 | 日本不卡视频一二三区| 国产1区2区3区精品美女| 欧美日韩日日骚| 国产精品久久福利| 久久国产精品99精品国产| 99久久99久久免费精品蜜臀| 日韩欧美一卡二卡| 亚洲美女免费在线| 国产黄人亚洲片| 欧美一区二区三区视频免费| 国产精品不卡一区| 麻豆精品精品国产自在97香蕉| 91美女在线看| 日本一区二区高清| 精品一区二区三区在线观看国产| 91丨九色丨国产丨porny| 精品蜜桃在线看| 天天色综合成人网| 一本色道亚洲精品aⅴ| 国产午夜亚洲精品不卡| 日本一不卡视频| 欧美日韩一级大片网址| 亚洲视频你懂的| 国产白丝精品91爽爽久久| 欧美大白屁股肥臀xxxxxx| 亚洲午夜在线视频| 色综合久久久久综合99| 国产日产欧美一区二区三区| 精品在线一区二区三区| 欧美一区二区免费观在线| 亚洲福利视频一区| 日本久久电影网| 成人免费在线视频| 处破女av一区二区| 亚洲精品在线免费播放| 麻豆精品一区二区| 欧美一二三区在线| 日韩av电影一区| 91精品一区二区三区在线观看| 亚洲一卡二卡三卡四卡无卡久久| 色综合一个色综合| 亚洲欧美激情视频在线观看一区二区三区 | 欧美日韩一区二区在线观看视频| 成人欧美一区二区三区视频网页| 岛国精品在线播放| 国产三级欧美三级| 国产91对白在线观看九色| 国产亚洲综合性久久久影院| 国产精品一级片| 日本一二三四高清不卡| 岛国一区二区三区| 亚洲天堂免费在线观看视频| 成人美女视频在线观看18| 国产精品麻豆视频| 91女厕偷拍女厕偷拍高清| 亚洲精品精品亚洲| 欧美亚洲禁片免费| 日本亚洲三级在线| 精品日韩欧美在线| 国产成人精品免费一区二区| 国产精品欧美久久久久一区二区| 成人18视频日本| 亚洲精品精品亚洲| 欧美精品一二三区| 蜜臀av性久久久久蜜臀aⅴ四虎 | 国产日韩欧美激情| 成人免费视频播放| 亚洲精品欧美激情| 在线播放日韩导航| 精品一区二区精品| 国产精品―色哟哟| 91在线视频官网| 视频一区二区中文字幕| 日韩美女在线视频| 成人黄色免费短视频| 亚洲精品你懂的| 日韩一区二区免费在线电影| 国产一区二区不卡在线| 最新中文字幕一区二区三区| 欧美日韩另类一区| 国产一区二区中文字幕| 日韩伦理av电影| 欧美一区二区日韩| 成人深夜在线观看| 午夜婷婷国产麻豆精品| 久久久亚洲精品一区二区三区| 99国产精品一区| 美女视频网站久久| 国产精品传媒在线| 日韩一卡二卡三卡四卡| 成人av资源网站| 日本视频免费一区| 中文字幕五月欧美| 日韩精品一区二区三区视频在线观看 | 欧美精品三级在线观看| 国产麻豆精品一区二区| 亚洲一区二区三区国产| 久久久国产精华| 欧美老肥妇做.爰bbww| 丰满少妇久久久久久久| 秋霞午夜av一区二区三区| 国产精品久久久久久久久搜平片 | 久久久亚洲国产美女国产盗摄 | 久久婷婷综合激情| 欧美性一级生活| 国产成人精品一区二| 亚洲成人777| 亚洲天堂久久久久久久| 亚洲精品一区二区三区精华液| 一本一本久久a久久精品综合麻豆| 九九九久久久精品| 亚洲成人7777|