Survivor Program

Hello everyone. I am currently working on a program for school where I have to stimulate a survivor game. In the game, there is a "creature" that is randomly generated on a 6x6 island grid. The game requires no user input, so the creature will just randomly "hop" around the island until it reaches a randomly generated bridge, at which point it escapes and ends the game, hops into the water on the sides of the island, or reaches turn 20, which means that the "creature" dies due to it having starved. So far I have generated an array, where w represents water on the edge of the island. . So far I have this code written:

My plan to simulate the creature hopping is to use a random number generator that randomly chooses a number between 0-8. Each number corresponds to the creature moving 1 space diagonally, vertically or to the sides. For example, 0 would correspond to the creature moving up to the left 1 would correspond to the creature moving up one space vertically etc. This would just correspond to a column and/or row change of 1. I wish to know how I can accomplish this. And I also wish to know how I can randomly generate a creature on the island.

My plan to simulate the creature hopping is to use a random number generator that randomly chooses a number between 0-8. Each number corresponds to the creature moving 1 space diagonally, vertically or to the sides. For example, 0 would correspond to the creature moving up to the left 1 would correspond to the creature moving up one space vertically etc. I wish to know how I can accomplish this.

Your sample code already generates random numbers, but I guess what you actually want is a number in the range 0...7 inclusive if you number them the way you propose. So I would change your code to rand() % 8.

Originally Posted by Ayu12

And I also wish to know how I can randomly generate a creature on the island.

Can the creature only appear on land? If there are N land spots on your map, then generate a number 1...N and place the creature in the land spot indicated by that number. 1 is the first land spot, and so on.