Question

In: Computer Science

You must program the game called MaDi which is described below. There is a board of...

You must program the game called MaDi which is described below. There is a board of NxN (the size N is defined by the user and must be a number greater than or equal to 2), where in each box there is an instruction. The first (the [0] [0]) and the last box (the [N-1] [N-1]) have no instruction. Possible instructions are:
1. Don't move
2. Advance 4 places
3. Jump to the next row
4. Go back 2 places
5. It exploded! End of the game.
In order to facilitate the visualization of the matrix for the player, the instruction number will be displayed on the board and below it the list of instructions with their numbering.
Instructions:
1. Don't move
2. Advance 4 places
3. Jump to the next row
4. Go back 2 places
5. Bomb! Exploded.
The instruction that goes in each square of the board will be assigned randomly each time the game starts.
The player starts with his chip in the first position (row: 0, column: 0) and (bottom-right corner). On each turn the player rolls a die that will tell him how many spaces to advance. You advance across the board from left to right and from top to bottom as follows:
On each turn the player rolls a dice that tells him how many positions on the board to advance. After advancing, he must execute what is indicated in the instruction of the box where he fell. For each turn, only execute one instruction on the board. The player has a maximum number of rolls of the dice, which will be asked to the player when starting the game.
The game is lost if the dice are thrown without having reached the goal or if the product of rolling the dice advances to a square with a bomb. The game is won if you reach the goal (it does not have to be by exact count) before the roll of the dice runs out.

Solutions

Expert Solution

import numpy as np

import random

def roll_die():

return randint(1, 7)

n = int(input('Input the size of the board(greater than 2): ')

while n < 2:

  print('The number should be above 2: \n Try again')

n = int(input('Input the size of the board(greater than 2): ')

max_rolls = int(input('Enter the maximum number of rolls: ')

total_steps = n * n

bomb_exploded = False

while max_rolls != 0 and not bomb_exploded:

die_number = roll_die()

if die_number == 1:

    continue

elif die_number == 2:

    total_steps -= 4

elif die_number == 3:

    total_steps -= n

elif die_number == 4:

    total_steps += 2

else:

    bomb_exploded = True

max_rolls -= 1

if total_steps <= 0:

max_rolls = 0

if max_rolls >= 0 or not bomb_exploded:

print('The player has won!!!')

else:

print('Sorry mate! The bomb exploded or you've run out of turns! Try again next time!')


Related Solutions

Suppose you have declared a character array called board of size 9 for a game by...
Suppose you have declared a character array called board of size 9 for a game by the declaration char board[9] and you want to initialize it with a loop so that each array member has a space character each at the beginning of the game. Which one of the following loops is the correct initialization?
Fly By Night Games Company has decided to hire you to program their new board game...
Fly By Night Games Company has decided to hire you to program their new board game simulator for the game “Chutes & Ladders”. The board has squares which are numbered from 1 to 100 and players have counters which start on the theorectical square 0. The players take turns at spinning a spinner with the numbers 1 to 6 on it, and each moves his or her counter forward the number of squares corresponding to the number on the spinner....
The coding for this program to run as described on Python: Your (turtle) program must include:...
The coding for this program to run as described on Python: Your (turtle) program must include: include import turtle on a line after the comments so you can use the various Turtle-related objects and methods. Create a turtle named after your favorite ice cream flavor. Make sure the name has no punctuation and consists only of letters, numbers and the underscore character. Write your python program so your turtle is constantly moving and can be turned left and right using...
This exercise requires designing a program which solves the problem described in the problem statement below....
This exercise requires designing a program which solves the problem described in the problem statement below. Provide comments in your pseudo-code and Java program as necessary. Your solution must include these components: UML Class diagram Flowchart Pseudo-code Program Coded Program Output Problem Statement Design a class named Pet, which should have the following fields: name: The name field holds the name of a pet. type: The type field hold the type of animal that a pet is (for example, “dog”,...
Using JavaScript You must submit a file, called indentation.js indentation.js: program to indent The following program...
Using JavaScript You must submit a file, called indentation.js indentation.js: program to indent The following program is difficult to follow because of its indentation: print ( "binary"); var n = Math.pow (2, 31) - 1; var bits = 0; while (n> 0) { bits + = n & 1; n >> = 1; } print ("Number of bits at 1:" + bits); for (var i = 1; i <= bits; i ++) { var str = ""; if (i% 3...
Develop a Java application that plays a "guess the number" game as described below. a) The...
Develop a Java application that plays a "guess the number" game as described below. a) The user interface is displayed and the user clicks the “Start Game” button to begin the game. b) Your application then gets a random number in the range 1-1000 inclusive (you might want to use Math.random or the Random class). c) The application then displays the following prompt (probably via a JLabel): I have a number between 1 and 1000 can you guess my number?...
IN C++ Write a program to play the Card Guessing Game. Your program must give the...
IN C++ Write a program to play the Card Guessing Game. Your program must give the user the following choices: - Guess only the face value of the card. -Guess only the suit of the card. -Guess both the face value and suit of the card. Before the start of the game, create a deck of cards. Before each guess, use the function random_shuffle to randomly shuffle the deck.
Write a class encapsulating a board game. A board game has the following additional attributes: the...
Write a class encapsulating a board game. A board game has the following additional attributes: the number of players and whether the game can end in a tie. Code the constructor and the toString method of the new class. You also need to include a client class(with the main method) to test your code. code in Python
You've just unboxed a new board game by legendary creator Stefan Feld. In the game, you...
You've just unboxed a new board game by legendary creator Stefan Feld. In the game, you roll a seven-sided, fair die with 4 red faces, 2 green faces, and 1 blue face. Your roll dictates how much gold you receive for rolling: red gives 1 gold, green gives 2 gold, and blue gives 4 gold. a. Define a random variable for this setting, state the support, and find its probability model. b. Find the expected value and variance of your...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT