Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // wojna
- //
- // Created by Dawid Siarczyński on 23/11/2019.
- // Copyright © 2019 Dawid Siarczyński. All rights reserved.
- #include <iostream>
- #include <time.h>
- #include <queue>
- #include <stdio.h>
- #define SIZE 52
- using namespace std;
- struct Karta
- {
- char figura;
- char kolor;
- };
- //zmienne globalne
- Karta talia[SIZE];
- char const* const figura[13] =
- { "two of","three of","four of","five of","six of","seven of","eight of","nine of","ten of","jack of","queen of","King of","ace of" };
- char const* const kolor[4] = { "clubs","diamonds","hearts","spades" };
- int counter = 0;
- int decksize;
- int fsize;
- int add;
- queue <int> wplayer_1;
- queue <int> kplayer_1;
- queue <int> wplayer_2;
- queue <int> kplayer_2;
- queue <int> wwar_1;
- queue <int> wwar_2;
- queue <int> kwar_1;
- queue <int> kwar_2;
- queue <int> wcontainer1;
- queue <int> kcontainer1;
- queue <int> wcontainer2;
- queue <int> kcontainer2;
- void zlozTalie(Karta* newdeck, char const* const newFigura, char const* const newKolor)
- {
- for (int i = 0; i < decksize; i++)
- {
- newdeck[i].figura = ((i % fsize) + add);
- newdeck[i].kolor = (i / fsize);
- }
- }
- void tasuj(Karta* newdeck)
- {
- for (int i = 0; i < decksize; i++)
- {
- int j = rand() % decksize;
- Karta t = newdeck[i];
- newdeck[i] = newdeck[j];
- newdeck[j] = t;
- }
- }
- void wyswietl(Karta* newdeck) {
- for (int i = 0; i < decksize; i++) {
- cout << figura[talia[i].figura] << " " << kolor[talia[i].kolor] << endl;
- }
- }
- void rozdaj(Karta* newdeck) {
- for (int i = 0; i < decksize; i++) {
- if (i % 2 == 0) {
- wplayer_1.push(newdeck[i].figura);
- kplayer_1.push(newdeck[i].kolor);
- }
- else {
- wplayer_2.push(newdeck[i].figura);
- kplayer_2.push(newdeck[i].kolor);
- }
- }
- };
- void cleverwar()
- {
- int pl = 0;
- while (!wplayer_1.empty() && !wplayer_2.empty()) {
- int wybor = 0;
- if (pl % 2) {
- if (!wcontainer1.empty()) {
- cout << "Player 1: " << figura[wcontainer1.front()] << " " << kolor[kcontainer1.front()] << " cards: " << wplayer_1.size() << endl;
- }
- else {
- cout << "Player 1: " << figura[wplayer_1.front()] << " " << kolor[kplayer_1.front()] << " cards: " << wplayer_1.size() << endl;
- }
- wcontainer2.push(wplayer_2.front());
- kcontainer2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- cout << " Player 2 pick (1 or 2) : " << " cards: " << wplayer_2.size() << endl;
- cout << "1 : " << figura[wplayer_2.front()] << " " << kolor[kplayer_2.front()] << endl;
- cout << "2 : " << figura[wcontainer2.front()] << " " << kolor[kcontainer2.front()] << endl;
- cin >> wybor;
- if (wybor == 1) {
- if (!wcontainer1.empty()) {
- {
- if (wcontainer1 > wplayer_2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_1.push(wwar_1.front());
- kplayer_1.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_1.push(wwar_2.front());
- kplayer_1.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_1.push(wplayer_2.front());
- kplayer_1.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wplayer_1.push(wcontainer1.front());
- kplayer_1.push(kcontainer1.front());
- kcontainer1.pop();
- wcontainer1.pop();
- if (wplayer_2.empty()) {
- cout << "Player 1 won";
- break;
- }
- pl++;
- }
- else if (wcontainer1 < wplayer_2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_2.push(wwar_1.front());
- kplayer_2.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_2.push(wwar_2.front());
- kplayer_2.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_2.push(wplayer_2.front());
- wplayer_2.pop();
- wplayer_2.push(wcontainer1.front());
- wcontainer1.pop();
- kplayer_2.push(kplayer_2.front());
- kplayer_2.pop();
- kplayer_2.push(kcontainer1.front());
- kcontainer1.pop();
- pl++;
- }
- else if (wcontainer1 == wplayer_2)
- {
- cout << " !!!!!!WAR!!!!!!" << endl;
- if (wplayer_1.size() < 1) {
- cout << " Player 2 won";
- break;
- }
- else if (wplayer_2.size() < 1) {
- cout << "Player 1 won";
- break;
- }
- else {
- wwar_2.push(wcontainer1.front());
- kwar_2.push(kcontainer1.front());
- wcontainer1.pop();
- kcontainer1.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- if (wplayer_1.empty())
- break;
- else if (wplayer_2.empty())
- break;
- else {
- wwar_2.push(wplayer_2.front());
- kwar_2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- pl++;
- cleverwar();
- return;
- }
- }
- }
- else {
- if (wplayer_1 > wplayer_2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_1.push(wwar_1.front());
- kplayer_1.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_1.push(wwar_2.front());
- kplayer_1.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_1.push(wplayer_2.front());
- kplayer_1.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wplayer_1.push(wplayer_1.front());
- kplayer_1.push(kplayer_1.front());
- kplayer_1.pop();
- wplayer_1.pop();
- if (wplayer_2.empty()) {
- cout << "Player 1 won";
- break;
- }
- pl++;
- }
- else if (wplayer_1 < wplayer_2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_2.push(wwar_1.front());
- kplayer_2.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_2.push(wwar_2.front());
- kplayer_2.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_2.push(wplayer_2.front());
- wplayer_2.pop();
- wplayer_2.push(wplayer_1.front());
- wplayer_1.pop();
- kplayer_2.push(kplayer_2.front());
- kplayer_2.pop();
- kplayer_2.push(kplayer_1.front());
- kplayer_1.pop();
- pl++;
- if (wplayer_1.empty()) {
- cout << "Player 2 won";
- break;
- }
- }
- else if (wplayer_1 == wplayer_2)
- {
- cout << " !!!!!!WAR!!!!!!" << endl;
- if (wplayer_1.size() < 1) {
- cout << " Player 2 won";
- break;
- }
- else if (wplayer_2.size() < 1) {
- cout << "Player 1 won";
- break;
- }
- else {
- wwar_2.push(wcontainer2.front());
- kwar_2.push(kcontainer2.front());
- wcontainer2.pop();
- kcontainer2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- if (wplayer_1.empty())
- break;
- else if (wplayer_2.empty())
- break;
- else {
- wwar_2.push(wplayer_2.front());
- kwar_2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- pl++;
- cleverwar();
- return;
- }
- }
- }
- else if (wybor == 2) {
- if (!wcontainer1.empty()) {
- {
- if (wcontainer1 > wcontainer2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_1.push(wwar_1.front());
- kplayer_1.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_1.push(wwar_2.front());
- kplayer_1.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_1.push(wcontainer2.front());
- wcontainer2.pop();
- kplayer_1.push(kcontainer2.front());
- kcontainer2.pop();
- wplayer_1.push(wcontainer1.front());
- wcontainer1.pop();
- kplayer_1.push(kcontainer1.front());
- kcontainer1.pop();
- pl++;
- }
- else if (wcontainer1 < wcontainer2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_2.push(wwar_1.front());
- kplayer_2.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_2.push(wwar_2.front());
- kplayer_2.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_2.push(wcontainer2.front());
- wcontainer2.pop();
- kplayer_2.push(kcontainer2.front());
- kcontainer2.pop();
- wplayer_2.push(wcontainer1.front());
- wcontainer1.pop();
- kplayer_2.push(kcontainer1.front());
- kcontainer1.pop();
- pl++;
- }
- else if (wcontainer1 == wcontainer2)
- {
- cout << " !!!!!!WAR!!!!!!" << endl;
- if (wplayer_1.size() < 1) {
- cout << " Player 2 won";
- break;
- }
- else if (wplayer_2.size() < 1) {
- cout << "Player 1 won";
- break;
- }
- else {
- wwar_2.push(wcontainer2.front());
- kwar_2.push(kcontainer2.front());
- wcontainer2.pop();
- kcontainer2.pop();
- wwar_1.push(wcontainer1.front());
- kwar_1.push(kcontainer1.front());
- wcontainer1.pop();
- kcontainer1.pop();
- }
- if (wplayer_1.empty())
- break;
- else if (wplayer_2.empty())
- break;
- else {
- wwar_2.push(wplayer_2.front());
- kwar_2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- pl++;
- cleverwar();
- return;
- }
- }
- }
- else {
- if (wplayer_1 > wcontainer2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_1.push(wwar_1.front());
- kplayer_1.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_1.push(wwar_2.front());
- kplayer_1.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_1.push(wcontainer2.front());
- wcontainer2.pop();
- kplayer_1.push(kcontainer2.front());
- kcontainer2.pop();
- wplayer_1.push(wplayer_1.front());
- wplayer_1.pop();
- kplayer_1.push(kplayer_1.front());
- kplayer_1.pop();
- pl++;
- }
- else if (wplayer_1 < wcontainer2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_2.push(wwar_1.front());
- kplayer_2.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_2.push(wwar_2.front());
- kplayer_2.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_2.push(wcontainer2.front());
- wcontainer2.pop();
- kplayer_2.push(kcontainer2.front());
- kcontainer2.pop();
- wplayer_2.push(wplayer_1.front());
- wplayer_1.pop();
- kplayer_2.push(kplayer_1.front());
- kplayer_1.pop();
- pl++;
- if (wplayer_1.empty()) {
- cout << "Player 2 won";
- break;
- }
- }
- else if (wplayer_1 == wcontainer2)
- {
- cout << " !!!!!!WAR!!!!!!" << endl;
- if (wplayer_1.size() < 1) {
- cout << " Player 2 won";
- break;
- }
- else if (wplayer_2.size() < 1) {
- cout << "Player 1 won";
- break;
- }
- else {
- wwar_2.push(wcontainer2.front());
- kwar_2.push(kcontainer2.front());
- wcontainer2.pop();
- kcontainer2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- if (wplayer_1.empty())
- break;
- else if (wplayer_2.empty())
- break;
- else {
- wwar_2.push(wplayer_2.front());
- kwar_2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- pl++;
- cleverwar();
- return;
- }
- }
- }
- }
- else {
- if (!wcontainer2.empty()) {
- cout << "Player 2: " << figura[wcontainer2.front()] << " " << kolor[kcontainer2.front()] << "cards: " << wplayer_2.size() << endl;
- }
- else {
- cout << "Player 2: " << figura[wplayer_2.front()] << " " << kolor[kplayer_2.front()] << "cards: " << wplayer_2.size() << endl;
- }
- wcontainer1.push(wplayer_1.front());
- kcontainer1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- cout << " Player 1 pick (1 or 2) : " << "cards: " << wplayer_1.size() << endl;
- cout << "1 : " << figura[wplayer_1.front()] << " " << kolor[kplayer_1.front()] << endl;
- cout << "2 : " << figura[wcontainer1.front()] << " " << kolor[kcontainer1.front()] << endl;
- cin >> wybor;
- if (wybor == 1) {
- if (!wcontainer2.empty()) {
- {
- if (wcontainer2 < wplayer_1)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_1.push(wwar_1.front());
- kplayer_1.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_1.push(wwar_2.front());
- kplayer_1.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_1.push(wcontainer2.front());
- kplayer_1.push(kcontainer2.front());
- wcontainer2.pop();
- kcontainer2.pop();
- wplayer_1.push(wplayer_1.front());
- kplayer_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- pl++;
- }
- else if (wcontainer2 > wplayer_1)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_2.push(wwar_1.front());
- kplayer_2.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_2.push(wwar_2.front());
- kplayer_2.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_2.push(wplayer_1.front());
- wplayer_1.pop();
- wplayer_2.push(wcontainer2.front());
- wcontainer2.pop();
- kplayer_2.push(kplayer_1.front());
- kplayer_2.pop();
- kplayer_2.push(kcontainer2.front());
- kcontainer2.pop();
- if (wplayer_1.empty()) {
- cout << "Player 2 won";
- break;
- }
- pl++;
- }
- else if (wcontainer2 == wplayer_1)
- {
- cout << " !!!!!!WAR!!!!!!" << endl;
- if (wplayer_1.size() < 1) {
- cout << " Player 2 won";
- break;
- }
- else if (wplayer_2.size() < 1) {
- cout << "Player 1 won";
- break;
- }
- else {
- wwar_2.push(wcontainer2.front());
- kwar_2.push(kcontainer2.front());
- wcontainer2.pop();
- kcontainer2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- if (wplayer_1.empty())
- break;
- else if (wplayer_2.empty())
- break;
- else {
- wwar_2.push(wplayer_2.front());
- kwar_2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- pl++;
- cleverwar();
- return;
- }
- }
- }
- else {
- if (wplayer_1 > wplayer_2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_1.push(wwar_1.front());
- kplayer_1.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_1.push(wwar_2.front());
- kplayer_1.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_1.push(wplayer_2.front());
- wplayer_2.pop();
- kplayer_1.push(kplayer_2.front());
- kplayer_2.pop();
- wplayer_1.push(wplayer_1.front());
- wplayer_1.pop();
- kplayer_1.push(kplayer_1.front());
- kplayer_1.pop();
- if (wplayer_2.empty()) {
- cout << "Player 1 won";
- break;
- }
- pl++;
- }
- else if (wplayer_1 < wplayer_2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_2.push(wwar_1.front());
- kplayer_2.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_2.push(wwar_2.front());
- kplayer_2.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_2.push(wplayer_2.front());
- wplayer_2.pop();
- kplayer_2.push(kplayer_2.front());
- kplayer_2.pop();
- wplayer_2.push(wplayer_1.front());
- wplayer_1.pop();
- kplayer_2.push(kplayer_1.front());
- kplayer_1.pop();
- if (wplayer_1.empty()) {
- cout << "Player 2 won";
- break;
- }
- pl++;
- }
- else if (wplayer_1 == wplayer_2)
- {
- cout << " !!!!!!WAR!!!!!!" << endl;
- if (wplayer_1.size() < 1) {
- cout << " Player 2 won";
- break;
- }
- else if (wplayer_2.size() < 1) {
- cout << "Player 1 won";
- break;
- }
- else {
- wwar_2.push(wcontainer2.front());
- kwar_2.push(kcontainer2.front());
- wcontainer2.pop();
- kcontainer2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- if (wplayer_1.empty())
- break;
- else if (wplayer_2.empty())
- break;
- else {
- wwar_2.push(wplayer_2.front());
- kwar_2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- pl++;
- cleverwar();
- return;
- }
- }
- }
- else if (wybor == 2) {
- if (!wcontainer2.empty()) {
- {
- if (wcontainer1 > wcontainer2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_1.push(wwar_1.front());
- kplayer_1.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_1.push(wwar_2.front());
- kplayer_1.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_1.push(wcontainer2.front());
- wcontainer2.pop();
- kplayer_1.push(kcontainer2.front());
- kcontainer2.pop();
- wplayer_1.push(wcontainer1.front());
- wcontainer1.pop();
- kplayer_1.push(kcontainer1.front());
- kcontainer1.pop();
- pl++;
- }
- else if (wcontainer1 < wcontainer2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_2.push(wwar_1.front());
- kplayer_2.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_2.push(wwar_2.front());
- kplayer_2.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_2.push(wcontainer2.front());
- wcontainer2.pop();
- kplayer_2.push(kcontainer2.front());
- kcontainer2.pop();
- wplayer_2.push(wcontainer1.front());
- wcontainer1.pop();
- kplayer_2.push(kcontainer1.front());
- kcontainer1.pop();
- pl++;
- }
- else if (wcontainer1 == wcontainer2)
- {
- cout << " !!!!!!WAR!!!!!!" << endl;
- if (wplayer_1.size() < 1) {
- cout << " Player 2 won";
- break;
- }
- else if (wplayer_2.size() < 1) {
- cout << "Player 1 won";
- break;
- }
- else {
- wwar_2.push(wcontainer2.front());
- kwar_2.push(kcontainer2.front());
- wcontainer2.pop();
- kcontainer2.pop();
- wwar_1.push(wcontainer1.front());
- kwar_1.push(kcontainer1.front());
- wcontainer1.pop();
- kcontainer1.pop();
- }
- if (wplayer_1.empty())
- break;
- else if (wplayer_2.empty())
- break;
- else {
- wwar_2.push(wplayer_2.front());
- kwar_2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- pl++;
- cleverwar();
- return;
- }
- }
- }
- else {
- if (wcontainer1 > wplayer_2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_1.push(wwar_1.front());
- kplayer_1.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_1.push(wwar_2.front());
- kplayer_1.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_1.push(wcontainer1.front());
- wcontainer1.pop();
- kplayer_1.push(kcontainer1.front());
- kcontainer1.pop();
- wplayer_1.push(wplayer_2.front());
- wplayer_2.pop();
- kplayer_1.push(kplayer_2.front());
- kplayer_2.pop();
- pl++;
- }
- else if (wcontainer1 < wplayer_2)
- {
- while (!wwar_1.empty() && !kwar_1.empty()) {
- wplayer_2.push(wwar_1.front());
- kplayer_2.push(kwar_1.front());
- wwar_1.pop();
- kwar_1.pop();
- }
- while (!wwar_2.empty() && !kwar_2.empty()) {
- wplayer_2.push(wwar_2.front());
- kplayer_2.push(kwar_2.front());
- wwar_2.pop();
- kwar_2.pop();
- }
- wplayer_2.push(wcontainer1.front());
- wcontainer1.pop();
- kplayer_2.push(kcontainer1.front());
- kcontainer1.pop();
- wplayer_2.push(wplayer_2.front());
- wplayer_2.pop();
- kplayer_2.push(kplayer_2.front());
- kplayer_2.pop();
- if (wplayer_1.empty()) {
- cout << "Player 2 won";
- break;
- }
- pl++;
- }
- else if (wplayer_2 == wcontainer1)
- {
- cout << " !!!!!!WAR!!!!!!" << endl;
- if (wplayer_1.size() < 1) {
- cout << " Player 2 won";
- break;
- }
- else if (wplayer_2.size() < 1) {
- cout << "Player 1 won";
- break;
- }
- else {
- wwar_1.push(wcontainer1.front());
- kwar_1.push(kcontainer1.front());
- wcontainer1.pop();
- kcontainer1.pop();
- wwar_2.push(wplayer_2.front());
- kwar_2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- }
- if (wplayer_1.empty())
- break;
- else if (wplayer_2.empty())
- break;
- else {
- wwar_2.push(wplayer_2.front());
- kwar_2.push(kplayer_2.front());
- wplayer_2.pop();
- kplayer_2.pop();
- wwar_1.push(wplayer_1.front());
- kwar_1.push(kplayer_1.front());
- wplayer_1.pop();
- kplayer_1.pop();
- }
- pl++;
- cleverwar();
- return;
- }
- }
- }
- }
- }
- }
- int main()
- {
- srand(time(0));
- cout << "Pick size of a deck (must be divisible by 4): ";
- cin >> decksize;
- fsize = (decksize / 4);
- add = (52 - decksize) / 4;
- zlozTalie(talia, *figura, *kolor);
- tasuj(talia);
- rozdaj(talia);
- cleverwar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement