This question is pretty complicated.
Write a program to simulate a simplified board game called Survival. Two clans are stranded on opposite ends of an island in the Pacific Ocean. It has been about one week since they both arrived at the island mysteriously. Through some fortune both clans have discovered a plot of land in the middle of the island overflowing with resources. The land is a 10 x 10 region, where each element has one type of hidden resource.
The hidden resources are (1) food, (2) weapons, (3) medical supplies and (4) clean water. Each clan will send one representative to play this game.
The simplified game of Survival is a two-player game played on a 10 x 10 game board. The objective of the game is for each clan to gather as many resources to determine who will survive the longest on the island. The winner is the player who has the most number of resources, in terms of points. This modified version of Survival will be simulated using two computer players.
No user input is required for this game. The 10x10 board will be simulated using a 10 x 10 2D array. At the start, the game must randomly decide which computer player (1 or 2) will go first.
This game will include the following pieces:
• “food” piece – represents one food resource
• “weapons” piece – represents one weapons resource
• “medical supplies” piece – represents one medical supplies resource • “clean water” piece – represents one clean water resource
For this game the program should randomly hide 15 pieces of each resource across the 10 x 10 grid. Assume only one resource can be placed inside each box of the grid. The game begins by generating a random number between 25 and 100, inclusive which indicates the total number of turns (i.e. player 1 and player 2 combined) to take.
Then, the program should simulate the game play as follows:
• At each turn, the current state of the game board should be displayed and which resources have been taken by a computer player (player 1 or
2);
• At each turn the program must also generate two random numbers, each between 1 and 10, inclusive that represent the x and y position in the 2D array.
• The rules for placing an item on the game board are as follows:
o If the two random numbers total up to 0, 10 or 18, then the player has the choice to denote the area around that [x][y]. The choice depends on another random number between 1 and 2, inclusive. If the random number is 1, then the detonation will happen. Otherwise, no detonation occurs, the resource can be assigned to the player’s inventory and the game board is updated.
The area around the [x][y] for detonation is the immediate 8 neighbours of the [x][y] position. Denotation means that all resources in those 8 immediate neighbours will be destroyed such that no computer player can acquire them now or in the future.
o For any other dice value, the program should check the [x][y] position. If there is a resource available there it should be assigned to the computer player’s inventory and the game board is updated.
• If the [x][y] position on the game board has no resource, the computer player skips its turn.
Overall, each position (or slot) in the displayed 10x10 2D game board can contain any of the following:
• E empty space
• F food resource
• W weapons resource
• M medical supplies resource
• C clean water resource
Every time a resource is assigned to the inventory of one of the computer player’s points are assigned as follows:
Resource Points
Food 45
Weapons 25
Medical Supplies 25
Clean Water 50
The game ends when the following condition is satisfied:
• When there are no more remaining resources to find on the game board. At this point, your program should go through the game board identify the winner.
How to win ( in order of priority)
One player has 25% more clean water resources than the other player
One player has 35% more medical supplies resources than the other player
The player with most number of points
• The program should print a “Tie” if both computer players end up with the same number of points based on their inventory.
Your program must, at least, include the following methods/functions with the correct input parameters and output type:
i. initializeGameBoard, which will take as input the player’s 2D array and assign empty slots containing E;
ii. getResource, which will take as input the 2D array and updates the game board based on the indicated rules;
iii. computeResourcePoints, which will take a resource and return the points awarded to it;
iv. computeWinner, which will take as input the 2D array and display the winner.
Your program also needs to track and print the following:
• The total number of resources belonging to each computer player
• The total number of hidden resources destroyed through detonation
• The total number of hidden resources by type (e.g. food, weapons, etc.) destroyed through detonation
I did a list showing the steps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
Start- Create 10 x 10 board
- Generate 15 random [x,y]
- Insert food
- Generate 15 random [x,y]
- Insert 15 random [x,y]
- Insert weapons
- Generate 15 random [x,y]
- Insert medical supplies
- Generate 15 random [x,y]
- Insert water
- Generate P|15 =< P >= 100
- Generate random 1/2
- If else statement for player turn
- Generate 15 random [x,y]
- Send player to square
- Generate random 1/2
- If statement( if is 1), detonate 3x3 area.
- To board status
- Player scores
- If statement for (is no of turns >p?)
- Yes - Player Won
- No - start value +1
- if statement for if there is item
- Yes - Collect
- No - To board Status
- Player scores
- If statement for (is no of turns >p?)
- Yes - Player Won
- No - Start value +1
- Stop
|
This are the code I did so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <iostream>
using namespace std;
int main()
{
int array[10][10];
int food = 15;
int weapon = 15;
int medicalsupplies = 15;
int water = 15;
for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++)
array[x][y] = rand() % 900 + 100;
}
for (int i = 0; i < 10; ++i)
{
for (int j = 0; j < 10; ++j)
{
cout << array[i][j];
}
cout << '\n';
}
cout << endl;
for (int y = 0; y < 10; y++) {
for (int x = 0; x < 10; x++)
food = (rand() % food) + 1;
}
for (int y = 0; y < 10; y++) {
for (int x = 0; x < 10; x++)
weapon = (rand() % weapon) + 1;
}
return 0;
}
|
I think I did something wrong somewhere where I'm supposed to hide 15 of each resources across the board but I couldn't figure out the problem.