Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Player.cpp - University of Michigan EECS 280

Rating
-
Sold
-
Pages
5
Grade
A+
Uploaded on
13-02-2023
Written in
2022/2023

// Project UID 1d9f47bfccfbfdefe1 #include "Player.h" #include algorithm #include cassert class Simple :public Player { private: std::string nameP; std::vectorCard hand{}; public: Simple(std::string namePlayer) : nameP(namePlayer) {} //EFFECTS returns player's name virtual const std::string& get_name() const { return nameP; } //REQUIRES player has less than MAX_HAND_SIZE cards //EFFECTS adds Card c to Player's hand virtual void add_card(const Card& c) { _back(c); std::sort((), ()); } //REQUIRES round is 1 or 2 //MODIFIES order_up_suit //EFFECTS If Player wishes to order up a trump suit then return true and // change order_up_suit to desired suit. If Player wishes to pass, then do // not modify order_up_suit and return false. virtual bool make_trump(const Card& upcard, bool is_dealer, int round, std::string& order_up_suit) const { int trumps = 0; int size = static_cast int(()); if (round == 1) { for (int i = 0; i size; ++i) { if (hand[i].is_face() && hand[i].is_trump(_suit())) { ++trumps; } } if (trumps = 2) { order_up_suit = _suit(); return true; } } if (round == 2) { std::string nextSuit = Suit_next(_suit()); for (int i = 0; i size; ++i) { if (hand[i].is_face() && hand[i].is_trump(nextSuit)) { ++trumps; } } if (trumps = 1) { order_up_suit = nextSuit; return true; } if (is_dealer) { order_up_suit = nextSuit;

Show more Read less
Institution
Course

Content preview

// Project UID 1d9f47bfc76643019cfbf037641defe1

#include "Player.h"
#include <algorithm>
#include <cassert>


class Simple :public Player {
private:
std::string nameP;
std::vector<Card> hand{};


public:
Simple(std::string namePlayer) : nameP(namePlayer) {}
//EFFECTS returns player's name
virtual const std::string& get_name() const {
return nameP;
}

//REQUIRES player has less than MAX_HAND_SIZE cards
//EFFECTS adds Card c to Player's hand
virtual void add_card(const Card& c) {
hand.push_back(c);
std::sort(hand.begin(), hand.end());
}

//REQUIRES round is 1 or 2
//MODIFIES order_up_suit
//EFFECTS If Player wishes to order up a trump suit then return true and
// change order_up_suit to desired suit. If Player wishes to pass, then do
// not modify order_up_suit and return false.
virtual bool make_trump(const Card& upcard, bool is_dealer,
int round, std::string& order_up_suit) const {
int trumps = 0;
int size = static_cast <int>(hand.size());
if (round == 1) {
for (int i = 0; i < size; ++i) {

if (hand[i].is_face() && hand[i].is_trump(upcard.get_suit())) {
++trumps;
}
}
if (trumps >= 2) {
order_up_suit = upcard.get_suit();
return true;
}
}

if (round == 2) {
std::string nextSuit = Suit_next(upcard.get_suit());
for (int i = 0; i < size; ++i) {
if (hand[i].is_face() && hand[i].is_trump(nextSuit)) {
++trumps;
}
}
if (trumps >= 1) {
order_up_suit = nextSuit;
return true;
}
if (is_dealer) {
order_up_suit = nextSuit;
}
}

This study source was downloaded by 100000850872992 from CourseHero.com on 02-12-2023 20:59:26 GMT -06:00


https://www.coursehero.com/file/89323148/Playercpp/

, return false;
}

//REQUIRES Player has at least one card
//EFFECTS Player adds one card to hand and removes one card from hand.
virtual void add_and_discard(const Card& upcard) {

std::string trump = upcard.get_suit();// make_trump??
int lowest = 0;
int size = static_cast <int>(hand.size());
hand.push_back(upcard);
std::sort(hand.begin(), hand.end());
for (int i = 0; i < size; ++i) {
if (Card_less(hand[i], hand[lowest], trump)) {
lowest = i;
}
}
hand.erase((hand.begin() + lowest));
// remove min card with cardless function
}


//REQUIRES Player has at least one card, trump is a valid suit
//EFFECTS Leads one Card from Player's hand according to their strategy
// "Lead" means to play the first Card in a trick. The card
// is removed the player's hand.
virtual Card lead_card(const std::string& trump) {
std::sort(hand.begin(), hand.end());
int size = static_cast <int>(hand.size());
int highest = 3;
bool allTrump = true;
for (int i = 0; i < size; ++i) {
if (hand[i].get_suit() != trump) { // for--> of all trump --> if 1
not trump
allTrump = false;
}
}
for (int i = 0; i < size; ++i) {
if (allTrump == true && Card_less(hand[highest], hand[i], trump)) {
highest = i;
}
if (allTrump == false) {
if (hand[i].get_suit() != trump &&
Card_less(hand[highest], hand[i], trump)) {
highest = i;
}
}
}
Card H = hand[highest];
hand.erase((hand.begin() + highest));
return H;
}

//REQUIRES Player has at least one card, trump is a valid suit
//EFFECTS Plays one Card from Player's hand according to their strategy.
// The card is removed from the player's hand.
virtual Card play_card(const Card& led_card, const std::string& trump) {
int highest = 4;
int size = static_cast <int>(hand.size());
int lowest = 0;
std::sort(hand.begin(), hand.end());
for (int i = 0; i < size; ++i) {

if (hand[i].get_suit() == led_card.get_suit()) {

This study source was downloaded by 100000850872992 from CourseHero.com on 02-12-2023 20:59:26 GMT -06:00


https://www.coursehero.com/file/89323148/Playercpp/

Written for

Course

Document information

Uploaded on
February 13, 2023
Number of pages
5
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ExamsConnoisseur Self
Follow You need to be logged in order to follow users or courses
Sold
587
Member since
3 year
Number of followers
344
Documents
1492
Last sold
1 week ago

4.2

68 reviews

5
40
4
11
3
13
2
1
1
3

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions