Exemplo n.º 1
0
void Table::updateLegalCards(Card card) { //only called if card is allowed
	int suit = card.getSuit();
	int rank = card.getRank();
	std::string cardName = card.getCardName(card.getRank(), card.getSuit());

	legalCards_.erase(cardName);
	// std::cout << (legalCards_.find("7S") == legalCards_.end()) << std::endl;
	if (legalCards_.find("7S") == legalCards_.begin()) {
		legalCards_.insert("7C");
		legalCards_.insert("7D");
		legalCards_.insert("7H");
		legalCards_.insert("6S");
		legalCards_.insert("8S");
		legalCards_.erase("7S");
	}
	else if (rank == (7-1)) { //index of 7 is 1 less
		legalCards_.insert(card.getCardName(Rank(card.getRank() - 1), card.getSuit()));
		legalCards_.insert(card.getCardName(Rank(card.getRank() + 1), card.getSuit()));
	}
	else if (rank < (7-1)) {
		legalCards_.insert(card.getCardName(Rank(card.getRank() - 1), card.getSuit()));
	}
	else {
		legalCards_.insert(card.getCardName(Rank(card.getRank() + 1), card.getSuit()));
	}
}
Exemplo n.º 2
0
//recalculates legal card set after new card is played
void Table::updateLegalCards(Card card) { //only called if card is allowed
	int suit = card.getSuit();
	int rank = card.getRank();
	std::string cardName = card.getCardName(card.getRank(), card.getSuit());

	legalCards_.erase(cardName);
	//special case: 7S played opens all other 7's
	if (legalCards_.find("7S") == legalCards_.begin()) {
		legalCards_.insert("7C");
		legalCards_.insert("7D");
		legalCards_.insert("7H");
		legalCards_.insert("6S");
		legalCards_.insert("8S");
		legalCards_.erase("7S");
	}
	else if (rank == (7-1)) { //index of 7 is 1 less due to enum numeration
		legalCards_.insert(card.getCardName(Rank(card.getRank() - 1), card.getSuit()));
		legalCards_.insert(card.getCardName(Rank(card.getRank() + 1), card.getSuit()));
	}
	else if (rank == (13-1) || rank == (1-1)) {} //king and ace
	else if (rank < (7-1)) { //cards less than 7
		legalCards_.insert(card.getCardName(Rank(card.getRank() - 1), card.getSuit()));
	}
	else { //cards greater than 7
		legalCards_.insert(card.getCardName(Rank(card.getRank() + 1), card.getSuit()));
	}
}
Exemplo n.º 3
0
void FilesManager::createDecksReport() {
	readFromFile("decks.dat");
	std::ofstream fileStream;
	fileStream.open("report.txt", std::ios::out | std::ios::app);
	if(fileStream) {
		Colors colors[] = { Red, Black, Blue, White, Green };
		int decksSize = getDecksNumber();
		for(int i = 0; i < COLORS_COUNT; i++) {
			fileStream << getColorName(matchColorByInteger(i)) << std::endl;
			for(int j = 0; j < decksSize; j++) {
				if(decks[j].getColor() == colors[i]) {
					fileStream << "Owner: " << getPlayerNameById(decks[j].getDeckOwnerId()) << " ";
					fileStream << "Card: " << decks[j].getCards()[0].getCardName() << " ";
					fileStream << "Color: " << decks[j].getCards()[0].getColor() << std::endl;
				}
			}
		}
		Card mostCommonCard = getMostCommonCardIdInAllDecks();
		fileStream << "Most common card: " << mostCommonCard.getCardName() << " ";
		fileStream << "Color:" << mostCommonCard.getColor() << std::endl;
	} else {
		fileStream.clear();
		fileStream.close();
		throw serializable_exception;
	}
}
Exemplo n.º 4
0
//returns true if card is in legal cards
bool Table::isLegalCard(Card card) {
	if (legalCards_.find(card.getCardName(card.getRank(), card.getSuit())) != legalCards_.end()) {
		return true;
	}
	else {
		return false;
	}
}
Exemplo n.º 5
0
bool Table::isLegalCard(Card card) {
	// std::cout << "Legal cards: " << legalCards_.size() << "\n";
	// if (legalCards_.size() == 0) {
	// 	if (card.getCardName(card.getRank(), card.getSuit()) != "7S") {
	// 		return false;
	// 	}
	// 	return true;
	// }
	// else {
		//need to check if card is in legalCards, right?
		if (legalCards_.find(card.getCardName(card.getRank(), card.getSuit())) != legalCards_.end()) {
			return true;
		}
		else {
			return false;
		}
	// }
}
Exemplo n.º 6
0
 void run() {
     Card *testCard = new Card(10, "testName");
     test_( testCard->getID() == 10);
     test_( testCard->getCardName() == "testName");
 }