mirror of
https://github.com/Llewellynvdm/GoFish.git
synced 2024-06-03 16:40:48 +00:00
Added debugging, made a number of bug fixes, and fixed naming issue.
This commit is contained in:
parent
09a92cb887
commit
68376d206d
259
main.cpp
259
main.cpp
|
@ -1,19 +1,20 @@
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
* Champlain College SDEV-345-81
|
* Champlain College SDEV-345-81
|
||||||
*
|
*
|
||||||
* C++ Week 4: Discussion (first semester) - Go Fish (2020/09/20)
|
* C++ Week 4: Discussion (first semester) - Go Fish (2020/09/20)
|
||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Collaborate on the discussion to develop a card game. “Go Fish” is a classic children’s card game
|
* Collaborate on the discussion to develop a card game.
|
||||||
|
* “Go Fish” is a classic children’s card game
|
||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Written by Llewellyn van der Merwe <llewellyn.vandermerw@mymail.champlain.edu>, September 2020
|
* Written by Llewellyn van der Merwe <llewellyn.vandermerw@mymail.champlain.edu>, September 2020
|
||||||
* Copyright (C) 2020. All Rights Reserved
|
* Copyright (C) 2020. All Rights Reserved
|
||||||
* License GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
* License GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*
|
*
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class mapper {
|
class cardDB {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,11 +55,16 @@ protected:
|
||||||
map<string, string> deck_display;
|
map<string, string> deck_display;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* for debugging
|
||||||
|
**/
|
||||||
|
bool debug = false;
|
||||||
|
// just change this to true to see debug info
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to setup the mapper
|
* Constructor to setup the mapper
|
||||||
**/
|
**/
|
||||||
mapper() {
|
cardDB() {
|
||||||
// for display
|
// for display
|
||||||
this->deck_display["H1"] = "Ace of Hearts";
|
this->deck_display["H1"] = "Ace of Hearts";
|
||||||
this->deck_display["D1"] = "Ace of Diamonds";
|
this->deck_display["D1"] = "Ace of Diamonds";
|
||||||
|
@ -67,6 +73,7 @@ public:
|
||||||
|
|
||||||
this->deck_display["H2"] = "Two of Hearts";
|
this->deck_display["H2"] = "Two of Hearts";
|
||||||
this->deck_display["D2"] = "Two of Diamonds";
|
this->deck_display["D2"] = "Two of Diamonds";
|
||||||
|
this->deck_display["S2"] = "Two of Spades";
|
||||||
this->deck_display["C2"] = "Two of Clubs";
|
this->deck_display["C2"] = "Two of Clubs";
|
||||||
|
|
||||||
this->deck_display["H3"] = "Three of Hearts";
|
this->deck_display["H3"] = "Three of Hearts";
|
||||||
|
@ -221,7 +228,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we can find the card
|
// check if we can find the card
|
||||||
bool find(string key) {
|
bool searchDeck(string key) {
|
||||||
// the iterator search
|
// the iterator search
|
||||||
map<string, double>::iterator found = this->deck_specifics_a.find(key);
|
map<string, double>::iterator found = this->deck_specifics_a.find(key);
|
||||||
// check if it is found
|
// check if it is found
|
||||||
|
@ -241,7 +248,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we can find the card
|
// check if we can find the card
|
||||||
bool find(double key) {
|
bool searchDeck(double key) {
|
||||||
// the iterator search
|
// the iterator search
|
||||||
map<double, string>::iterator found = this->deck_specifics_b.find(key);
|
map<double, string>::iterator found = this->deck_specifics_b.find(key);
|
||||||
// check if it is found
|
// check if it is found
|
||||||
|
@ -267,7 +274,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class deck : public mapper {
|
class deck : public cardDB {
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* mode 1 = RANK; 2 = SPECIFIC;
|
* mode 1 = RANK; 2 = SPECIFIC;
|
||||||
|
@ -290,7 +297,6 @@ public:
|
||||||
stack<double> mixed;
|
stack<double> mixed;
|
||||||
|
|
||||||
deck() {
|
deck() {
|
||||||
|
|
||||||
// setup the mixed deck
|
// setup the mixed deck
|
||||||
for (map<string, double>::iterator i = this->deck_specifics_a.begin(); i != this->deck_specifics_a.end(); ++i) {
|
for (map<string, double>::iterator i = this->deck_specifics_a.begin(); i != this->deck_specifics_a.end(); ++i) {
|
||||||
// random sort the cards
|
// random sort the cards
|
||||||
|
@ -313,6 +319,8 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if debug mode we check the shuffle
|
||||||
|
vector<double> debug_deck;
|
||||||
// complete the shuffle
|
// complete the shuffle
|
||||||
int not_again[] = {0, 0, 0, 0, 0};
|
int not_again[] = {0, 0, 0, 0, 0};
|
||||||
int deck_n = 0;
|
int deck_n = 0;
|
||||||
|
@ -323,26 +331,41 @@ public:
|
||||||
if (1 == deck_n && !this->deck_1.empty()) {
|
if (1 == deck_n && !this->deck_1.empty()) {
|
||||||
// add to real deck
|
// add to real deck
|
||||||
this->mixed.push(this->deck_1.top());
|
this->mixed.push(this->deck_1.top());
|
||||||
|
if (this->debug) {
|
||||||
|
debug_deck.push_back(this->deck_1.top());
|
||||||
|
}
|
||||||
// remove from tem deck
|
// remove from tem deck
|
||||||
this->deck_1.pop();
|
this->deck_1.pop();
|
||||||
} else if (2 == deck_n && !this->deck_2.empty()) {
|
} else if (2 == deck_n && !this->deck_2.empty()) {
|
||||||
// add to real deck
|
// add to real deck
|
||||||
this->mixed.push(this->deck_2.top());
|
this->mixed.push(this->deck_2.top());
|
||||||
|
if (this->debug) {
|
||||||
|
debug_deck.push_back(this->deck_2.top());
|
||||||
|
}
|
||||||
// remove from tem deck
|
// remove from tem deck
|
||||||
this->deck_2.pop();
|
this->deck_2.pop();
|
||||||
} else if (3 == deck_n && !this->deck_3.empty()) {
|
} else if (3 == deck_n && !this->deck_3.empty()) {
|
||||||
// add to real deck
|
// add to real deck
|
||||||
this->mixed.push(this->deck_3.top());
|
this->mixed.push(this->deck_3.top());
|
||||||
|
if (this->debug) {
|
||||||
|
debug_deck.push_back(this->deck_3.top());
|
||||||
|
}
|
||||||
// remove from tem deck
|
// remove from tem deck
|
||||||
this->deck_3.pop();
|
this->deck_3.pop();
|
||||||
} else if (4 == deck_n && !this->deck_4.empty()) {
|
} else if (4 == deck_n && !this->deck_4.empty()) {
|
||||||
// add to real deck
|
// add to real deck
|
||||||
this->mixed.push(this->deck_4.top());
|
this->mixed.push(this->deck_4.top());
|
||||||
|
if (this->debug) {
|
||||||
|
debug_deck.push_back(this->deck_4.top());
|
||||||
|
}
|
||||||
// remove from tem deck
|
// remove from tem deck
|
||||||
this->deck_4.pop();
|
this->deck_4.pop();
|
||||||
} else if (5 == deck_n && !this->deck_5.empty()) {
|
} else if (5 == deck_n && !this->deck_5.empty()) {
|
||||||
// add to real deck
|
// add to real deck
|
||||||
this->mixed.push(this->deck_5.top());
|
this->mixed.push(this->deck_5.top());
|
||||||
|
if (this->debug) {
|
||||||
|
debug_deck.push_back(this->deck_5.top());
|
||||||
|
}
|
||||||
// remove from tem deck
|
// remove from tem deck
|
||||||
this->deck_5.pop();
|
this->deck_5.pop();
|
||||||
} else {
|
} else {
|
||||||
|
@ -357,6 +380,14 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if debug mode we check the shuffle
|
||||||
|
if (this->debug) {
|
||||||
|
// this is the current deck
|
||||||
|
cout << __LINE__ << " This is the current deck" << endl;
|
||||||
|
// setup the reverse map
|
||||||
|
for(double i : debug_deck)
|
||||||
|
cout << i << " = " << this->deck_specifics_b[i] << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -383,9 +414,17 @@ public:
|
||||||
map<string, int>::iterator found = this->deck_ranks_a.find(key);
|
map<string, int>::iterator found = this->deck_ranks_a.find(key);
|
||||||
// check if it is found
|
// check if it is found
|
||||||
if (found != this->deck_ranks_a.end()) {
|
if (found != this->deck_ranks_a.end()) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " getRankKey [" << key << "] => " << found->second << endl;
|
||||||
|
}
|
||||||
// element found;
|
// element found;
|
||||||
return found->second;
|
return found->second;
|
||||||
}
|
}
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " getRankKey [" << key << "] => not found" << endl;
|
||||||
|
}
|
||||||
// element not found
|
// element not found
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -474,7 +513,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class hand : public mapper {
|
class hand : public cardDB {
|
||||||
protected:
|
protected:
|
||||||
// the deck in each and
|
// the deck in each and
|
||||||
bool cards[13][4] = {};
|
bool cards[13][4] = {};
|
||||||
|
@ -487,6 +526,10 @@ protected:
|
||||||
rank = (int) card;
|
rank = (int) card;
|
||||||
shape = (int) (card * 10000);
|
shape = (int) (card * 10000);
|
||||||
shape = (shape - (rank * 10000)) / 1000;
|
shape = (shape - (rank * 10000)) / 1000;
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " set [" << card << "] R=" << rank << " S=" << shape << " state=" << state << endl;
|
||||||
|
}
|
||||||
// set the state
|
// set the state
|
||||||
return this->set(rank, shape, state);
|
return this->set(rank, shape, state);
|
||||||
}
|
}
|
||||||
|
@ -494,6 +537,10 @@ protected:
|
||||||
bool set(int rank, int shape, bool state) {
|
bool set(int rank, int shape, bool state) {
|
||||||
// now set the card state
|
// now set the card state
|
||||||
this->cards[rank][shape] = state;
|
this->cards[rank][shape] = state;
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " set R=" << rank << " S=" << shape << " state=" << state << endl;
|
||||||
|
}
|
||||||
// always true :)
|
// always true :)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -501,10 +548,18 @@ protected:
|
||||||
// remove the cards locally
|
// remove the cards locally
|
||||||
bool remove(double card, bool found = false) {
|
bool remove(double card, bool found = false) {
|
||||||
// check if this card is in the deck
|
// check if this card is in the deck
|
||||||
if (found || this->find(card)) {
|
if (found || this->searchDeck(card)) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " removed=" << card << endl;
|
||||||
|
}
|
||||||
// was removed so true
|
// was removed so true
|
||||||
return this->set(card, false);
|
return this->set(card, false);
|
||||||
}
|
}
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " not removed=" << card << endl;
|
||||||
|
}
|
||||||
// was not removed
|
// was not removed
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -512,18 +567,30 @@ protected:
|
||||||
// remove the card locally (may not be needed)
|
// remove the card locally (may not be needed)
|
||||||
bool remove(string card, bool found = false) {
|
bool remove(string card, bool found = false) {
|
||||||
// check if this card is in the deck
|
// check if this card is in the deck
|
||||||
if (found || this->find(card)) {
|
if (found || this->searchDeck(card)) {
|
||||||
// get the double
|
// get the double
|
||||||
double d_card = this->get(card);
|
double d_card = this->get(card);
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " removed=[" << d_card << "]=" << card << endl;
|
||||||
|
}
|
||||||
// was removed so true
|
// was removed so true
|
||||||
return this->set(d_card, false);
|
return this->set(d_card, false);
|
||||||
}
|
}
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " not removed=" << card << endl;
|
||||||
|
}
|
||||||
// was not removed
|
// was not removed
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the cards locally (may not be needed)
|
// remove the cards locally (may not be needed)
|
||||||
bool remove(int rank) {
|
bool remove(int rank) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " removed=" << rank << endl;
|
||||||
|
}
|
||||||
// there can only be four ranks
|
// there can only be four ranks
|
||||||
for (int shape = 1; shape < 5; shape++) {
|
for (int shape = 1; shape < 5; shape++) {
|
||||||
this->set(rank, shape, false);
|
this->set(rank, shape, false);
|
||||||
|
@ -534,17 +601,30 @@ protected:
|
||||||
|
|
||||||
// the getter
|
// the getter
|
||||||
bool has(int rank, int shape) {
|
bool has(int rank, int shape) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " has R=" << rank << " S=" << shape << " answer=" << this->cards[rank][shape] << endl;
|
||||||
|
}
|
||||||
// now add the card
|
// now add the card
|
||||||
return this->cards[rank][shape];
|
return this->cards[rank][shape];
|
||||||
}
|
}
|
||||||
|
|
||||||
// the getter RANK
|
// the getter RANK
|
||||||
bool has(int rank) {
|
bool has(int rank, bool give) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (int s = 1; s < 5; s++) {
|
for (int s = 1; s < 5; s++) {
|
||||||
if (this->cards[rank][s]) {
|
if (this->cards[rank][s]) {
|
||||||
double r = this->getDoubleKey(rank, s);
|
double r = this->getDoubleKey(rank, s);
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug && give){
|
||||||
|
cout << __LINE__ << " has & give R=" << rank << " S=" << s << " answer=1" << " [" << r << "]" << endl;
|
||||||
|
} else if (this->debug){
|
||||||
|
cout << __LINE__ << " has R=" << rank << " S=" << s << " answer=1" << " [" << r << "]" << endl;
|
||||||
|
}
|
||||||
|
// give value to another player
|
||||||
|
if (give) {
|
||||||
this->lose.push_back(r);
|
this->lose.push_back(r);
|
||||||
|
}
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -575,12 +655,39 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the cards locally
|
// set the cards locally
|
||||||
bool add(double card) {
|
bool add(int card) {
|
||||||
// check if this card is in the deck
|
// check if this card is in the deck
|
||||||
if (this->find(card)) {
|
if (this->searchDeck(card)) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " add " << card << endl;
|
||||||
|
}
|
||||||
// was set so true
|
// was set so true
|
||||||
return this->set(card, true);
|
return this->set(card, true);
|
||||||
}
|
}
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " did not add " << card << endl;
|
||||||
|
}
|
||||||
|
// was not set
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the cards locally
|
||||||
|
bool add(double card) {
|
||||||
|
// check if this card is in the deck
|
||||||
|
if (this->searchDeck(card)) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " add " << card << endl;
|
||||||
|
}
|
||||||
|
// was set so true
|
||||||
|
return this->set(card, true);
|
||||||
|
}
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " did not add " << card << endl;
|
||||||
|
}
|
||||||
// was not set
|
// was not set
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -588,24 +695,42 @@ public:
|
||||||
// set the cards locally (may not be needed)
|
// set the cards locally (may not be needed)
|
||||||
bool add(string card) {
|
bool add(string card) {
|
||||||
// check if this card is in the deck
|
// check if this card is in the deck
|
||||||
if (this->find(card)) {
|
if (this->searchDeck(card)) {
|
||||||
// get the double
|
// get the double
|
||||||
double d_card = this->get(card);
|
double d_card = this->get(card);
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " add [" << d_card << "] " << card << endl;
|
||||||
|
}
|
||||||
// was set so true
|
// was set so true
|
||||||
return this->set(d_card, true);
|
return this->set(d_card, true);
|
||||||
}
|
}
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " did not add " << card << endl;
|
||||||
|
}
|
||||||
// was not set
|
// was not set
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the cards locally
|
// set the cards locally
|
||||||
bool hasCard(double card, bool give = false) {
|
bool hasCard(double card, bool give) {
|
||||||
|
// always rest the lose
|
||||||
|
this->lose.clear();
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " we clear the lose vector" << endl;
|
||||||
|
}
|
||||||
// check if this card is in the deck
|
// check if this card is in the deck
|
||||||
if (this->find(card)) {
|
if (this->searchDeck(card)) {
|
||||||
int rank, shape;
|
int rank, shape;
|
||||||
rank = (int) card;
|
rank = (int) card;
|
||||||
shape = (int) (card * 10000);
|
shape = (int) (card * 10000);
|
||||||
shape = (shape - (rank * 10000)) / 1000;
|
shape = (shape - (rank * 10000)) / 1000;
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " has card [" << card << "]" << " R=" << rank << " S=" << shape << endl;
|
||||||
|
}
|
||||||
// check if we must remove it at the same time
|
// check if we must remove it at the same time
|
||||||
if (give) {
|
if (give) {
|
||||||
// get the card
|
// get the card
|
||||||
|
@ -624,40 +749,55 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the card RANK locally
|
// set the card RANK locally
|
||||||
bool hasCard(int card, bool give = false) {
|
bool hasCard(int card, bool give) {
|
||||||
// always rest the lose
|
// always rest the lose
|
||||||
this->lose.clear();
|
this->lose.clear();
|
||||||
// check if this card is in the deck
|
// check if this card is in the deck
|
||||||
if (card > 0 && card < 14) {
|
if (card > 0 && card < 14) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " has card [" << card << "]" << endl;
|
||||||
|
}
|
||||||
// check if we must remove it at the same time
|
// check if we must remove it at the same time
|
||||||
if (give) {
|
if (give) {
|
||||||
// get the card
|
// get the card
|
||||||
if (this->has(card)) {
|
if (this->has(card, give)) {
|
||||||
// remove since it is found
|
// remove since it is found
|
||||||
for (auto c : this->lose)
|
for (double c : this->lose) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug) {
|
||||||
|
cout << __LINE__ << " lose [" << c << "]" << endl;
|
||||||
|
}
|
||||||
this->remove(c, true);
|
this->remove(c, true);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// not found
|
// not found
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// return if the card is found
|
// return if the card is found
|
||||||
return this->has(card);
|
return this->has(card, give);
|
||||||
}
|
}
|
||||||
// not a card
|
// not a card
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the cards locally (may not be needed)
|
// set the cards locally (may not be needed)
|
||||||
bool hasCard(string card, bool give = false) {
|
bool hasCard(string card, bool give) {
|
||||||
|
// always rest the lose
|
||||||
|
this->lose.clear();
|
||||||
// check if this card is in the deck
|
// check if this card is in the deck
|
||||||
if (this->find(card)) {
|
if (this->searchDeck(card)) {
|
||||||
// get the double
|
// get the double
|
||||||
double d_card = this->get(card);
|
double d_card = this->get(card);
|
||||||
int rank, shape;
|
int rank, shape;
|
||||||
rank = (int) d_card;
|
rank = (int) d_card;
|
||||||
shape = (int) (d_card * 10000);
|
shape = (int) (d_card * 10000);
|
||||||
shape = (shape - (rank * 10000)) / 1000;
|
shape = (shape - (rank * 10000)) / 1000;
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " has card [" << card << "=" << d_card << "]" << " R=" << rank << " S=" << shape << endl;
|
||||||
|
}
|
||||||
// check if we must remove it at the same time
|
// check if we must remove it at the same time
|
||||||
if (give) {
|
if (give) {
|
||||||
// get the card
|
// get the card
|
||||||
|
@ -682,10 +822,25 @@ public:
|
||||||
|
|
||||||
// ask for a card
|
// ask for a card
|
||||||
bool askCard(int card, hand &AHand) {
|
bool askCard(int card, hand &AHand) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " ask [" << card << "]" << endl;
|
||||||
|
}
|
||||||
if (card > 0 && AHand.hasCard(card, true)) {
|
if (card > 0 && AHand.hasCard(card, true)) {
|
||||||
vector<double> winnings = AHand.getWinnings();
|
vector<double> winnings = AHand.getWinnings();
|
||||||
for (auto i : winnings)
|
for (double c : winnings) {
|
||||||
this->add(i);
|
// show values in debugging
|
||||||
|
if (this->debug) {
|
||||||
|
cout << __LINE__ << " winning [" << c << "]" << endl;
|
||||||
|
}
|
||||||
|
if (!this->add(c)){
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " winning ERROR->[" << c << "]" << endl;
|
||||||
|
}
|
||||||
|
// break on error
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
// cards were found
|
// cards were found
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -695,7 +850,15 @@ public:
|
||||||
|
|
||||||
// ask for a card
|
// ask for a card
|
||||||
bool askCard(double card, hand &AHand) {
|
bool askCard(double card, hand &AHand) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug){
|
||||||
|
cout << __LINE__ << " ask [" << card << "]" << endl;
|
||||||
|
}
|
||||||
if (AHand.hasCard(card, true)) {
|
if (AHand.hasCard(card, true)) {
|
||||||
|
// show values in debugging
|
||||||
|
if (this->debug) {
|
||||||
|
cout << __LINE__ << " before add [" << card << "]" << endl;
|
||||||
|
}
|
||||||
// cards were found
|
// cards were found
|
||||||
return this->add(card);
|
return this->add(card);
|
||||||
}
|
}
|
||||||
|
@ -719,18 +882,16 @@ protected:
|
||||||
bool deceit;
|
bool deceit;
|
||||||
// allow empty deck
|
// allow empty deck
|
||||||
bool empty_deck;
|
bool empty_deck;
|
||||||
// the deck index
|
|
||||||
int index = 1;
|
|
||||||
// player hands
|
// player hands
|
||||||
map<int, hand> hands;
|
map<int, hand> hands;
|
||||||
|
|
||||||
// opening setup
|
// opening setup
|
||||||
void setupBoard() {
|
void setupBoard() {
|
||||||
// for quick testing
|
// for quick testing
|
||||||
// this->players = 2;
|
//this->players = 2;
|
||||||
// this->mode = 1;
|
//this->mode = 1;
|
||||||
// this->empty_deck = false;
|
//this->empty_deck = false;
|
||||||
// return;
|
//return;
|
||||||
// string to get answers
|
// string to get answers
|
||||||
string tmp;
|
string tmp;
|
||||||
// ask the opening questions
|
// ask the opening questions
|
||||||
|
@ -857,7 +1018,7 @@ public:
|
||||||
} else {
|
} else {
|
||||||
cout << "So H1 is the key for Ace of Hearts" << endl;
|
cout << "So H1 is the key for Ace of Hearts" << endl;
|
||||||
}
|
}
|
||||||
cout << "Are you ready to continue?" << endl;
|
cout << "Player [" << p << "] are you ready to continue?" << endl;
|
||||||
cout << "(y/n): ";
|
cout << "(y/n): ";
|
||||||
cin >> yes;
|
cin >> yes;
|
||||||
if (yes == "y" || yes == "Y" || yes == "yes" || yes == "Yes") {
|
if (yes == "y" || yes == "Y" || yes == "yes" || yes == "Yes") {
|
||||||
|
@ -876,6 +1037,17 @@ public:
|
||||||
if (p > this->players) {
|
if (p > this->players) {
|
||||||
p = 1;
|
p = 1;
|
||||||
}
|
}
|
||||||
|
// little pause to setup the new player
|
||||||
|
while (true) {
|
||||||
|
cout << "Player [" << p << "] are you ready to continue?" << endl;
|
||||||
|
cout << "(y/n): ";
|
||||||
|
cin >> yes;
|
||||||
|
if (yes == "y" || yes == "Y" || yes == "yes" || yes == "Yes") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cin.clear();
|
||||||
|
cin.ignore();
|
||||||
|
}
|
||||||
// reset getting new player
|
// reset getting new player
|
||||||
get_new_player = false;
|
get_new_player = false;
|
||||||
}
|
}
|
||||||
|
@ -907,16 +1079,14 @@ public:
|
||||||
ask = 2;
|
ask = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// player questions
|
|
||||||
cout << "You are player [" << p << "]" << endl;
|
|
||||||
cout << "We will show your hand in a moment." << endl;
|
|
||||||
// check if we should ask for next player
|
// check if we should ask for next player
|
||||||
if (ask_next) {
|
if (ask_next) {
|
||||||
|
cout << "We will show your hand in a moment." << endl;
|
||||||
while (true) {
|
while (true) {
|
||||||
cout << "Please select a player you would like to ask between:" << endl;
|
cout << "Please select a player you would like to ask between:" << endl;
|
||||||
cout << "[" << f << " - " << l << "] ";
|
cout << "[" << f << " - " << l << "] ";
|
||||||
cin >> tmp;
|
cin >> tmp;
|
||||||
if ((tmp >= f || tmp <= l) && tmp != p) {
|
if (tmp >= f && tmp <= l && tmp != p) {
|
||||||
ask = tmp;
|
ask = tmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -934,7 +1104,7 @@ public:
|
||||||
cin >> card;
|
cin >> card;
|
||||||
// make string uppercase
|
// make string uppercase
|
||||||
transform(card.begin(), card.end(), card.begin(), ::toupper);
|
transform(card.begin(), card.end(), card.begin(), ::toupper);
|
||||||
if (this->find(card)) {
|
if (this->searchDeck(card)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cin.clear();
|
cin.clear();
|
||||||
|
@ -974,10 +1144,11 @@ public:
|
||||||
cout << endl;
|
cout << endl;
|
||||||
} else {
|
} else {
|
||||||
cout << "The new card was added to your hand...." << endl;
|
cout << "The new card was added to your hand...." << endl;
|
||||||
cout << "Okay it is now the next players turn!" << endl;
|
// player questions
|
||||||
cout << endl;
|
cout << "Player [" << p << "] your turn is over." << endl;
|
||||||
cout << endl;
|
cout << endl << endl << endl << endl << endl << endl;
|
||||||
cout << endl;
|
cout << endl << endl << endl << endl << endl << endl;
|
||||||
|
cout << endl << endl << endl << endl << endl << endl;
|
||||||
get_new_player = true;
|
get_new_player = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user