コード例 #1
0
ファイル: Poker.c プロジェクト: konorati/OldProjects
/*************************************************************************
* Date last modified: April 17th, 2013
* Description: Sets the winning cards array for each the player.
*     ex: index 0 = 1 if straight flush exists...
* Input parameters: integer arrays of number of each face value and suit in hand,
*     array of winning card list
* Returns: 
* Precondition: array of face values and suits has been set
* Postcondition: winner list is set based on current cards
*************************************************************************/
void setDetermineWinnerArray(int *suits, int *faces, int *winnerList){
	int i = 0, j = 0;
	//Set all indexes to -1
	for(i = 0; i < 13; i++){
		winnerList[i] = -1;
	}
	if(containsFlush(suits) >= 0 && containsStraight(faces) > 0){ // If straight flush set array position 1 to 1
		winnerList[0] = 1;
	}
	else if(containsFourOfAKind(faces) >= 0){ // If four of a kind set array in position 2 to face index of four of a kind
		winnerList[1] = containsFourOfAKind(faces);
	}
	else if(containsThreeOfAKind(faces) >= 0 && containsPair(faces) >= 0){ // If full house set array in position 3 to face index of three of a kind
		winnerList[2] = containsThreeOfAKind(faces);
	}
	else if(containsFlush(suits) >= 0){ // If flush set array position 4 to 1
		winnerList[3] = 1;
	}
	else if(containsStraight(faces) > 0){ // If straight set array position 5 to 1
		winnerList[4] = 1;
	}
	else if(containsThreeOfAKind(faces) >= 0){ // If three of a kind set array in position 6 to face index of three of a kind
		winnerList[5] = containsThreeOfAKind(faces);
	}
	else if(containsTwoPair(faces) >= 0){ // If two pair set array position 7 to highest pair and array position 8 to second pair
		winnerList[6] = containsTwoPair(faces);
		winnerList[7] = containsPair(faces);
	}
	else if(containsPair(faces) >= 0){ // If pair set array position 8 to pair
		winnerList[7] = containsPair(faces);
	}
	//Set high cards (1-5)
	j = 8;
	for(i = NUM_FACES; i >= 0; i--){ 
		if(faces[i] > 0){
			winnerList[j] = i;
			j++;
		}
	}
}
コード例 #2
0
ファイル: Grammar.c プロジェクト: fnmartinez/TLATPE
void removeUnitaryProductions(GrammarADT grammar) {
    ProductionsADT  productions = getProductions(grammar);
    int i,j,k, productionquant = getQuant(productions), unitaryquant = 0, lastunitaryquant = 0;
    /*auxiliar array for unitary productions*/
    char * unitaries = NULL;
    /*iterate over productions and determine first unitaries:
     * the productions that have only one non terminal symbol
     * on the right side */
    for (i=0; i< productionquant; i++) {
        char first = getProductionComponent(getProduction(productions,i),0);
        char sec = getProductionComponent(getProduction(productions,i),1);
        char third = getProductionComponent(getProduction(productions,i),2);
        if ( isNonTerminal(sec) && third == LAMDA ) {
            addPair(&unitaries,&unitaryquant,first, sec);
        } else if( isNonTerminal(third) && sec == LAMDA) {
            addPair(&unitaries,&unitaryquant,first, third);
        }
    }
    /*iterate over unitaries, adding the closure*/
    while(unitaryquant != lastunitaryquant) {
        lastunitaryquant = unitaryquant;
        for (i=0; i<unitaryquant ; i+=2) {
            char first1 = unitaries[i];
            char sec1 = unitaries[i+1];
            for (j=0; j<unitaryquant ; j+=2) {
                char first2 = unitaries[j];
                char sec2 = unitaries[j+1];
                /*(A,B)(B,C)-> (A,C)*/
                if (sec1 == first2 ) {
                    if (!containsPair(unitaries,unitaryquant,first1,sec2) &&
                            first1 != sec2 ) { /*no sense in adding (A,A) unitaries*/
                        addPair(&unitaries,&unitaryquant,first1,sec2);
                    }
                }
            }
        }
    }
    /*Debug*/
    //printByPairs(unitaries,unitaryquant);
    //printf("unitaries quant: %d\n\n", unitaryquant/2);
    /*create the new productions and remove the unitaries*/
    for(i=0; i<productionquant; i++) {
        ProductionADT p1 = getProduction(productions,i);
        if ( isUnitary(p1) ) {
            char first1 = getProductionComponent(p1,0);
            char sec1 = getProductionComponent(p1,1);
            char third1 = getProductionComponent(p1,2);
            for(j=0; j<unitaryquant; j+=2) {
                char uni1 = unitaries[j];
                char uni2 = unitaries[j+1];
                //A->B and (A,B) (unitary production is localized)
                if ((first1 == uni1) && (sec1 == uni2 || third1 == uni2 )) {
                    for(k=0; k<productionquant; k++ ) {
                        ProductionADT p2 = getProduction(productions,k);
                        char first2 = getProductionComponent(p2,0);
                        char sec2 = getProductionComponent(p2,1);
                        char third2 = getProductionComponent(p2,2);
                        if(!isUnitary(p2)) {
                            if(first2 == uni2 ) {
                                addProduction(productions,newProduction(first1,sec2,third2));
                            }
                        }
                    }
                }
            }
            removeParticularProduction(productions,p1);
            free(p1);
        }
    }
    /*remove non terminals and terminals that are no longer there */
    actualizeTerminals(grammar);
    actualizeNonTerminals(grammar);
    actualizeProductions(grammar);



}
コード例 #3
0
ファイル: Poker.c プロジェクト: konorati/OldProjects
/*************************************************************************
* Date last modified: April 17th, 2013
* Description: Determines which of the computers cards to keep based on current hand,
*     set those cards to keep (1) in the keep card array
* Input parameters: array of keep cards, array of number of each suit in hand,
*     array of number of each face value in hand, players current hand
* Returns: 
* Precondition: array of face values and number of each suit has been set, array of 
*     keep cards has been reset to 0, hand has been dealt
* Postcondition: 0-5 cards are set to keep based on quality of hand
*************************************************************************/
void determineCompKeepCards(int *keepCards, int *suits, int *faces, Card hand[HAND_SIZE]){
	int i = 0, keep = 0, keep2 = 0, numKeep = 0, j = 0;
	//If straight keep all cards
	if(containsStraight(faces)){
		keepAllCards(keepCards);
	}
	//If flush keep all cards
	else if(containsFlush(suits) >= 0){
		keepAllCards(keepCards);
	}
	//If four of a kind keep all cards if extra card is a face card
	else if(containsFourOfAKind(faces) >= 0){
		keep = containsFourOfAKind(faces);
		for(i = 0; i < HAND_SIZE; i++){
			if(hand[i].faceIndex == keep){
				keepCards[i] = 1;
			}
			else if(hand[i].faceIndex > 8){
				keepCards[i] = 1;
			}
		}
	}
	//If full house keep all cards
	else if(containsThreeOfAKind(faces) >= 0 && containsPair(faces) >= 0){
		keepAllCards(keepCards);
	}
	//If three of a kind keep three
	else if(containsThreeOfAKind(faces) >= 0){
		keep = containsThreeOfAKind(faces);
		for(i = 0; i < HAND_SIZE; i++){
			if(hand[i].faceIndex == keep){
				keepCards[i] = 1;
			}
		}
	}
	//If 2 pair keep the 2 pair
	else if(containsTwoPair(faces) >= 0){
		keep = containsPair(faces);
		keep2 = containsTwoPair(faces);
		for(i = 0; i < HAND_SIZE; i++){
			if(hand[i].faceIndex == keep || hand[i].faceIndex == keep2){
				keepCards[i] = 1;
			}
		}
	}
	//If one pair keep the pair
	else if(containsPair(faces) >= 0){
		keep = containsPair(faces);
		for(i = 0; i < HAND_SIZE; i++){
			if(hand[i].faceIndex == keep){
				keepCards[i] = 1;
			}
		}
	}
	else if(hasFourToAFlush(suits) >= 0){ //If four to a flush keep those cards
		j = hasFourToAFlush(suits);
		for(i = 0; i < HAND_SIZE; i++){
			if(hand[i].suitIndex == j){
				keepCards[i] = 1;
			}
		}
	}
	else{ //If nothing then keep face cards
		for(i = NUM_FACES-1; i > 8; i--){
			if(faces[i] == 1){
				for(j = 0; j < HAND_SIZE; j++){
					if(hand[j].faceIndex == i){
						keepCards[j] = 1;
					}
				}
			}
		}
	}
}