Skip to content

Commit

Permalink
Merge pull request #1 from bluestmango/dev
Browse files Browse the repository at this point in the history
Add replay option
  • Loading branch information
bluestmango authored Oct 10, 2024
2 parents d7dfa6a + 48c5471 commit 4898ece
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Simple higher or lower game, designed to be played with a deck of cards. For those unfamiliar, you flip up
the top card and guess whether the next one will be higher or lower than it

Script calculates the statistically best guess & terminates after a wrong one.
Script calculates the statistically best guess & optionally restarts after a wrong one.
Haven't tested what happens if the deck runs out, probably nothing good. Will handle that in future if it's needed
41 changes: 34 additions & 7 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
#include <ctime>
using namespace std;

bool asktoreplay(int& card, bool& lastGuess, vector<int> deck) {

cout << "\nGAME OVER";
cout << "\nReplay? (y/n) ";
char replay;
cin >> replay;

if (replay == 'y') {

card = 0;
lastGuess;
deck = {1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8,
8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13};
return 1;
}
return 0;
}

int main() {

//initialize deck
Expand Down Expand Up @@ -47,6 +65,11 @@ int main() {

card = 1;
}

else if (card == 72 || card == 40 || card == 0) {

card = 10;
}

else if (card == 26 || card == 58) {

Expand All @@ -70,14 +93,18 @@ int main() {
}


//check whether the previous guess was correct. Terminate program if not
if (card > lastCard && lastGuess == 0) {
//check whether the previous guess was correct. Ask to replay if not
if (card > lastCard && lastGuess == 0 || card < lastCard && lastGuess == 1) {

return 0;
}
else if (card < lastCard && lastGuess == 1) {

return 0;
if (asktoreplay(card, lastGuess, deck)) {

continue;
}
else {

return 0;
}

}

//iterate through deck, tally higher/lower cards, & delete pulled card
Expand Down

0 comments on commit 4898ece

Please sign in to comment.