示例#1
0
文件: AI.cs 项目: MarShin/FlipCard
        public void setResult1(GameCard card)
        {
            // store no matter exist already in list

                result1 = card;
                myMem.AddToMemory(result1);
        }
示例#2
0
		public virtual int MatchedCardPos (GameCard realCard) 			//Interface FUNCTION 3
		{
			Debug.Log ("Finding a card in memory to match card " + realCard.id + " at position " + realCard.position);
			int result = -1;
			int startNode = 0;
			for (int i=0; i<numOfLines && (result == -1); i++) 
			{result = FindMatchWithInput (store [i], realCard.id, realCard.position, startNode, i);}
			return result;
		}
示例#3
0
		public void AddToMemory (GameCard realCard)						//Interface FUNCTION 1 
		{ 
			//1. hashing
			int key = Hashing(realCard);
			//2. duplicating
			MemCard headCard = new MemCard ();
			headCard.id = realCard.id;
			headCard.position = realCard.position;
			headCard.next = store[key];
			//3. storing
			store [key] = headCard;
			Debug.Log ("Card " + headCard.id + " at position " + headCard.position +  " added to " + key + "-th Memory Track ");
			
			//4. flush useless memory
			if(limitedSize) {DeleteLastWhenOutOfRange (ref store[key], 0);}
			
		}
示例#4
0
		//----------------------Below are important Functions doing actual searching------------------------------------


		protected bool FindCardsMatchWithinMem (MemCard line, int targetNode, ref bool endLine, int trackNum)
		{	//Function: helper for HaveMatchedPair()
			//Method: Feed a GameCard from Mem into FindMatchWithInput()
			//1. find the card
			for (int i=0; line != null && i < targetNode; i++) {
				line = line.next;
			}
			//2. if it is the end, endline & not found; This part is really important when memory line is not full
			if (line == null) {
				Debug.Log ("Pairing search over in track " + trackNum);
				endLine = true; 
				return false;
			}
			//3. if not end, Pass to find match	
			Debug.Log ("Memory track " + trackNum + " -node " + targetNode +
			           ": Try to see if " + line.id + " at position " + line.position + 
			           " can match with any other node");
			
			GameCard tempCard = new GameCard(); 
			tempCard.id = line.id; tempCard.position = line.position;
			int result = MatchedCardPos (tempCard);
			if (result != -1) {
				UpdatePair(line, result); //just update the pair, not directly return
				return true;
			}
			return false;
		}
示例#5
0
		protected override int Hashing (GameCard targetCard) 
		{
			return 0;
		}
示例#6
0
		public override int MatchedCardPos (GameCard realCard) 
		{
			Debug.Log ("Finding a card in memory to match card " + realCard.id + " at position " + realCard.position);
			int result = -1;
			int startNode = 0;
			int key = Hashing (realCard); //only search a single line
			result = FindMatchWithInput (store [key], realCard.id, realCard.position, startNode, key);
			return result;
		}
示例#7
0
		protected override int Hashing (GameCard targetCard) 
		{	
			return ((targetCard.id%100) < (numOfCards/4))? 0 : 1;
		}
示例#8
0
		//-----------------------------Below are helpers-------------------------------------------
		
		
		protected virtual int Hashing (GameCard targetCard) 
		{	//divide into left & right half
			int x = targetCard.position % numOfCards;
			return (x < (numOfCards / 2)) ? 0 : 1;
		}