Question
I will give an upvote if someone can give me any kind of help with this project. I need help with Initializing the creature world
I will give an upvote if someone can give me any kind of help with this project.
I need help with Initializing the creature world with 5 randomly chosen creature objects.(either rock, paper or scissors). then when the user presses enter the creatures should move in the direction specified below.
Starting code:
import java.util.*; public class Prog3 { public static final int ROWS = 5; public static final int COLS = 5; // you will probably need to have many more final values // do not have any non-final data here
public static void main(String args[]) { System.out.println("!! Welcome to Program 3 !!");
Creature[][] world; Creature[] creatures;
//intialize the Creature[][] world with null world = new Creature[ROWS][COLS]; for (int r = 0; r
// simulates the dynamical system. MAIN GAME LOOP while(true){ pressEnter = in.nextLine(); if(pressEnter.equals("exit")) break; } System.out.println("Done. Normal termination."); }
private static int[] getEmptyRowCol(Creature[][] inWorld) { // Assume inWorld has at least one row and one column Random Random rand = new Random(); int rrow = rand.nextInt(inWorld.length), rcol = rand.nextInt(inWorld[0].length); while (inWorld[rrow][rcol] != null) { rrow = rand.nextInt(inWorld.length); rcol = rand.nextInt(inWorld[0].length); } return new int[]{rrow, rcol}; }
private static void printWorld(Creature[][] inWorld) { System.out.print("+"); for (int i = 0; i
public abstract class Creature { /ot sure if these variables should be here public final static int NORTH = 0; public final static int SOUTH = 1; public final static int WEST = 2; public final static int EAST = 3; public final static int NUM_DIRECTIONS = 4; protected final String name; protected final int startRow, startCol; //I am not sure what all should be in this constructor public Creature(String inName, int inStartRow, int inStartCol){ name = inName; startRow = inStartRow; startCol = inStartCol; } public abstract void move(Creature[][] inWorld); //toString method //kill method }
import java.util.*;
public class Rock extends Creature {
public Rock(String name, int inStartRow, int inStartCol){ super(name, inStartRow, inStartCol); }
// there might be some errors but this is the general format of how move should be implemented. public void move(Creature[][] inWorld) { int row = startRow,col = startCol;
int prevRow = row, prevCol = col; int rint = new java.util.Random().nextInt(NUM_DIRECTIONS); if (rint == NORTH && row > 0 && !(inWorld[row - 1][col] instanceof Rock)) row--; else if (rint == SOUTH && row 0 && !(inWorld[row][col - 1] instanceof Rock)) col--; else if (rint == EAST && col
if (prevRow != row || prevCol != col) { System.out.println("Rock moved from " + "(" + prevRow + "," + prevCol + ") " + "to " + "(" + row + "," + col + ")."); if (inWorld[row][col] == null) { // ?? } else { Creature other = inWorld[row][col]; if (other instanceof Scissors) { // ?? System.out.println("Rock killed Scissors at " + "(" + row + "," + col + ")."); } else if (other instanceof Paper) { // ?? System.out.println("Rock killed by Paper at " + "(" + row + "," + col + ")."); } } inWorld[prevRow][prevCol] = null; } else System.out.println("Rock at " + "(" + row + "," + col + ") " + "could not move."); } // toString? }
public class Scissors extends Creature { public Scissors(String name, int inStartRow, int inStartCol) { super(name, inStartRow, inStartCol); }
public void move(Creature[][] inWorld) { } }
public class Paper extends Creature { public Paper(String name, int inStartRow, int inStartCol) { super(name, inStartRow, inStartCol); }
public void move(Creature[][] inWorld) { } }
final output:
Introduction: FROM WIKIPEDIA: In mathematics, a dynamical system is a system in which a function describes the time dependence of a point in a geometrical space. Ex amples include the mathematical models that describe the swinging of a cl the flow of water in a pipe, and the number of fish each springtime in a lake. The study of dynamical systems is the focus of dynamical systems theory, which has applications to a wide variety of fields such as mathematics, physics, biology, chemistry, engineering, eco- nomics, and medicine. Dynamical systems are a fundamental part of chaos thcory, logistic map dynamics, bifurcation theory, the self-assembly process, and the edge of chaos concept ock pendulum In this program, with polymorphism and inheritance in mind, you will create a simulation of a simple 2D dynamical system. In this simulation, there will be three types of Creatures Rocks, Papers and Scissors. These creatures live in a world composed of a 5-by-5 grid of cells. Only one creature may occupy a cell at a time. The grid is enclosed, so a creature is not allowed to move off the edges of the grid. If a cell is unoccupied, then it shall store the value null. Time is simulated in discrete (integer) time steps. Each creature performs some action every time step. The behavior of each type of creature is discussed below Introduction: FROM WIKIPEDIA: In mathematics, a dynamical system is a system in which a function describes the time dependence of a point in a geometrical space. Ex amples include the mathematical models that describe the swinging of a cl the flow of water in a pipe, and the number of fish each springtime in a lake. The study of dynamical systems is the focus of dynamical systems theory, which has applications to a wide variety of fields such as mathematics, physics, biology, chemistry, engineering, eco- nomics, and medicine. Dynamical systems are a fundamental part of chaos thcory, logistic map dynamics, bifurcation theory, the self-assembly process, and the edge of chaos concept ock pendulum In this program, with polymorphism and inheritance in mind, you will create a simulation of a simple 2D dynamical system. In this simulation, there will be three types of Creatures Rocks, Papers and Scissors. These creatures live in a world composed of a 5-by-5 grid of cells. Only one creature may occupy a cell at a time. The grid is enclosed, so a creature is not allowed to move off the edges of the grid. If a cell is unoccupied, then it shall store the value null. Time is simulated in discrete (integer) time steps. Each creature performs some action every time step. The behavior of each type of creature is discussed belowStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started