Esempio n. 1
0
int selectTarget(Stack** line, Stack** freecell, Stack** homecell, CardInfo* cardInfo) {
	// get target
	int i;
	Card* res;
	Card* temp;
	int target;
	int index;
	int num;
	int success = 0;
	printf("Please enter the target (Line stack - 1, Freecell - 2): ");
	scanf("%d", &target);
	fflush(stdin);
	if(target == 1) {
		printf("Please enter the index and a number of cards: ");
		scanf("%d%d", &index, &num);
		fflush(stdin);

		// check the condition of card bunch
		res = getNthCard(line[index-1], num);
		temp = res;
		for(i = 0; i < num-1; ++i) {
			if(getCardColor(temp) == getCardColor(temp->next)) return -1;
			if(temp->number-1 != temp->next->number) return -1;
			temp = temp->next;
		}

		//print out result
		printf("Selected Card:");
		for(temp = res; temp != NULL; temp = temp->next) {
			printf(" ");
			printConsoleFormat(temp);
		}
		printf("\n");

		cardInfo->card = res;
		cardInfo->target =target;
		cardInfo->index = index;
		cardInfo->num = num;
		return 1;
	} else if (target == 2) {
		printf("Please enter the index: ");
		scanf("%d", &index);
		fflush(stdin);
		cardInfo->card = freecell[index-1]->head;

		if(!cardInfo->card) return -1;
		printf("Selected Card:");
		printf(" ");
		printConsoleFormat(cardInfo->card);
		printf("\n");

		cardInfo->target =target;
		cardInfo->index = index;
		cardInfo->num = 1;		
		return 1;
	}

	return 0;
}
Esempio n. 2
0
state setNewDeckOrder(state s, playerNum p, unsigned int *posIndexes)
{
    pile unseenCards = getAllUnseenCards(s, p);
    pile oppNewHand = getPRevCards(s, 1-p);
    unsigned int numUnseenCards = numCardsLeft(unseenCards);
    unsigned int numUnseenOppCards = numCardsLeft(getPHand(s, 1-p)) -
        numCardsLeft(oppNewHand);
    for(unsigned int i=0; i < numUnseenOppCards; i++)
    {
        card c = getNthCard(unseenCards, posIndexes[i]);
        oppNewHand = addCards(oppNewHand, c);
    }
    pile newDeck = 0;
    unsigned int deckCurrIndex = s.deckWithIndex >> 28;
    for(unsigned int i=numUnseenOppCards; i < numUnseenCards; i++, deckCurrIndex++)
    {
        card c = getNthCard(unseenCards, posIndexes[i]);
        newDeck = addCards(newDeck, c);
        s.deckOrder[deckCurrIndex] = c;
    }
    s.deckWithIndex = newDeck + (s.deckWithIndex & (((unsigned long long) 0xf) << 28));
    s = setPHand(s, 1-p, oppNewHand);
    return s;
}