Question

In: Statistics and Probability

IN PSEUDOCODE PLEASE! Hush, Hush Kleine Hexe (or in English “on your broom”) is a Ravensburger...

IN PSEUDOCODE PLEASE!

Hush, Hush Kleine Hexe (or in English “on your broom”) is a Ravensburger memory board game for kids. Here are the basic rules we will apply. The number of players will be between 2 and 4. It won’t change for the entire game. There are 5 colors (red, orange, yellow, blue, green) token. There are 5 indistinguishable black witch hats. There is one dice which has a color on each face and then a shuffle. There are 5 rows. At the beginning, all the tokens are at the bottom row. Any token crossing the 5th signals the end of the game (and a win). Any player can move any token. For each player, a turn is composed of three steps: Rolling the die If the die falls on a color, then the current player guesses which of the hats has the witch of the correct color under it. If the guess is correct, the player does another round. Otherwise, this ends their turn If the die falls on shuffle, the player can exchange the positions of the 5 die/token combinations. This ends their turn. For your final project you will design this board game. The interface will be a simple grid like this where the leftmost column and the bottom row are the cell labels for this 6x6 grid. The letters are used as players' pieces, Blue, Red, Orange, bellow, and Green. Your program will ask how many players are playing, then it will shuffle the token/hat pairs. For each round, each player will have a turn. For each turn, The program will print the covered board The player will play until their have either finished a shuffle or they have guessed the color wrong. The program will roll the die using a random function. The player will either guess or shuffle depending on the roll A shuffle can have up to 5 switches. If the die rolls on a color, the program will state which color rolled. Then it will ask the player for their guess, print the board with the token uncovered, and state whether the guess was correct or not. If the guess was correct, the token/hat is advanced up one row. If the guess was incorrect, the turn of that particular player is over. Your program will be able to notice a win, will stop immediately and announce the win. All inputs will be validated. You will use the best practices we have learned in class. Any infinite loops, breaks, continue, gotos will be dealt with harshly. You will use one or more arrays, one or more loops, one or more random generator functions, You will have at least 3 functions which will have parameters (at least one), return values (at least one), and will modify the array (at least one). A function which only displays a message will not count. Your program will be able to handle 2 to 4 players seamlessly. You may use classes and objects, but it is not an obligation.

Solutions

Expert Solution

import java.io.*;
import java.util.Random;

public class Hushgame {

public static void main(String[] args) {
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
Random rand = new Random();

final int MAX_ROWS = 5;
final int MAX_COLS = 5;

int[][] myArray = new int[MAX_ROWS][MAX_COLS];
Boolean[][] isCovered= new Boolean[MAX_ROWS][MAX_COLS];

//input number of players
boolean flag=true;
int numPlayer=0;
numPlayer=intInputer(2, 4, "please enter the number of players(2,3 or 4)");

//initialize board
FillMyArray(myArray,isCovered);
PrintArray(myArray,isCovered);
int maxRound=1000;
int currentRound=0;
int dice;
boolean isWinner=false;
while(!isWinner){
//no winner, continue playing
currentRound=currentRound+1;
int playerID;
for(playerID=1;playerID<numPlayer+1;playerID++){
if(!isWinner){
System.out.println("player "+playerID+"'s turn");
}
boolean roll=true;
while(roll & (!isWinner)){
System.out.println("type anything or nothing and press enter to roll");
String letsroll;
try{
letsroll=reader.readLine();
}catch (IOException e){
System.out.println("Error reading");
}
dice=rand.nextInt(6);
//dice=1;
System.out.println("the outcome of the dice is: " + dice);
//shuffle
if(dice==0){
int numShuffle=0;
System.out.println("you diced shuffle");
numShuffle=intInputer(1, 5, "please enter the number of shuffles(1-5) you want");
for(int j=1;j<numShuffle+1;j++){
System.out.println("round of shuffler: "+ j + " out of " +numShuffle+" shuffle(s)");
int firstCol=0, secondCol=0;
firstCol=intInputer(1, 5, "input first column of the shuffler(1-5)")-1;
secondCol=firstCol;
while(secondCol==firstCol)
{
secondCol=intInputer(1, 5, "input second column of the shuffler(1-5)")-1;
if(secondCol==firstCol){
System.out.println("invalid value, please enter a colomn different from the first column");
}
}
Shuffler(myArray,firstCol,secondCol);
}
System.out.println("done shuffle, next player");
roll=false;
}else{
int inputCol=0;
inputCol=intInputer(1, 5, "please indicate which column has color "+ GetCharEquivalent(dice)+", please enter 1-5")-1;

//guessed right
if(CheckHat(myArray,GetCharEquivalent(dice),inputCol)){
System.out.println("WOW, your answer is correct. "+ GetCharEquivalent(dice)+" move one block forward and you can roll again.");
//move one block
int myRow;
myRow=FindRow(myArray,inputCol);
// System.out.println("myrow="+ myRow);
myArray[myRow][inputCol]=0;
isCovered[myRow][inputCol]=false;
myArray[myRow-1][inputCol]=dice;
isCovered[myRow-1][inputCol]=true;
PrintArray(myArray,isCovered);
//check if there is a winner
isWinner=IsThereWinner(myArray);
if(isWinner){
System.out.println("Congrats, player "+playerID+" won!!!");
}
}else{
System.out.println("Sorry, "+GetCharEquivalent(dice)+" is not in column "+ (inputCol+1)+".");
String wrongColor;
wrongColor=GetCharEquivalent(myArray[FindRow(myArray,inputCol)][inputCol]);
System.out.println("the color in column "+(inputCol+1)+" is "+ wrongColor +".");
System.out.println("next player");
roll=false;
}
}
}
}
}
}

public static int intInputer(int min, int max, String msg){
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
int output=-1;
while(output<min | output>max){
System.out.println(msg);

try{
output = Integer.parseInt(reader.readLine());
}catch (Throwable t){
System.out.println("Error reading, please enter an interger");
}
}
return output;
}

public static void Shuffler(int[][] myArray, int fcol,int scol){
int frow,srow;
frow=FindRow(myArray, fcol);
srow=FindRow(myArray, scol);
int temp;
temp=myArray[frow][fcol];
myArray[frow][fcol]=myArray[srow][scol];
myArray[srow][scol]=temp;
}
public static int FindRow(int[][] myArray, int col){
int i;
for (i = 0; i<myArray.length ; i++ ) { // array.length = max rows
if(myArray[i][col]>0){
return i;
}
}
return i;
}


public static boolean CheckHat(int[][] myArray, String color, int column){
boolean flag=false;
int i=0;
while(i<myArray[0].length && !flag) {
if(GetCharEquivalent(myArray[i][column]).equals(color)){
flag=true;
}
i++;
}
return flag;
}

public static boolean IsThereWinner(int[][] myArray){
boolean iswinner=false;
int j = 0;
while (j <myArray[0].length && !iswinner) {
if(myArray[0][j] > 0){
iswinner=true;
}
else j++;
}
return iswinner;
}
///initialization of the grid
public static void FillMyArray(int[][] myArray, Boolean[][] isCovered){
int i, j;
for (i = 0; i<myArray.length ; i++ ) { // array.length = max rows
for(j = 0; j <myArray[0].length; j++) { // array[0].length = max cols
myArray[i][j] = 0;
isCovered[i][j]=false;
}
}

myArray[myArray.length-1][0]=1;
isCovered[myArray.length-1][0]=true;
myArray[myArray.length-1][1]=2;
isCovered[myArray.length-1][1]=true;
myArray[myArray.length-1][2]=3;
isCovered[myArray.length-1][2]=true;
myArray[myArray.length-1][3]=4;
isCovered[myArray.length-1][3]=true;
myArray[myArray.length-1][4]=5;
isCovered[myArray.length-1][4]=true;

}


public static void PrintArray(int[][] myArray,Boolean[][] isCovered) {
int i, j;
int[][] myPrintArry;
for (i = 0; i<myArray.length ; i++ ) { // array.length = max rows
System.out.print((i+1)+" ");
for(j = 0; j <myArray[0].length; j++) { // array[0].length = max cols
if(isCovered[i][j]){
System.out.print( GetCharEquivalentCovered(myArray[i][j]) + " ");
} else {
System.out.print( GetCharEquivalent(myArray[i][j]) + " ");
}
}
System.out.println();
}
System.out.print(" ");
for(i=0;i<myArray.length;i++)
{
System.out.print((i+1)+" ");
}
System.out.println();
}

public static String GetCharEquivalent(int a){

if (a==0)
return "*";
else if (a==1)
return "G";
else if (a==2)
return "R";
else if (a==3)
return "B";
else if (a==4)
return "O";
else if (a==5)
return "Y";
else
return " ";

}

public static String GetCharEquivalentCovered(int a){
if(a==0)
return "*";
else
return "X";

}

}


Related Solutions

What does the following pseudocode axiom mean, in English? 1. ( aStack.push( item ) ).pop() =...
What does the following pseudocode axiom mean, in English? 1. ( aStack.push( item ) ).pop() = aStack 2. aList.getLength() = ( aList.insert( i, item ) ).getLength() - 1 3. ( aList.insert( i, item ) ).remove( i ) = aList 4. aList.getEntry( i ) = ( aList.insert( i, item ) ).getEntry( i+1 )
PSEUDOCODE: 1. You are designing software for a voting booth. Please create pseudocode for a modular...
PSEUDOCODE: 1. You are designing software for a voting booth. Please create pseudocode for a modular program that: - Takes in a user inputted integer for age. If their age is below 18, display "you are too young to vote" - Only If their age is high enough, please ask them which candidate they wish to vote for. Valid options are "dog", "cat", "horse" - If they did not choose a valid option display "you did not choose a valid...
(I AM IN A INTRO TO PROGRAMMING, PLEASE USE SIMPLE PSEUDOCODE IF POSSIBLE) Create pseudocode for...
(I AM IN A INTRO TO PROGRAMMING, PLEASE USE SIMPLE PSEUDOCODE IF POSSIBLE) Create pseudocode for a program for Hansel's Housecleaning Service. The program prompts the user for a customer's last name only. While the last name is not “zzz” your program will ask for the number of bathrooms and the number of other rooms to be cleaned and display the cleaning charge. You should use a sentinel-controlled while loop in your main loop logic. A customer name of “zzz”...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your...
How Heapify is done (theory, pseudocode, and examples) the examples used Java code please (in your own words)
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the loop). The program should ignore any negative input and should continue to read user inputs until 0 is entered. The program should display the largest value and...
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a...
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a month, then determine what season it is based on that input. Write a method that takes in a month and day and returns which season it is (“Spring”, “Summer”, “Fall”, “Winter”). Your main method should be the only one that includes a print statement. Note the first days of each season: • March 19th – Spring • June 20st – Summer • September 22nd...
Your business provides CDs on learning English that compliment the teaching that is provided by your...
Your business provides CDs on learning English that compliment the teaching that is provided by your employees based in Mexico. Assume that you decide to capitalize on these CDs by selling them to a large retail store based in Mexico. The CDs are not as effective without the teaching, but can be useful to individuals who want to learn the basics of the English language. You do not want to take the risk of sending a case of CDs to...
Please explain what the Big O Notation is in plain English. Please include the logic behind...
Please explain what the Big O Notation is in plain English. Please include the logic behind it and calculations if necessary. I have trouble understanding it, I will be taking a test soon so I will need an easier way to remember it. I use Python btw.
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem...
This is an Intro to java question. Please provide code and pseudocode for better understanding. Problem 4: Player Move Overworld (10 points) (Game Development) You're the lead programmer for an indie game studio making a retro-style game called Zeldar. You've been tasked to implement the player movement. The game is top-down, with the overworld modeled as a 2d grid. The player's location is tracked by x,y values correlating to its row and column positions within that grid. Given the current...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA...
This is an intro to java question. Please answer with pseudocode and code. Problem 2: RSA Public Key (10 points) (Cyber Security) RSA is an asymmetric encryption scheme, where a public key is used to encrypt data and a different, private key decrypts that data. RSA public/private keys are generated from two prime numbers, typically very large ones. The idea behind RSA is based on the fact that its difficult to factorize very large integers. RSA public key generation is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT