Advertisement
Guest User

cleverwar

a guest
Dec 15th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.11 KB | None | 0 0
  1. //
  2. // main.cpp
  3. // wojna
  4. //
  5. // Created by Dawid Siarczyński on 23/11/2019.
  6. // Copyright © 2019 Dawid Siarczyński. All rights reserved.
  7.  
  8. #include <iostream>
  9. #include <time.h>
  10. #include <queue>
  11. #include <stdio.h>
  12. #define SIZE 52
  13. using namespace std;
  14.  
  15. struct Karta
  16. {
  17. char figura;
  18. char kolor;
  19. };
  20. //zmienne globalne
  21. Karta talia[SIZE];
  22.  
  23. char const* const figura[13] =
  24. { "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" };
  25. char const* const kolor[4] = { "clubs","diamonds","hearts","spades" };
  26. int counter = 0;
  27. int decksize;
  28. int fsize;
  29. int add;
  30. queue <int> wplayer_1;
  31. queue <int> kplayer_1;
  32. queue <int> wplayer_2;
  33. queue <int> kplayer_2;
  34. queue <int> wwar_1;
  35. queue <int> wwar_2;
  36. queue <int> kwar_1;
  37. queue <int> kwar_2;
  38. queue <int> wcontainer1;
  39. queue <int> kcontainer1;
  40. queue <int> wcontainer2;
  41. queue <int> kcontainer2;
  42.  
  43.  
  44. void zlozTalie(Karta* newdeck, char const* const newFigura, char const* const newKolor)
  45. {
  46. for (int i = 0; i < decksize; i++)
  47. {
  48.  
  49. newdeck[i].figura = ((i % fsize) + add);
  50. newdeck[i].kolor = (i / fsize);
  51.  
  52. }
  53. }
  54. void tasuj(Karta* newdeck)
  55. {
  56. for (int i = 0; i < decksize; i++)
  57. {
  58. int j = rand() % decksize;
  59. Karta t = newdeck[i];
  60. newdeck[i] = newdeck[j];
  61. newdeck[j] = t;
  62. }
  63. }
  64. void wyswietl(Karta* newdeck) {
  65. for (int i = 0; i < decksize; i++) {
  66. cout << figura[talia[i].figura] << " " << kolor[talia[i].kolor] << endl;
  67. }
  68. }
  69. void rozdaj(Karta* newdeck) {
  70. for (int i = 0; i < decksize; i++) {
  71. if (i % 2 == 0) {
  72. wplayer_1.push(newdeck[i].figura);
  73. kplayer_1.push(newdeck[i].kolor);
  74. }
  75. else {
  76. wplayer_2.push(newdeck[i].figura);
  77. kplayer_2.push(newdeck[i].kolor);
  78. }
  79. }
  80. };
  81.  
  82. void cleverwar()
  83. {
  84. int pl = 0;
  85. while (!wplayer_1.empty() && !wplayer_2.empty()) {
  86. int wybor = 0;
  87.  
  88. if (pl % 2) {
  89. if (!wcontainer1.empty()) {
  90. cout << "Player 1: " << figura[wcontainer1.front()] << " " << kolor[kcontainer1.front()] << " cards: " << wplayer_1.size() << endl;
  91. }
  92. else {
  93. cout << "Player 1: " << figura[wplayer_1.front()] << " " << kolor[kplayer_1.front()] << " cards: " << wplayer_1.size() << endl;
  94.  
  95. }
  96. wcontainer2.push(wplayer_2.front());
  97. kcontainer2.push(kplayer_2.front());
  98. wplayer_2.pop();
  99. kplayer_2.pop();
  100.  
  101. cout << " Player 2 pick (1 or 2) : " << " cards: " << wplayer_2.size() << endl;
  102. cout << "1 : " << figura[wplayer_2.front()] << " " << kolor[kplayer_2.front()] << endl;
  103. cout << "2 : " << figura[wcontainer2.front()] << " " << kolor[kcontainer2.front()] << endl;
  104. cin >> wybor;
  105. if (wybor == 1) {
  106.  
  107. if (!wcontainer1.empty()) {
  108. {
  109. if (wcontainer1 > wplayer_2)
  110. {
  111. while (!wwar_1.empty() && !kwar_1.empty()) {
  112. wplayer_1.push(wwar_1.front());
  113. kplayer_1.push(kwar_1.front());
  114. wwar_1.pop();
  115. kwar_1.pop();
  116. }
  117. while (!wwar_2.empty() && !kwar_2.empty()) {
  118. wplayer_1.push(wwar_2.front());
  119. kplayer_1.push(kwar_2.front());
  120. wwar_2.pop();
  121. kwar_2.pop();
  122. }
  123.  
  124. wplayer_1.push(wplayer_2.front());
  125. kplayer_1.push(kplayer_2.front());
  126. wplayer_2.pop();
  127. kplayer_2.pop();
  128. wplayer_1.push(wcontainer1.front());
  129. kplayer_1.push(kcontainer1.front());
  130. kcontainer1.pop();
  131. wcontainer1.pop();
  132. if (wplayer_2.empty()) {
  133. cout << "Player 1 won";
  134. break;
  135. }
  136. pl++;
  137. }
  138. else if (wcontainer1 < wplayer_2)
  139. {
  140. while (!wwar_1.empty() && !kwar_1.empty()) {
  141. wplayer_2.push(wwar_1.front());
  142. kplayer_2.push(kwar_1.front());
  143. wwar_1.pop();
  144. kwar_1.pop();
  145. }
  146. while (!wwar_2.empty() && !kwar_2.empty()) {
  147. wplayer_2.push(wwar_2.front());
  148. kplayer_2.push(kwar_2.front());
  149. wwar_2.pop();
  150. kwar_2.pop();
  151. }
  152.  
  153. wplayer_2.push(wplayer_2.front());
  154. wplayer_2.pop();
  155. wplayer_2.push(wcontainer1.front());
  156. wcontainer1.pop();
  157. kplayer_2.push(kplayer_2.front());
  158. kplayer_2.pop();
  159. kplayer_2.push(kcontainer1.front());
  160. kcontainer1.pop();
  161. pl++;
  162. }
  163. else if (wcontainer1 == wplayer_2)
  164. {
  165. cout << " !!!!!!WAR!!!!!!" << endl;
  166. if (wplayer_1.size() < 1) {
  167. cout << " Player 2 won";
  168. break;
  169. }
  170. else if (wplayer_2.size() < 1) {
  171. cout << "Player 1 won";
  172. break;
  173. }
  174. else {
  175. wwar_2.push(wcontainer1.front());
  176. kwar_2.push(kcontainer1.front());
  177. wcontainer1.pop();
  178. kcontainer1.pop();
  179. wwar_1.push(wplayer_1.front());
  180. kwar_1.push(kplayer_1.front());
  181. wplayer_1.pop();
  182. kplayer_1.pop();
  183.  
  184. }
  185. if (wplayer_1.empty())
  186. break;
  187. else if (wplayer_2.empty())
  188. break;
  189. else {
  190. wwar_2.push(wplayer_2.front());
  191. kwar_2.push(kplayer_2.front());
  192. wplayer_2.pop();
  193. kplayer_2.pop();
  194. wwar_1.push(wplayer_1.front());
  195. kwar_1.push(kplayer_1.front());
  196. wplayer_1.pop();
  197. kplayer_1.pop();
  198. }
  199. pl++;
  200. cleverwar();
  201. return;
  202. }
  203.  
  204.  
  205.  
  206. }
  207. }
  208. else {
  209. if (wplayer_1 > wplayer_2)
  210. {
  211. while (!wwar_1.empty() && !kwar_1.empty()) {
  212. wplayer_1.push(wwar_1.front());
  213. kplayer_1.push(kwar_1.front());
  214. wwar_1.pop();
  215. kwar_1.pop();
  216. }
  217. while (!wwar_2.empty() && !kwar_2.empty()) {
  218. wplayer_1.push(wwar_2.front());
  219. kplayer_1.push(kwar_2.front());
  220. wwar_2.pop();
  221. kwar_2.pop();
  222. }
  223.  
  224. wplayer_1.push(wplayer_2.front());
  225. kplayer_1.push(kplayer_2.front());
  226. wplayer_2.pop();
  227. kplayer_2.pop();
  228. wplayer_1.push(wplayer_1.front());
  229. kplayer_1.push(kplayer_1.front());
  230. kplayer_1.pop();
  231. wplayer_1.pop();
  232. if (wplayer_2.empty()) {
  233. cout << "Player 1 won";
  234. break;
  235. }
  236. pl++;
  237. }
  238. else if (wplayer_1 < wplayer_2)
  239. {
  240. while (!wwar_1.empty() && !kwar_1.empty()) {
  241. wplayer_2.push(wwar_1.front());
  242. kplayer_2.push(kwar_1.front());
  243. wwar_1.pop();
  244. kwar_1.pop();
  245. }
  246. while (!wwar_2.empty() && !kwar_2.empty()) {
  247. wplayer_2.push(wwar_2.front());
  248. kplayer_2.push(kwar_2.front());
  249. wwar_2.pop();
  250. kwar_2.pop();
  251. }
  252.  
  253. wplayer_2.push(wplayer_2.front());
  254. wplayer_2.pop();
  255. wplayer_2.push(wplayer_1.front());
  256. wplayer_1.pop();
  257. kplayer_2.push(kplayer_2.front());
  258. kplayer_2.pop();
  259. kplayer_2.push(kplayer_1.front());
  260. kplayer_1.pop();
  261. pl++;
  262. if (wplayer_1.empty()) {
  263. cout << "Player 2 won";
  264. break;
  265. }
  266. }
  267. else if (wplayer_1 == wplayer_2)
  268. {
  269. cout << " !!!!!!WAR!!!!!!" << endl;
  270. if (wplayer_1.size() < 1) {
  271. cout << " Player 2 won";
  272. break;
  273. }
  274. else if (wplayer_2.size() < 1) {
  275. cout << "Player 1 won";
  276. break;
  277. }
  278. else {
  279. wwar_2.push(wcontainer2.front());
  280. kwar_2.push(kcontainer2.front());
  281. wcontainer2.pop();
  282. kcontainer2.pop();
  283. wwar_1.push(wplayer_1.front());
  284. kwar_1.push(kplayer_1.front());
  285. wplayer_1.pop();
  286. kplayer_1.pop();
  287.  
  288. }
  289. if (wplayer_1.empty())
  290. break;
  291. else if (wplayer_2.empty())
  292. break;
  293. else {
  294. wwar_2.push(wplayer_2.front());
  295. kwar_2.push(kplayer_2.front());
  296. wplayer_2.pop();
  297. kplayer_2.pop();
  298. wwar_1.push(wplayer_1.front());
  299. kwar_1.push(kplayer_1.front());
  300. wplayer_1.pop();
  301. kplayer_1.pop();
  302. }
  303. pl++;
  304. cleverwar();
  305. return;
  306. }
  307.  
  308.  
  309.  
  310. }
  311. }
  312. else if (wybor == 2) {
  313. if (!wcontainer1.empty()) {
  314. {
  315. if (wcontainer1 > wcontainer2)
  316. {
  317. while (!wwar_1.empty() && !kwar_1.empty()) {
  318. wplayer_1.push(wwar_1.front());
  319. kplayer_1.push(kwar_1.front());
  320. wwar_1.pop();
  321. kwar_1.pop();
  322. }
  323. while (!wwar_2.empty() && !kwar_2.empty()) {
  324. wplayer_1.push(wwar_2.front());
  325. kplayer_1.push(kwar_2.front());
  326. wwar_2.pop();
  327. kwar_2.pop();
  328. }
  329.  
  330. wplayer_1.push(wcontainer2.front());
  331. wcontainer2.pop();
  332. kplayer_1.push(kcontainer2.front());
  333. kcontainer2.pop();
  334. wplayer_1.push(wcontainer1.front());
  335. wcontainer1.pop();
  336. kplayer_1.push(kcontainer1.front());
  337. kcontainer1.pop();
  338. pl++;
  339. }
  340. else if (wcontainer1 < wcontainer2)
  341. {
  342. while (!wwar_1.empty() && !kwar_1.empty()) {
  343. wplayer_2.push(wwar_1.front());
  344. kplayer_2.push(kwar_1.front());
  345. wwar_1.pop();
  346. kwar_1.pop();
  347. }
  348. while (!wwar_2.empty() && !kwar_2.empty()) {
  349. wplayer_2.push(wwar_2.front());
  350. kplayer_2.push(kwar_2.front());
  351. wwar_2.pop();
  352. kwar_2.pop();
  353. }
  354.  
  355. wplayer_2.push(wcontainer2.front());
  356. wcontainer2.pop();
  357. kplayer_2.push(kcontainer2.front());
  358. kcontainer2.pop();
  359. wplayer_2.push(wcontainer1.front());
  360. wcontainer1.pop();
  361. kplayer_2.push(kcontainer1.front());
  362. kcontainer1.pop();
  363. pl++;
  364. }
  365. else if (wcontainer1 == wcontainer2)
  366. {
  367. cout << " !!!!!!WAR!!!!!!" << endl;
  368. if (wplayer_1.size() < 1) {
  369. cout << " Player 2 won";
  370. break;
  371. }
  372. else if (wplayer_2.size() < 1) {
  373. cout << "Player 1 won";
  374. break;
  375. }
  376. else {
  377. wwar_2.push(wcontainer2.front());
  378. kwar_2.push(kcontainer2.front());
  379. wcontainer2.pop();
  380. kcontainer2.pop();
  381. wwar_1.push(wcontainer1.front());
  382. kwar_1.push(kcontainer1.front());
  383. wcontainer1.pop();
  384. kcontainer1.pop();
  385.  
  386. }
  387. if (wplayer_1.empty())
  388. break;
  389. else if (wplayer_2.empty())
  390. break;
  391. else {
  392. wwar_2.push(wplayer_2.front());
  393. kwar_2.push(kplayer_2.front());
  394. wplayer_2.pop();
  395. kplayer_2.pop();
  396. wwar_1.push(wplayer_1.front());
  397. kwar_1.push(kplayer_1.front());
  398. wplayer_1.pop();
  399. kplayer_1.pop();
  400. }
  401. pl++;
  402. cleverwar();
  403. return;
  404. }
  405. }
  406. }
  407.  
  408. else {
  409. if (wplayer_1 > wcontainer2)
  410. {
  411. while (!wwar_1.empty() && !kwar_1.empty()) {
  412. wplayer_1.push(wwar_1.front());
  413. kplayer_1.push(kwar_1.front());
  414. wwar_1.pop();
  415. kwar_1.pop();
  416. }
  417. while (!wwar_2.empty() && !kwar_2.empty()) {
  418. wplayer_1.push(wwar_2.front());
  419. kplayer_1.push(kwar_2.front());
  420. wwar_2.pop();
  421. kwar_2.pop();
  422. }
  423.  
  424. wplayer_1.push(wcontainer2.front());
  425. wcontainer2.pop();
  426. kplayer_1.push(kcontainer2.front());
  427. kcontainer2.pop();
  428. wplayer_1.push(wplayer_1.front());
  429. wplayer_1.pop();
  430. kplayer_1.push(kplayer_1.front());
  431. kplayer_1.pop();
  432.  
  433.  
  434. pl++;
  435. }
  436. else if (wplayer_1 < wcontainer2)
  437. {
  438. while (!wwar_1.empty() && !kwar_1.empty()) {
  439. wplayer_2.push(wwar_1.front());
  440. kplayer_2.push(kwar_1.front());
  441. wwar_1.pop();
  442. kwar_1.pop();
  443. }
  444. while (!wwar_2.empty() && !kwar_2.empty()) {
  445. wplayer_2.push(wwar_2.front());
  446. kplayer_2.push(kwar_2.front());
  447. wwar_2.pop();
  448. kwar_2.pop();
  449. }
  450.  
  451. wplayer_2.push(wcontainer2.front());
  452. wcontainer2.pop();
  453. kplayer_2.push(kcontainer2.front());
  454. kcontainer2.pop();
  455. wplayer_2.push(wplayer_1.front());
  456. wplayer_1.pop();
  457. kplayer_2.push(kplayer_1.front());
  458. kplayer_1.pop();
  459. pl++;
  460. if (wplayer_1.empty()) {
  461. cout << "Player 2 won";
  462. break;
  463. }
  464. }
  465. else if (wplayer_1 == wcontainer2)
  466. {
  467. cout << " !!!!!!WAR!!!!!!" << endl;
  468. if (wplayer_1.size() < 1) {
  469. cout << " Player 2 won";
  470. break;
  471. }
  472. else if (wplayer_2.size() < 1) {
  473. cout << "Player 1 won";
  474. break;
  475. }
  476. else {
  477. wwar_2.push(wcontainer2.front());
  478. kwar_2.push(kcontainer2.front());
  479. wcontainer2.pop();
  480. kcontainer2.pop();
  481. wwar_1.push(wplayer_1.front());
  482. kwar_1.push(kplayer_1.front());
  483. wplayer_1.pop();
  484. kplayer_1.pop();
  485.  
  486. }
  487. if (wplayer_1.empty())
  488. break;
  489. else if (wplayer_2.empty())
  490. break;
  491. else {
  492. wwar_2.push(wplayer_2.front());
  493. kwar_2.push(kplayer_2.front());
  494. wplayer_2.pop();
  495. kplayer_2.pop();
  496. wwar_1.push(wplayer_1.front());
  497. kwar_1.push(kplayer_1.front());
  498. wplayer_1.pop();
  499. kplayer_1.pop();
  500. }
  501. pl++;
  502. cleverwar();
  503. return;
  504. }
  505. }
  506. }
  507. }
  508. else {
  509. if (!wcontainer2.empty()) {
  510. cout << "Player 2: " << figura[wcontainer2.front()] << " " << kolor[kcontainer2.front()] << "cards: " << wplayer_2.size() << endl;
  511.  
  512. }
  513. else {
  514. cout << "Player 2: " << figura[wplayer_2.front()] << " " << kolor[kplayer_2.front()] << "cards: " << wplayer_2.size() << endl;
  515. }
  516. wcontainer1.push(wplayer_1.front());
  517. kcontainer1.push(kplayer_1.front());
  518. wplayer_1.pop();
  519. kplayer_1.pop();
  520. cout << " Player 1 pick (1 or 2) : " << "cards: " << wplayer_1.size() << endl;
  521. cout << "1 : " << figura[wplayer_1.front()] << " " << kolor[kplayer_1.front()] << endl;
  522. cout << "2 : " << figura[wcontainer1.front()] << " " << kolor[kcontainer1.front()] << endl;
  523. cin >> wybor;
  524. if (wybor == 1) {
  525. if (!wcontainer2.empty()) {
  526. {
  527. if (wcontainer2 < wplayer_1)
  528. {
  529. while (!wwar_1.empty() && !kwar_1.empty()) {
  530. wplayer_1.push(wwar_1.front());
  531. kplayer_1.push(kwar_1.front());
  532. wwar_1.pop();
  533. kwar_1.pop();
  534. }
  535. while (!wwar_2.empty() && !kwar_2.empty()) {
  536. wplayer_1.push(wwar_2.front());
  537. kplayer_1.push(kwar_2.front());
  538. wwar_2.pop();
  539. kwar_2.pop();
  540. }
  541.  
  542. wplayer_1.push(wcontainer2.front());
  543. kplayer_1.push(kcontainer2.front());
  544. wcontainer2.pop();
  545. kcontainer2.pop();
  546. wplayer_1.push(wplayer_1.front());
  547. kplayer_1.push(kplayer_1.front());
  548. wplayer_1.pop();
  549. kplayer_1.pop();
  550. pl++;
  551. }
  552. else if (wcontainer2 > wplayer_1)
  553. {
  554. while (!wwar_1.empty() && !kwar_1.empty()) {
  555. wplayer_2.push(wwar_1.front());
  556. kplayer_2.push(kwar_1.front());
  557. wwar_1.pop();
  558. kwar_1.pop();
  559. }
  560. while (!wwar_2.empty() && !kwar_2.empty()) {
  561. wplayer_2.push(wwar_2.front());
  562. kplayer_2.push(kwar_2.front());
  563. wwar_2.pop();
  564. kwar_2.pop();
  565. }
  566.  
  567. wplayer_2.push(wplayer_1.front());
  568. wplayer_1.pop();
  569. wplayer_2.push(wcontainer2.front());
  570. wcontainer2.pop();
  571. kplayer_2.push(kplayer_1.front());
  572. kplayer_2.pop();
  573. kplayer_2.push(kcontainer2.front());
  574. kcontainer2.pop();
  575. if (wplayer_1.empty()) {
  576. cout << "Player 2 won";
  577. break;
  578. }
  579. pl++;
  580.  
  581. }
  582. else if (wcontainer2 == wplayer_1)
  583. {
  584. cout << " !!!!!!WAR!!!!!!" << endl;
  585. if (wplayer_1.size() < 1) {
  586. cout << " Player 2 won";
  587. break;
  588. }
  589. else if (wplayer_2.size() < 1) {
  590. cout << "Player 1 won";
  591. break;
  592. }
  593. else {
  594. wwar_2.push(wcontainer2.front());
  595. kwar_2.push(kcontainer2.front());
  596. wcontainer2.pop();
  597. kcontainer2.pop();
  598. wwar_1.push(wplayer_1.front());
  599. kwar_1.push(kplayer_1.front());
  600. wplayer_1.pop();
  601. kplayer_1.pop();
  602.  
  603. }
  604. if (wplayer_1.empty())
  605. break;
  606. else if (wplayer_2.empty())
  607. break;
  608. else {
  609. wwar_2.push(wplayer_2.front());
  610. kwar_2.push(kplayer_2.front());
  611. wplayer_2.pop();
  612. kplayer_2.pop();
  613. wwar_1.push(wplayer_1.front());
  614. kwar_1.push(kplayer_1.front());
  615. wplayer_1.pop();
  616. kplayer_1.pop();
  617. }
  618. pl++;
  619. cleverwar();
  620. return;
  621. }
  622.  
  623.  
  624.  
  625. }
  626. }
  627. else {
  628. if (wplayer_1 > wplayer_2)
  629. {
  630. while (!wwar_1.empty() && !kwar_1.empty()) {
  631. wplayer_1.push(wwar_1.front());
  632. kplayer_1.push(kwar_1.front());
  633. wwar_1.pop();
  634. kwar_1.pop();
  635. }
  636. while (!wwar_2.empty() && !kwar_2.empty()) {
  637. wplayer_1.push(wwar_2.front());
  638. kplayer_1.push(kwar_2.front());
  639. wwar_2.pop();
  640. kwar_2.pop();
  641. }
  642.  
  643. wplayer_1.push(wplayer_2.front());
  644. wplayer_2.pop();
  645. kplayer_1.push(kplayer_2.front());
  646. kplayer_2.pop();
  647. wplayer_1.push(wplayer_1.front());
  648. wplayer_1.pop();
  649. kplayer_1.push(kplayer_1.front());
  650. kplayer_1.pop();
  651. if (wplayer_2.empty()) {
  652. cout << "Player 1 won";
  653. break;
  654. }
  655. pl++;
  656. }
  657. else if (wplayer_1 < wplayer_2)
  658. {
  659. while (!wwar_1.empty() && !kwar_1.empty()) {
  660. wplayer_2.push(wwar_1.front());
  661. kplayer_2.push(kwar_1.front());
  662. wwar_1.pop();
  663. kwar_1.pop();
  664. }
  665. while (!wwar_2.empty() && !kwar_2.empty()) {
  666. wplayer_2.push(wwar_2.front());
  667. kplayer_2.push(kwar_2.front());
  668. wwar_2.pop();
  669. kwar_2.pop();
  670. }
  671.  
  672. wplayer_2.push(wplayer_2.front());
  673. wplayer_2.pop();
  674. kplayer_2.push(kplayer_2.front());
  675. kplayer_2.pop();
  676. wplayer_2.push(wplayer_1.front());
  677. wplayer_1.pop();
  678. kplayer_2.push(kplayer_1.front());
  679. kplayer_1.pop();
  680. if (wplayer_1.empty()) {
  681. cout << "Player 2 won";
  682. break;
  683. }
  684. pl++;
  685. }
  686. else if (wplayer_1 == wplayer_2)
  687. {
  688. cout << " !!!!!!WAR!!!!!!" << endl;
  689. if (wplayer_1.size() < 1) {
  690. cout << " Player 2 won";
  691. break;
  692. }
  693. else if (wplayer_2.size() < 1) {
  694. cout << "Player 1 won";
  695. break;
  696. }
  697. else {
  698. wwar_2.push(wcontainer2.front());
  699. kwar_2.push(kcontainer2.front());
  700. wcontainer2.pop();
  701. kcontainer2.pop();
  702. wwar_1.push(wplayer_1.front());
  703. kwar_1.push(kplayer_1.front());
  704. wplayer_1.pop();
  705. kplayer_1.pop();
  706.  
  707. }
  708. if (wplayer_1.empty())
  709. break;
  710. else if (wplayer_2.empty())
  711. break;
  712. else {
  713. wwar_2.push(wplayer_2.front());
  714. kwar_2.push(kplayer_2.front());
  715. wplayer_2.pop();
  716. kplayer_2.pop();
  717. wwar_1.push(wplayer_1.front());
  718. kwar_1.push(kplayer_1.front());
  719. wplayer_1.pop();
  720. kplayer_1.pop();
  721. }
  722. pl++;
  723. cleverwar();
  724. return;
  725. }
  726. }
  727. }
  728.  
  729.  
  730.  
  731.  
  732. else if (wybor == 2) {
  733. if (!wcontainer2.empty()) {
  734. {
  735. if (wcontainer1 > wcontainer2)
  736. {
  737. while (!wwar_1.empty() && !kwar_1.empty()) {
  738. wplayer_1.push(wwar_1.front());
  739. kplayer_1.push(kwar_1.front());
  740. wwar_1.pop();
  741. kwar_1.pop();
  742. }
  743. while (!wwar_2.empty() && !kwar_2.empty()) {
  744. wplayer_1.push(wwar_2.front());
  745. kplayer_1.push(kwar_2.front());
  746. wwar_2.pop();
  747. kwar_2.pop();
  748. }
  749.  
  750. wplayer_1.push(wcontainer2.front());
  751. wcontainer2.pop();
  752. kplayer_1.push(kcontainer2.front());
  753. kcontainer2.pop();
  754. wplayer_1.push(wcontainer1.front());
  755. wcontainer1.pop();
  756. kplayer_1.push(kcontainer1.front());
  757. kcontainer1.pop();
  758. pl++;
  759. }
  760. else if (wcontainer1 < wcontainer2)
  761. {
  762. while (!wwar_1.empty() && !kwar_1.empty()) {
  763. wplayer_2.push(wwar_1.front());
  764. kplayer_2.push(kwar_1.front());
  765. wwar_1.pop();
  766. kwar_1.pop();
  767. }
  768. while (!wwar_2.empty() && !kwar_2.empty()) {
  769. wplayer_2.push(wwar_2.front());
  770. kplayer_2.push(kwar_2.front());
  771. wwar_2.pop();
  772. kwar_2.pop();
  773. }
  774.  
  775. wplayer_2.push(wcontainer2.front());
  776. wcontainer2.pop();
  777. kplayer_2.push(kcontainer2.front());
  778. kcontainer2.pop();
  779. wplayer_2.push(wcontainer1.front());
  780. wcontainer1.pop();
  781. kplayer_2.push(kcontainer1.front());
  782. kcontainer1.pop();
  783. pl++;
  784. }
  785. else if (wcontainer1 == wcontainer2)
  786. {
  787. cout << " !!!!!!WAR!!!!!!" << endl;
  788. if (wplayer_1.size() < 1) {
  789. cout << " Player 2 won";
  790. break;
  791. }
  792. else if (wplayer_2.size() < 1) {
  793. cout << "Player 1 won";
  794. break;
  795. }
  796. else {
  797. wwar_2.push(wcontainer2.front());
  798. kwar_2.push(kcontainer2.front());
  799. wcontainer2.pop();
  800. kcontainer2.pop();
  801. wwar_1.push(wcontainer1.front());
  802. kwar_1.push(kcontainer1.front());
  803. wcontainer1.pop();
  804. kcontainer1.pop();
  805.  
  806. }
  807. if (wplayer_1.empty())
  808. break;
  809. else if (wplayer_2.empty())
  810. break;
  811. else {
  812. wwar_2.push(wplayer_2.front());
  813. kwar_2.push(kplayer_2.front());
  814. wplayer_2.pop();
  815. kplayer_2.pop();
  816. wwar_1.push(wplayer_1.front());
  817. kwar_1.push(kplayer_1.front());
  818. wplayer_1.pop();
  819. kplayer_1.pop();
  820. }
  821. pl++;
  822. cleverwar();
  823. return;
  824. }
  825. }
  826. }
  827. else {
  828. if (wcontainer1 > wplayer_2)
  829. {
  830. while (!wwar_1.empty() && !kwar_1.empty()) {
  831. wplayer_1.push(wwar_1.front());
  832. kplayer_1.push(kwar_1.front());
  833. wwar_1.pop();
  834. kwar_1.pop();
  835. }
  836. while (!wwar_2.empty() && !kwar_2.empty()) {
  837. wplayer_1.push(wwar_2.front());
  838. kplayer_1.push(kwar_2.front());
  839. wwar_2.pop();
  840. kwar_2.pop();
  841. }
  842.  
  843. wplayer_1.push(wcontainer1.front());
  844. wcontainer1.pop();
  845. kplayer_1.push(kcontainer1.front());
  846. kcontainer1.pop();
  847. wplayer_1.push(wplayer_2.front());
  848. wplayer_2.pop();
  849. kplayer_1.push(kplayer_2.front());
  850. kplayer_2.pop();
  851. pl++;
  852. }
  853. else if (wcontainer1 < wplayer_2)
  854. {
  855. while (!wwar_1.empty() && !kwar_1.empty()) {
  856. wplayer_2.push(wwar_1.front());
  857. kplayer_2.push(kwar_1.front());
  858. wwar_1.pop();
  859. kwar_1.pop();
  860. }
  861. while (!wwar_2.empty() && !kwar_2.empty()) {
  862. wplayer_2.push(wwar_2.front());
  863. kplayer_2.push(kwar_2.front());
  864. wwar_2.pop();
  865. kwar_2.pop();
  866. }
  867.  
  868. wplayer_2.push(wcontainer1.front());
  869. wcontainer1.pop();
  870. kplayer_2.push(kcontainer1.front());
  871. kcontainer1.pop();
  872. wplayer_2.push(wplayer_2.front());
  873. wplayer_2.pop();
  874. kplayer_2.push(kplayer_2.front());
  875. kplayer_2.pop();
  876. if (wplayer_1.empty()) {
  877. cout << "Player 2 won";
  878. break;
  879. }
  880. pl++;
  881. }
  882. else if (wplayer_2 == wcontainer1)
  883. {
  884. cout << " !!!!!!WAR!!!!!!" << endl;
  885. if (wplayer_1.size() < 1) {
  886. cout << " Player 2 won";
  887. break;
  888. }
  889. else if (wplayer_2.size() < 1) {
  890. cout << "Player 1 won";
  891. break;
  892. }
  893. else {
  894. wwar_1.push(wcontainer1.front());
  895. kwar_1.push(kcontainer1.front());
  896. wcontainer1.pop();
  897. kcontainer1.pop();
  898. wwar_2.push(wplayer_2.front());
  899. kwar_2.push(kplayer_2.front());
  900. wplayer_2.pop();
  901. kplayer_2.pop();
  902.  
  903. }
  904. if (wplayer_1.empty())
  905. break;
  906. else if (wplayer_2.empty())
  907. break;
  908. else {
  909. wwar_2.push(wplayer_2.front());
  910. kwar_2.push(kplayer_2.front());
  911. wplayer_2.pop();
  912. kplayer_2.pop();
  913. wwar_1.push(wplayer_1.front());
  914. kwar_1.push(kplayer_1.front());
  915. wplayer_1.pop();
  916. kplayer_1.pop();
  917. }
  918. pl++;
  919. cleverwar();
  920. return;
  921. }
  922. }
  923. }
  924. }
  925. }
  926. }
  927.  
  928.  
  929. int main()
  930. {
  931.  
  932.  
  933. srand(time(0));
  934. cout << "Pick size of a deck (must be divisible by 4): ";
  935. cin >> decksize;
  936. fsize = (decksize / 4);
  937. add = (52 - decksize) / 4;
  938. zlozTalie(talia, *figura, *kolor);
  939. tasuj(talia);
  940. rozdaj(talia);
  941. cleverwar();
  942.  
  943.  
  944.  
  945. return 0;
  946. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement