Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <stdlib.h>
- using namespace std;
- int losowanie (int piles[], int pilesAmount);
- void wyswietl(int piles[], int pilesAmount);
- bool isEmpty(int piles[], int pilesAmount);
- int main(int argc, char** argv) {
- srand(time(NULL));
- int pilesAmount = rand() % 6 + 3;
- int piles[pilesAmount];
- losowanie(piles, pilesAmount);
- int player = 1;
- while(true)
- {
- wyswietl(piles, pilesAmount);
- cout << "PLAYER'S " << player << " TURN." << endl;
- int pile, pawnAmount;
- cin >> pile;
- cin >> pawnAmount;
- if(pawnAmount > piles[pile - 1] || pawnAmount <= 0)
- {
- cout << "Invalid value of pawns." << endl << endl;
- }
- if(pile > pilesAmount || pile <= 0)
- {
- cout << "Invalid value of piles." << endl << endl;
- continue;
- }
- if(pawnAmount > piles[pile - 1] || pawnAmount <= 0)
- continue;
- piles[pile - 1] -= pawnAmount;
- switch(player)
- {
- case 1:
- player = 2;
- break;
- case 2:
- player = 1;
- break;
- }
- if(isEmpty(piles, pilesAmount))
- break;
- }
- cout << endl << endl << "####################################### " << "PLAYER " << player << " WINS!" << " #######################################";
- return 0;
- }
- int losowanie (int piles[], int pilesAmount)
- {
- for(int i = 0; i < pilesAmount; i++)
- {
- int pawns;
- bool shuffle = true;
- while(shuffle){
- shuffle = false;
- pawns = rand() % 26 + 4;
- for(int j = 0; j < i; j++)
- {
- if(pawns == piles[j])
- {
- shuffle = true;
- break;
- }
- }
- }
- piles[i] = pawns;
- }
- }
- void wyswietl(int piles[], int pilesAmount)
- {
- for(int i = 1; i <= pilesAmount; i++)
- {
- cout << i << " : " << piles[i - 1] << endl;
- }
- cout << endl;
- }
- bool isEmpty(int piles[], int pilesAmount)
- {
- for(int i = 0; i < pilesAmount; i++)
- if(piles[i] != 0)
- return false;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement