Ejemplo n.º 1
0
 /// <summary>
 /// Creating of a hash table
 /// </summary>
 public HashTable()
 {
     list = new List[n];
     for (int i = 0; i < n; ++i)
     {
         list[i] = new List();
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Create new hash table
 /// </summary>
 public HashTable(int size, AbstractHashFunction function)
 {
     hashFunction = function;
     maxHash = size;
     hashTable = new List[maxHash];
     for (int i = 0; i < maxHash; ++i)
         hashTable[i] = new List();
 }
 public HashTable()
 {
     list = new List[hashConstant];
     for (int i = 0; i < hashConstant; ++i)
     {
         list[i] = new List();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Priority queue constructor; Throw OutOfPriorityNumberException() if maxPriority < 0
 /// </summary>
 public PriorityQueue(int maxPriority)
 {
     if (maxPriority < 0)
         throw new OutOfPriorityNumberException();
     list = new List[maxPriority];
     for (var i = 0; i < maxPriority; ++i)
         list[i] = new List();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates hashtable of empty elements.
 /// </summary>
 /// <param name="hashsize"></param>
 public HashTable(int hashsize)
 {
     table = new List[hashsize];
     for (int i = 0; i < hashsize; ++i)
         table[i] = new List();
     HashSize = hashsize;
     this.countHash = this.CalculateHash;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates new hashtable of empty elements, takes a function for the hash table.
 /// </summary>
 /// <param name="hashsize"></param>
 public HashTable(int hashsize, HashFunction CountHash)
 {
     table = new List[hashsize];
     for (int i = 0; i < hashsize; ++i)
         table[i] = new List();
     HashSize = hashsize;
     this.countHash = CountHash;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="size"></param>
 public HashTable(int size)
 {
     hashTableSize = size;
     hashTable = new List[hashTableSize];
     for (int i = 0; i < hashTableSize; ++i)
     {
         hashTable[i] = new List();
     }
 }
 public HashTable(IHash hash)
 {
     this.hash = hash;
     list = new List[hashConstant];
     for (int i = 0; i < hashConstant; ++i)
     {
         list[i] = new List();
     }
 }
Ejemplo n.º 9
0
 public HashTable(IHash hash)
 {
     list = new List[n];
     for (int i = 0; i < n; ++i)
     {
         list[i] = new List();
     }
     this.hash = hash;
 }
Ejemplo n.º 10
0
 public HashTable(int size)
 {
     hashData = new List[size];
     tableSize = size;
     for (int i = 0; i < size; ++i)
     {
         hashData[i] = new List();
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Class constructor
 /// </summary>
 /// <param name="size"></param>
 public HashTable(int size, IHashFunction hashFunction)
 {
     this.hashFunction = hashFunction;
     hashTableSize = size;
     hashTable = new List[hashTableSize];
     for (int i = 0; i < hashTableSize; ++i)
     {
         hashTable[i] = new List();
     }
 }
Ejemplo n.º 12
0
 public HashTable(int size, IHashFunction function)
 {
     this.size = size;
     this.array = new List[size];
     for (int i = 0; i < size; ++i)
     {
         this.array[i] = new List();
     }
     this.hashFunction = function;
 }
Ejemplo n.º 13
0
		private void addInfoToList(byte type, int info, int player)
		{
			if ( pos >= list.Length )
			{
				List[] list1 = list;

				list = new List[ list1.Length + 50 ];
				for ( int i = 0; i < list1.Length; i++ )
					list[ i ] = list1[ i ];
			}

			list[ pos ].type = type;
			list[ pos ].info = info;
			list[ pos ].player = (byte)player;
			pos++;
		}
Ejemplo n.º 14
0
 public Chunk(World world, int i, int j)
 {
     chunkTileEntityMap = new HashMap();
     entities = new List[8];
     isTerrainPopulated = false;
     isModified = false;
     hasEntities = false;
     lastSaveTime = 0L;
     worldObj = world;
     xPosition = i;
     zPosition = j;
     heightMap = new byte[256];
     for (int k = 0; k < entities.Length; k++)
     {
         entities[k] = new ArrayList();
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Create new hash table
 /// </summary>
 public HashTable()
 {
     hashTable = new List[maxHash];
     for (int i = 0; i < maxHash; ++i)
         hashTable[i] = new List();
 }
Ejemplo n.º 16
0
		public negoList( byte[] Players )
		{
			players = Players;

			wiw = new int[ 2 ];
			for ( int p = 0; p < 2; p ++ )
				wiw[ p ] = ai.whoIsWinning( players[ p ], players[ ( p + 1 ) % 2 ] );

			list = new List[ 100 ]; 
			pos = 0; 

	#region bi

			#region Politic treaty

			int pb = 2;
			bool piw = false;

			if ( wiw[ 0 ] > 9 )
				piw = true;

			if ( Form1.game.playerList[ players[ 0 ] ].foreignRelation[ players[ 1 ] ].politic == (byte)Form1.relationPolType.peace )
			{
				addInfoToList( (byte)nego.infoType.politicTreaty, (byte)Form1.relationPolType.alliance, pb );
				if ( !piw )
					addInfoToList( (byte)nego.infoType.politicTreaty, (byte)Form1.relationPolType.Protected, pb );
				else
					addInfoToList( (byte)nego.infoType.politicTreaty, (byte)Form1.relationPolType.Protector, pb );
			}
			else if ( Form1.game.playerList[ players[ 0 ] ].foreignRelation[ players[ 1 ] ].politic == (byte)Form1.relationPolType.ceaseFire )
			{
				addInfoToList( (byte)nego.infoType.politicTreaty, (byte)Form1.relationPolType.peace, pb );
			}
			else if ( Form1.game.playerList[ players[ 0 ] ].foreignRelation[ players[ 1 ] ].politic == (byte)Form1.relationPolType.war )
			{  // cease fire est nécessaire pour négocier des ententes d alliances
				addInfoToList( (byte)nego.infoType.politicTreaty, (byte)Form1.relationPolType.ceaseFire, pb );
				list[ pos - 1 ].cantBeRemoved = true;
				list[ pos - 1 ].accepted = true;
			}
			else if ( Form1.game.playerList[ players[ 0 ] ].foreignRelation[ players[ 1 ] ].politic == (byte)Form1.relationPolType.alliance )
			{
			}
			else if ( Form1.game.playerList[ players[ 0 ] ].foreignRelation[ players[ 1 ] ].politic == (byte)Form1.relationPolType.Protector )
			{
			}
			else if ( Form1.game.playerList[ players[ 0 ] ].foreignRelation[ players[ 1 ] ].politic == (byte)Form1.relationPolType.Protected )
			{
			}

		#endregion

			// break alliance
			for ( int p = 0; p < Form1.game.playerList.Length; p++ )
				if ( 
					p != players[ 0 ] &&
					p != players[ 1 ] &&
					!Form1.game.playerList[ p ].dead &&
					Form1.game.playerList[ players[ 0 ] ].foreignRelation[ p ].madeContact && 
						Form1.game.playerList[ players[ 1 ] ].foreignRelation[ p ].madeContact && 
						( Form1.game.playerList[ players[ 0 ] ].foreignRelation[ p ].politic == (byte)Form1.relationPolType.alliance || Form1.game.playerList[ players[ 1 ] ].foreignRelation[ p ].politic == (byte)Form1.relationPolType.alliance ) )
					addInfoToList( (byte)nego.infoType.breakAllianceWith, p, pb );

			// war on
			for ( int p = 0; p < Form1.game.playerList.Length; p++ )
				if ( 
					p != players[ 0 ] &&
					p != players[ 1 ] &&
					!Form1.game.playerList[ p ].dead &&
					Form1.game.playerList[ players[ 0 ] ].foreignRelation[ p ].madeContact && Form1.game.playerList[ players[ 1 ] ].foreignRelation[ p ].madeContact && ( Form1.game.playerList[ players[ 0 ] ].foreignRelation[ p ].politic != (byte)Form1.relationPolType.war || Form1.game.playerList[ players[ 1 ] ].foreignRelation[ p ].politic != (byte)Form1.relationPolType.war ) )
					addInfoToList( (byte)nego.infoType.warOn, p, pb );

			// embargo on

			// vote

#endregion

	#region uni

			for ( pb = 0; pb < 2; pb++ )
			{
				int player = players[ pb ];
				bool[] region = new bool[ Form1.game.playerList.Length ];

				// cities
				for ( int c = 1; c <= Form1.game.playerList[ players[ pb ] ].cityNumber; c++ )
					if ( Form1.game.playerList[ players[ pb ] ].cityList[ c ].state != (byte)enums.cityState.dead && !Form1.game.playerList[ players[ pb ] ].cityList[ c ].isCapitale )
					{
						addInfoToList( (byte)nego.infoType.giveCity, c, pb );

						if ( Form1.game.playerList[ players[ pb ] ].cityList[ c ].originalOwner != player )
							region[ Form1.game.playerList[ players[ pb ] ].cityList[ c ].originalOwner ] = true;
					}

				// regions
				for ( int r = 0; r < Form1.game.playerList.Length; r++ )
					if ( region[ r ] )
						addInfoToList( (byte)nego.infoType.giveRegion, r, pb );

				// technos
				for ( int t = 0; t < Form1.game.playerList[ players[ pb ] ].technos.Length; t++ )
					if ( Form1.game.playerList[ players[ pb ] ].technos[ t ].researched && !Form1.game.playerList[ players[ (pb+1)%2 ] ].technos[ t ].researched )
						addInfoToList( (byte)nego.infoType.giveTechno, t, pb );

				// contact with
				for ( int p = 0; p < Form1.game.playerList.Length; p++ )
					if ( 
						p != players[ 0 ] &&
						p != players[ 1 ] &&
						!Form1.game.playerList[ p ].dead &&
						Form1.game.playerList[ players[ pb ] ].foreignRelation[ p ].madeContact && 
						!Form1.game.playerList[ players[ (pb+1)%2 ] ].foreignRelation[ p ].madeContact 
						)
						addInfoToList( (byte)nego.infoType.giveContactWith, p, pb );

				// maps
				if ( Form1.game.playerList[ players[ pb ] ].technos[ (byte)Form1.technoList.mapMaking ].researched )
				{
					addInfoToList( (byte)nego.infoType.giveMap, 0, pb );
					addInfoToList( (byte)nego.infoType.giveMap, 1, pb );
				}

				// resources
				for ( int r = 0; r < Statistics.resources.Length; r ++ )
					if ( 
						Form1.game.playerList[ players[ pb ] ].hasAccessToResources( r ) && !Form1.game.playerList[ players[ ( pb + 1 ) % 2 ] ].hasAccessToResources( r ) && 
						Form1.game.playerList[ players[ pb ] ].technos[ Statistics.resources[ r ].techno ].researched && Form1.game.playerList[ players[ ( pb + 1 ) % 2 ] ].technos[ Statistics.resources[ r ].techno ].researched
						)
						addInfoToList( (byte)nego.infoType.giveResource, r, pb ); 
/*
				// money
				if ( Form1.game.playerList[ players[ 0 ] ].money > 0 )
					addInfoToList( (byte)nego.infoType.giveMoney, (int)Form1.game.playerList[ players[ 0 ] ].money, pb );

				// money per turn
				if ( Form1.game.playerList[ players[ 0 ] ].totalTrade * Form1.game.playerList[ players[ 0 ] ].preferences.reserve / 100 > 0 )
					addInfoToList( (byte)nego.infoType.giveMoneyPerTurn, Form1.game.playerList[ players[ 0 ] ].totalTrade * Form1.game.playerList[ players[ 0 ] ].preferences.reserve / 100, pb );

				// % per turn
				if ( Form1.game.playerList[ players[ 0 ] ].preferences.reserve > 0 )
					addInfoToList( (byte)nego.infoType.givePercBrut, Form1.game.playerList[ players[ 0 ] ].preferences.reserve, pb );
*/
				// threats
			//	addInfoToList( (byte)nego.infoType.threat, Form1.game.playerList[ players[ pb ] ].preferences.reserve, pb );
			}

	#endregion

			List[] list1 = list;
			list = new List[ pos ];

			for ( int i = 0; i < list.Length; i ++ )
				list[ i ] = list1[ i ];

	#region set conflicts
			for ( int i = 0; i < list.Length; i ++ )
			{
				if ( list[ i ].type == (byte)nego.infoType.giveMap )
				{
					list[ i ].conflict = new int[ 1 ];
					for ( int j = 0; j < list.Length; j ++ )
						if ( i != j && list[ j ].type == (byte)nego.infoType.giveMap && list[ i ].player == list[ j ].player )
							list[ i ].conflict[ 0 ] = j;
				}
				else if ( list[ i ].type == (byte)nego.infoType.politicTreaty )
				{
					int tot = 0;

					for ( int j = 0; j < list.Length; j ++ )
						if ( i != j && list[ j ].type == (byte)nego.infoType.politicTreaty )
							tot++;

					list[ i ].conflict = new int[ tot ];
					for ( int j = 0, k = 0; j < list.Length; j ++ )
						if ( i != j && list[ j ].type == (byte)nego.infoType.politicTreaty )
							list[ i ].conflict[ k ] = j;
				}
				else if ( list[ i ].type == (byte)nego.infoType.economicTreaty )
				{
					int tot = 0;

					for ( int j = 0; j < list.Length; j++ )
						if ( i != j && list[ j ].type == (byte)nego.infoType.economicTreaty )
							tot++;

					list[ i ].conflict = new int[ tot ];
					for ( int j = 0, k = 0; j < list.Length; j++ )
						if ( i != j && list[ j ].type == (byte)nego.infoType.economicTreaty )
						{
							list[ i ].conflict[ k ] = j;
							k++;
						}
				}
				else if ( list[ i ].type == (byte)nego.infoType.giveRegion )
				{
					int tot = 0;
					for ( int j = 0; j < list.Length; j++ )
						if (
							i != j && 
							list[ j ].type == (byte)nego.infoType.giveCity && 
							list[ i ].player == list[ j ].player &&
							Form1.game.playerList[ players[ list[ i ].player ] ].cityList[ list[ j ].info ].originalOwner == list[ i ].info
							)
							tot++;

					list[ i ].conflict = new int[ tot ];
					for ( int j = 0, k = 0; j < list.Length; j++ )
						if (
							i != j && 
							list[ j ].type == (byte)nego.infoType.giveCity && 
							list[ i ].player == list[ j ].player &&
							Form1.game.playerList[ players[ list[ i ].player ] ].cityList[ list[ j ].info ].originalOwner == list[ i ].info
							)
						{
							list[ i ].conflict[ k ] = j;
							k++;

							list[ j ].conflict = new int[ 1 ];
							list[ j ].conflict[ 0 ] = i;
						}
				}
				else if ( 
					list[ i ].type == (byte)nego.infoType.warOn || 
					list[ i ].type == (byte)nego.infoType.breakAllianceWith || 
					list[ i ].type == (byte)nego.infoType.embargoOn 
					)
				{
					int tot = 0;

					for ( int j = 0; j < list.Length; j++ )
						if ( 
							i != j &&
							(
								list[ j ].type == (byte)nego.infoType.warOn || 
								list[ j ].type == (byte)nego.infoType.breakAllianceWith || 
								list[ j ].type == (byte)nego.infoType.embargoOn 
							) &&
							list[ j ].info == list[ i ].info
							)
							tot++;

					list[ i ].conflict = new int[ tot ];
					for ( int j = 0, k = 0; j < list.Length; j++ )
						if ( 
							i != j &&
							(
								list[ j ].type == (byte)nego.infoType.warOn || 
								list[ j ].type == (byte)nego.infoType.breakAllianceWith || 
								list[ j ].type == (byte)nego.infoType.embargoOn 
							) &&
							list[ j ].info == list[ i ].info
							)
							list[ i ].conflict[ k ] = j;
				}
				else if ( list[ i ].type == (byte)nego.infoType.threat )
				{
					int tot = 0;
					for ( int j = 0; j < list.Length; j++ )
						if ( i != j && list[ j ].type == (byte)nego.infoType.threat && list[ i ].player == list[ j ].player )
							tot++;

					list[ i ].conflict = new int[ tot ];
					for ( int j = 0, k = 0; j < list.Length; j++ )
						if ( i != j && list[ j ].type == (byte)nego.infoType.threat && list[ i ].player == list[ j ].player )
						{
							list[ i ].conflict[ k ] = j;
							k++;
						}
				}
			}
	#endregion

			canGiveMoney = new long[ 2 ];
			canGivePerTurn = new long[ 2 ]; 
			giveMoney = new long[ 2 ];
			moneyPerTurn = new long[ 2 ];

			for ( int p = 0; p < 2; p++ )
			{
				canGiveMoney[ p ] = (int)Form1.game.playerList[ players[ p ] ].money;
				canGivePerTurn[ p ] = Form1.game.playerList[ players[ p ] ].totalTrade * Form1.game.playerList[ players[ p ] ].preferences.reserve / 100;
			}
		}