Jump to content

Desperate for help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
seraphican

seraphican

    Newbie

  • Members
  • Pip
  • 4 posts
Im a year 1 student studing php programming.Recently i have been assigned an assignment and i really have huge trouble with the last question. Urgent need for help, please help me if you can!I have no idea how to even do this at all >.<

Question:
Write a program to simulate one computer player playing a simplified game of Minesweeper. The objective of the game is to find the hidden mines without detonating them. The computer player wins when it is able to identify the location of the mine without exploding them.

Assume there is no user input for this game. The computer player has a 4 x 4 2D array, which represents the land that may contain hidden mines. The program must randomly generate and hide a specific number of mines within the 4x4 2D land grid. Then, the program should simulate the game play as below:
• At each turn, the game board should be displayed
• At each turn, the computer player randomly selects a position on the land grid. Each position consists of a random x and y value (e.g. [2][2]).
• If the selected random position has no mine, a number is displayed. The number displayed can be as follows:
o 0  there are no mines in the right and left neighbours only
o 1  there is one mine in the right or left neighbour only
o 2  there are two mines in the right and left neighbours only
Then, the game awards 10 points to the player’s score.

• If the selected random position has a mine, then the program displays an appropriate message and the player loses 20 points from his current score.
• The program musn’t allow a selected random position to be re-selected again.
• At the end of the turn the updated 4x4 2D land grid should be displayed.
• Each position (or slot) in the displayed 4x4 2D land grid can contain any of the following:
o -1  not selected yet
o number  selected and indicates the number of mines in the left & right neighbours only
o 99  mine found and exploded
• The game ends when one of the following conditions is met:
o The computer player selects all the positions except those having mines. If this condition is met the program should print the computer player as winner.
o The computer player’s score drops below 0. If this condition is satisfied the program should print the computer player as loser.

Your program must, at least, include the following methods/functions with the correct input parameters and output type:

i. initializeLandGrid, which will take in the player’s 2D array as input
and assign blank slots containing -1 (-1 represents unselected slot).

ii. assignMines, which will assign the land mines to randomly selected hidden locations in a 4x4 2D array. You may assume a total of 8 mines will be hidden.

Marks will be awarded for making your program modular further. You must carefully choose the methods.

Partial output of running game:

Turn 1
Land Grid
-1 -1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1
Position [1,1] selected
No mine found!
Score = 10
Turn 2
Land Grid
-1 -1 -1 -1
-1 1 -1 -1
-1 -1 -1 -1
-1 -1 -1 -1
Position [3,3] selected
Mind found!!! Too bad!
Score = 0
Turn 3
Land Grid
-1 -1 -1 -1
-1 1 -1 -1
-1 -1 -1 -1
-1 -1 -1 99


#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
well, you need two two-dimensional arrays, one to print, and one to keep track of mines, initiate everything to -1 in the print array, and to 0 in the mine array then randomize the mines into the mine array, by turning some to 1

that's a starter!
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
First try writing the code you can using Orjan's advice, then we can help you with the more specifics. You should know enough by now to do most of it.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.