Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <time.h>
- #include <iomanip>
- #include <algorithm>
- using namespace std;
- int drawL = 60, discL = 0;
- void swap(int& a, int& b) {
- int temp = a;
- a = b;
- b = temp;
- }
- void assignCards(int drawPile[], int rack[]) {
- for (int i = 0; i < 10; i++) {
- rack[i] = drawPile[drawL - 1];
- drawL--;
- }
- }
- void arrayShuffle(int array[]) {
- srand (time(NULL));
- for (int i = drawL - 1; i > 0; i--) {
- int q = rand() % (i + 1);
- swap(array[i], array[q]);
- }
- }
- void arrayAssign(int arrayA[]) {
- for (int i = 0; i < drawL; i++) {
- arrayA[i] = i + 1;
- }
- }
- void printCards(int rack[]){
- for (int i = 0; i < 10; i++) {
- cout << "(" << rack[i] << "," << i << ")" << setw(3);
- }
- cout << endl;
- }
- bool sortCheck(int rack[]) {
- for (int i = 1; i < 10; i ++) {
- if (rack[i] < rack[i - 1]) {
- return false;
- }
- }
- return true;
- }
- int turn(int deck[], int rack[], int disc[], char resp) {
- int inp;
- cout << endl << "-------------------------------" << endl << endl;
- cout << "Player "<< resp << " has:"<<endl;
- printCards(rack);
- cout << endl << "Where do you want to draw from?" << endl;
- cout << "1) Discard Pile (" << disc[discL] << ")" << endl;
- cout << "2) Deck ???" << endl;
- cin >> inp;
- if (inp == 1) {
- cout << "What position card do you want to replace this with?" << endl;
- cout << "Input the position of the card you want to get rid of: ";
- cin >> inp;
- if (inp > 10 || inp < 0) {
- cout << "Error Input" << endl;
- exit(0);
- }
- else {
- int temp = rack[inp];
- rack[inp] = disc[discL];
- discL--;
- if (discL < 0) {
- cout << "The game is tied because there are no more cards in the discard pile." << endl;
- exit(0);
- }
- else {
- discL++;
- disc[discL] = temp;
- bool d = sortCheck(rack);
- if (d) {
- return resp;
- }
- }
- }
- }
- else if (inp == 2) {
- char rep;
- cout << "You drew a: " << deck[drawL] << endl;
- cout << "Would you like to replace it with one from the rack?(y/n)" << endl;
- cin >> rep;
- if (rep == 'y') {
- cout << "Input the position of the card you want to get rid of: ";
- cin >> inp;
- int temp = rack[inp];
- rack[inp] = deck[drawL];
- drawL--;
- if (drawL < 0){
- cout << "The game is tied because there are no more cards in the draw pile.";
- exit(0);
- }
- else {
- discL++;
- disc[discL] = temp;
- cout << "Print: " << disc[discL] << endl;
- bool d = sortCheck(rack);
- cout << d;
- if (d) {
- return resp;
- }
- }
- }
- else if (rep == 'n') {
- discL++;
- disc[discL] = deck[drawL];
- drawL--;
- }
- else {
- cout << "Error input";
- exit(0);
- }
- }
- else {
- cout << "Error input";
- exit(0);
- }
- return 'n';
- }
- int main() {
- int deck[drawL], rackA[10], rackB[10], discard[drawL];
- char ret = 'n';
- arrayAssign(deck);
- arrayShuffle(deck);
- assignCards(deck, rackA);
- assignCards(deck, rackB);
- discard[discL] = deck[drawL];
- //discL++;
- drawL++;
- cout << endl << "--- Welcome to Rack-0 ---" << endl;
- cout << "Find another player and assign teams A or B" << endl;
- cout << "(number on the card , position of the card in the rack)" << endl;
- while (ret == 'n'){
- ret = turn(deck, rackA, discard, 'A');
- if (ret == 'A') {
- cout << "Player A wins" << endl;
- exit(0);
- }
- ret = turn(deck, rackB, discard, 'B');
- if (ret == 'B') {
- cout << "Player B wins" << endl;
- exit(0);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement