Simple World作业代做、代写Java/Python编程设计作业、C++语言作业代做
east, south, or west) and belongs to a particular species, which determines how that creaturebehaves.la hoflfl ho Figure 1. A 4-by-4 grid, which contains five creatures. Two creatures belong to the speciesflytrap (whose short name is “fl”), two belong to the species hop (whose short name is “ho”), andone belongs to the species landmine (whose short name is “la”). The direction of each creatureis represented by the direction of the arrow.Figure 1 shows a 4-by-4 grid populated by five creatures. Two of them belong to the speciesflytrap (whose short name is “fl”), two belong to the species hop (whose short name is “ho”), andone belongs to the species landmine (whose short name is “la”). The direction of each creature is represented by the direction of the arrow. For example, the flytrap at the top row is facing eastand the flytrap at the bottom row is facing west.Table 1. The list of instructions and their explanations.hopThe creature moves forward as long as the square it is facing is empty. Ifmoving forward would put the creature outside the boundaries of the grid orwould cause it to land on top of another creature, the hop instruction doesnothing.left The creature turns left 90 degrees to face in a new direction.right The creature turns right 90 degrees to face in a new direction.infectIf the square immediately in front of this creature is occupied by a creature ofa different species (an “enemy”), that enemy creature is infected to becomethe same as the infecting species. When a creature is infected, it keeps itsposition and orientation, but changes its internal species indicator and beginsexecuting the same program as the infecting creature, starting at step 1. If thesquare immediately in front of this creature is empty, outside the grid, oroccupied by a creature of the same species, the infect instruction doesnothing.ifempty nIf the square in front of the creature is inside the grid boundary andunoccupied, jump to step n of the program; otherwise, go on with the nextinstruction in sequence.ifwall nIf the creature is facing the border of the grid (which we imagine asconsisting of a huge wall) jump to step n of the program; otherwise, go onwith the next instruction in sequence.ifsame nIf the square the creature is facing is occupied by a creature of the samespecies, jump to step n; otherwise, go on with the next instruction.ifenemy nIf the square the creature is facing is occupied by a creature of an enemyspecies, jump to step n; otherwise, go on with the next instruction.go n This instruction always jumps to step n, independent of any condition.Each species has an associated program which controls how each creature of that speciesbehaves. Programs are composed of a sequence of instructions. The instructions that can bepart of a program are listed in Table 1. There are nine legal instructions in total. The last fiveinstructions have an additional integer argument.Program is an attribute associated with species. Creatures of the same species have the sameprogram. However, different species have different programs.For example, the program of the species flytrap is composed of the following five instructions:ifenemy 4leftgo 1infectgo 1The meaning of each instruction for this example is commented below:(step 1) ifenemy 4 # If there is an enemy ahead, go to step 4(step 2) left # Turn left(step 3) go 1 # Go to step 1(step 4) infect # Infect the adjacent creature(step 5) go 1 # Go to step 1We will simulate the behaviors of all the creatures for a user specified number of rounds. In eachround, creatures take their turns one by one, starting from the first creature. After the firstcreature finishes its turn, the second creature begins its turn. So on and so forth. One round endswith the last creature finishing its turn. Then the next round begins with the first creature takingits turn. Note that during the simulation, a creature may infect another creature so that theinfected one changes its species. However, the simulation order of the infected creature does notchange.Each creature also maintains a variable called program counter which stores the index of theinstruction it is going to execute. On each turn of a creature, it executes a number of instructionsof its program, starting from the step indicated by the program counter. A program ordinarilycontinues with each new instruction in sequence, although this order can be changed by certaininstructions in the program such as the if*** instructions. In each turn, a creature can executeany number of if*** or go instructions without relinquishing this turn. Its turn ends only whenthe creature executes one of the instructions: hop, left, right, or infect. After its turn ends, thecreature updates the program counter to point to the next instruction, which will be executed atthe beginning of its next turn.Note that each creature maintains its own program counter, so that two different creaturesbelonging to the same species can have different program counters. The indices of the instructions start from one, i.e., the first instruction of each program is “step 1”. At the verybeginning of the simulation process, the program counters of all the creatures are set to their firstinstructions.III. Available TypesIn completing this project, you will have the following types available to you. They are definedin the file world_type.h.const unsigned int MAXSPECIES = 10; // Max number of species in the // worldconst unsigned int MAXPROGRAM = 40; // Max size of a species programconst unsigned int MAXCREATURES = 50; // Max number of creatures in // the worldconst unsigned int MAXHEIGHT = 20; // Max height of the gridconst unsigned int MAXWIDTH = 20; // Max width of the gridstruct point_t{ int r; int c;};/*// Type: point_t// ------------// This type is used to represent a point in the grid.// Its component r corresponds to the row number; its component// c corresponds to the column number.*/enum direction_t { EAST, SOUTH, WEST, NORTH };/*// Type: direction_t// ----------------// This type is used to represent direction, which can take on// one of the four values: East, South, West, and North.*/const string directName[] = {"east", "south", "west", "north"};// An array of strings representing the direction name.const string directShortName[] = {"e", "s", "w", "n"};// An array of strings representing the short names for directions.enum opcode_t {HOP, LEFT, RIGHT, INFECT, IFEMPTY, IFENEMY, IFSAME, IFWALL, GO};/*// Type: opcode_t// -------------// The type opcode_t is an enumeration of all of the legal// command names.*/const string opName[] = {"hop", "left", "right", "infect", "ifempty", "ifenemy", "ifsame", "ifwall", "go"};// An array of strings representing the command name.struct instruction_t{ opcode_t op; unsigned int address;};/*// Type: instruction_t// ------------------// The type instruction_t is used to represent an instruction// and consists of a pair of an operation code and an integer.// For some operation code, the integer stores the address of// the instruction it jumps to. The address is optional.*/struct species_t{ string name; unsigned int programSize; instruction_t program[MAXPROGRAM];};/*// Type: species_t// ------------------// The type species_t is used to represent a species// and consists of a string, an unsigned int, and an array// of instruction_t. The string gives the name of the// species. The unsigned int gives the number of instructions// in the program of the species. The array stores all the// instructions in the program according to their sequence.*/struct creature_t{ point_t location; direction_t direction; species_t *species; unsigned int programID;};/*// Type: creature_t// ------------------// The type creature_t is used to represent a creature.// It consists of a point_t, a direction_t, a pointer to// species_t and an unsigned int. The point_t gives the location of// the species. The direction_t gives the direction of the species.// The pointer to species_t points to the species the creature belongs// to. The programID gives the index of the instruction to be// executed in the instruction_t array of the species.*/struct grid_t{ unsigned int height; unsigned int width; creature_t *squares[MAXHEIGHT][MAXWIDTH];};/*// Type: grid_t// ------------------// The type grid_t consists of the height and the width of the grid// and a two-dimensional array of pointers to creature_t. If there is// a creature at the point (r, c) in the grid, then squares[r][c]// stores a pointer to that creature. If point (r, c) is not occupied// by any creature, then squares[r][c] is a NULL pointer.*/struct world_t{ unsigned int numSpecies; species_t species[MAXSPECIES]; unsigned int numCreatures; creature_t creatures[MAXCREATURES]; grid_t grid;};/*// Type: world_t// --------------// This type consists of two unsigned ints, an array of species_t,// an array of creature_t, and a grid_t object. The first unsigned// int numSpecies specifies the number of species in the creature// world. The second unsigned int numCreatures specifies the number// of creatures in the world. All the species are stored in the array// species and all the creatures are stored in the array creatures.// The grid is given in the object grid.*/IV. File InputAll the species, the programs for all the species, and the initial layout of the creature world arestored in files and these files will be read by your program to set up the simulation environment.Note: when you read files, you must use input file stream ifstream. Otherwise, since thefiles are read-only on our online judge, you may fail to read the files.As we described before, each species has an associated program. The program for each species isstored in a separate file whose name is just the name of that species. For example, the programfor the species flytrap is stored in a file called flytrap.A file describing a program contains all the instructions of that program in order. Each line listsjust one instruction. The first line lists the first instruction; the second line lists the secondinstruction; so on and so forth. Each instruction is one of the nine legal instructions described inTable 1. The program ends with the end of file or a blank line. Comments may appear after theblank line or at the end of each instruction line. For example, the program file for the flytrapspecies looks like:ifenemy 4 If there is an enemy, go to step 4.left If no enemy, turn left.go 1infectgo 1The flytrap sits in one place and spins.It infects anything which comes in front.Flytraps do well when they clump.Note that in writing functions for reading these program files, you should handle the commentscorrectly, which means that you should ignore these comments when setting up the program for aspecies.Since there are many species, we stored all of their program files in a directory.To help you get all the species and their program files, we also have a file telling the directorywhere the program files are stored and listing all the species. We call this file a species summary.The first line of this file shows the directory where all of the program files are stored. The next lines list all the species, with one species per line. For example, the following is a speciessummary file:creaturesflytraphoplandmineFrom this file, we can learn that the program files are stored in the directory called creatures.We have three species to simulate, which are flytrap, hop, and landmine. By first reading thespecies summary file, you will know where to find the program file for each species.Finally, there is a file describing the initial state of the creature world. We call it a world file. Thefirst line of this file gives the height of the two-dimensional grid (i.e., the number of rows) andthe second line gives the width of the grid (i.e., the number of columns). The remaining lines ofthis file describe all the creatures to simulate and their initial directions and locations, with onecreature per line. Each of these lines has the following format:<species> <initial-direction> <initial-row> <initial-column>where <species> is one of the species from the species summary file,<initial-direction> describes the initial direction and is one of the strings “east”,“south”, “west”, and “north”. <initial-row> describes the initial row location of thecreature. We use the convention that the top-most row of the grid is row 0 and the rownumber increases from top to bottom. <initial-column> describes the initial columnlocation of the creature. We use the convention that the left-most column of the grid is column0 and the column number increases from left to right. An example of a world file looks like:44hop east 2 0flytrap east 2 2It says that the size of the grid is 4-by-4 and there are two creatures in the world. The firstcreature belongs to the species hop. It faces east and lives at point (2, 0) initially. The secondcreature belongs to the species flytrap. It faces east and lives at point (2, 2) initially.In the simulation, the order on the creatures to simulate is important. This order isdetermined by the order that these creatures appear in the world file.V. Program ArgumentsYour program will obtain the names of the species summary file and the world file via programarguments. Additionally, your program will be told the number of rounds to simulate andwhether it should print the simulation result verbosely or not.The expected order of arguments is:<species-summary> <world-file> <rounds> [v|verbose]The first three arguments are mandatory. They give the name of the species summary file, thename of the world file, and the number of simulation rounds, respectively. The last argument isoptional. If the last argument is the string “v” or the string “verbose”, your program should printthe simulation result verbosely, which will be explained later. Otherwise, if it is omitted or is anyother string, your program should print the result concisely, which will also be explained later.Suppose that you program is called p3. It may be invoked by typing in a terminal:./p3 species world 10 vThen your program should read the species summary from the file called “species” and the worldfile from the file called “world”. The number of simulation rounds is 10. Your program shouldprint the simulation information verbosely.VI. Error Checking and Error MessageYour program should check for errors before it starts to simulate the moves of the creatures. Ifany error happens, your program should issue an error message and then exit. If there are noerrors happening, then the initial state of the creature world is legal and your program can startsimulating the creature world.We require you to do the following error checking and print the error message in exactly thesame way as described below. Note that some of the output error message has two lines and eacherror message should be ended with a newline character. All error messages should be sent to thestandard output stream cout; none to the standard error stream cerr.1. Check whether the number of arguments is less than three. If it is less than three, then one ofthe mandatory arguments is missing. You should print the following error message:Error: Missing arguments!Usage: ./p3 <species-summary> <world-file> <rounds> [v|verbose]2. Check whether the value <rounds> supplied by the user is negative. If it is negative, youshould print the following error message:Error: Number of simulation rounds is negative!3. Check whether file open is successful. If opening species summary file, world file, or anyspecies program file fails (for example, the file to be opened does not exist), print the followingerror message:Error: Cannot open file <filename>!where <filename> should be replaced with the name of the file that fails to be opened. If thatfile is not in the same directory as your program, you need to include its path in the<filename>. As you may know, there are multiple ways to specify a path. For us, the pathname should be specified in the most basic way, i.e., “<dir>/<filename>” (not“./<dir>/<filename>”, “<dir>//filename”, etc.). Once you find a file that cannot beopened, issue the above error message and terminate your program.4. Check whether the number of species listed in the species summary file exceeds the maximalnumber of species MAXSPECIES. If so, print the following error message:Error: Too many species!Maximal number of species is <MAXSPECIES>.where <MAXSPECIES> should be replaced with the maximal number of species set by yourprogram.5. Check whether the number of instructions for a species exceeds the maximal size of a speciesprogram MAXPROGRAM. If so, print the following error message:Error: Too many instructions for species <SPECIES_NAME>!Maximal number of instructions is <MAXPROGRAM>.where <SPECIES_NAME> should be replaced with the name of the species whose program hasmore instructions than the maximal number allowed and <MAXPROGRAM> should be replacedwith the maximal size of a species program set by your program.6. Check whether the species program file contains illegal instructions. We only allow nineinstructions as listed in Table 1. Your program needs to check whether the instruction name isone of the nine legal instruction names listed in the string array opName (which is defined inSection III). If an instruction name is not recognized, you should print the following errormessage:Error: Instruction <UNKNOWN_INSTRUCTION> is not recognized!where <UNKNOWN_INSTRUCTION> should be replaced with the name of the unrecognizedinstruction. You can assume that for any recognized instruction, it is given in the correct format.Thus, you don’t need to check whether an integer is appended after the instruction name or not.If there are multiple unrecognized instruction names, you only need to print out the first one andthen terminate the program.7. Check whether the number of creatures listed in the world file exceeds the maximal number ofcreatures MAXCREATURES. If so, print the following error message:Error: Too many creatures!Maximal number of creatures is <MAXCREATURES>.where <MAXCREATURES> should be replaced with the maximal number of creatures allowedby your program.8. Check whether each creature in the world file belongs to one of the species listed in thespecies summary file. If the species for a creature is not recognized, print the following errormessage:Error: Species <UNKNOWN_SPECIES> not found!where <UNKNOWN_SPECIES> should be replaced with the unrecognized species. If there aremultiple unrecognized species, you only need to print out the first one and then terminate theprogram.9. Check whether the direction string for each creature in the world file is one of the strings inthe array directName (which is defined in Section III). If the direction string is not recognized,print the following error message:Error: Direction <UNKNOWN_DIRECTION> is not recognized!where <UNKNOWN_DIRECTION> should be replaced with the unrecognized direction name. Ifthere are multiple unrecognized direction names, you only need to print out the first one and thenterminate the program.10. Check whether the grid height given by the world file is legal. A legal grid height is at leastONE and less than or equal to a maximal value MAXHEIGHT. If the grid height is illegal, printthe following error message:Error: The grid height is illegal!11. Check whether the grid width given by the world file is legal. A legal grid width is at leastONE and less than or equal to a maximal value MAXWIDTH. If the grid width is illegal, print thefollowing error message:Error: The grid width is illegal!12. Check whether each creature is inside the boundary of the grid. If any creature is outside theboundary, print the following error message:Error: Creature (<SPECIES> <DIR> <R> <C>) is out of bound!The grid size is <HEIGHT>-by-<WIDTH>.where <SPECIES> should be replaced with the species the creature belongs to, <DIR> bereplaced with the direction the creature is facing, <R> be replaced with the row location of thecreature, <C> be replaced with the column location of the creature, <HEIGHT> be replaced withthe height of the grid, and <WIDTH> be replaced with the width of the grid. Here, we use thefour-tuple (<SPECIES> <DIR> <R> <C>) to identify the creature. For example, if giventhe following world file:flytrap east 0 0hop south 3 2food west 2 1then Creature (hop south 3 2) is outside the boundary. Then, the error message should be:Error: Creature (hop south 3 2) is out of bound!The grid size is 3-by-3.If there are multiple creatures outside the boundary, you only need to print out the first one andthen terminate the program.13. Check whether each square in the grid is occupied by at most one creature. If any square isoccupied by more than one creature, print the following error message:Error: Creature (<SP1> <DIR1> <R> <C>) overlaps with creature(<SP2> <DIR2> <R> <C>)!where (<R> <C>) identifies the square which is occupied by more than one creature, the firstfour-tuple (<SP1> <DIR1> <R> <C>) identifies the second creature in order thatoccupies the square, and the second four-tuple (<SP2> <DIR2> <R> <C>) identifies thefirst creature in order that occupies the square. Once you find two creatures occupying thesame square, you issue the above error message and then terminate the program.Since you may implement the error checking in different order and in the case that there ismore than one error, the first error message printed out may be different. Therefore, wewill only test your error checking using test cases containing just one error.VII. Simulation OutputOnce all of the above error checkings on the initial state of the creature world are passed, youcan start simulating the creature world. You should print to the standard output the simulationinformation, either in a verbose mode or in a concise mode, depending on whether anadditional argument “v” or “verbose” is provided by the user.In the verbose mode, you first print the initial state of the world. In doing so, you begin withprinting the string “Initial state” followed by a newline. Then you graphically show thelayout of the initial grid using just characters. Each square takes a four-character field in yourterminal. Adjacent squares on the same row are separated by one space. If a square in the grid isnot occupied by any creature, the field for that square is filled with FOUR “_”. If a square isoccupied by a creature, then the first two characters of the field for that square are the first twoletters of the name of the species the creature belongs to. (We assume that all the species namescontain at least two characters and no two species names have the identical first two characters.)The third character in the field is a “_” and the fourth character is the first character of thedirection the creature faces, i.e., “e” for “east”, “s” for “south”, “w” for “west”, and “n” for“north”.For example, suppose a world file looks likehop east 2 0flytrap east 2 2Then the layout of the initial grid is printed as____ ____ ____ ________ ____ ____ ____ho_e ____ fl_e ________ ____ ____ ____Note that there is a space at the end of each line.After printing the initial layout, we begin the simulation from the first round to the last roundspecified by the user. In the i-th simulation round, you first print “Round <i>” followed by thenewline. For example, in the first round, you should first printRound 1During each simulation round, you simulate the moves of all the creatures in turn. When startingsimulating a creature, you announce that this creature takes action by printingCreature (<SPECIES> <DIR> <R> <C>) takes action:followed by a newline. In the above output, the four-tuple (<SPECIES> <DIR> <R> <C>)shows the state of the creature right before it takes the action, where <SPECIES> should bereplaced with the species the creature belongs to, <DIR> be replaced with the direction thecreature is facing, <R> be replaced with the row location of the creature, and <C> be replacedwith the column location of the creature.After this, you print the sequence of instructions that the creature executes for its turn. Thissequence may include any number of if*** and go instructions and end with one of the hop, left,right, and infect instruction. You should print the sequence of instructions the creature executesin order, with one instruction per line. The output format for an instruction is:Instruction <INSTR_NO>: <INSTR_NAME> [GOTO_STEP]where <INSTR_NO> should be replaced with the number of that instruction in the program (thenumber starts from 1), <INSTR_NAME> should be replaced with the name of the instruction,and [GOTO_STEP] is the number in an if*** or a go instruction and is optional.After printing the last instruction of the creature under consideration, you should print theupdated layout of the grid, using the same rule as you print the initial layout.Now let’s look at an example. Suppose that the program for the species hop ishopgo 1and the program for the species flytrap isifenemy 4 If there is an enemy, go to step 4.left If no enemy, turn left.go 1infectgo 1Then, given the following world file44hop east 2 0flytrap east 2 2the simulation information for the first round is printed asRound 1Creature (hop east 2 0) takes action:Instruction 1: hop____ ____ ____ ________ ____ ____ ________ ho_e fl_e ________ ____ ____ ____Creature (flytrap east 2 2) takes action:Instruction 1: ifenemy 4Instruction 2: left____ ____ ____ ________ ____ ____ ________ ho_e fl_n ________ ____ ____ ____The simulation information for the second round is printed asRound 2Creature (hop east 2 1) takes action:Instruction 2: go 1Instruction 1: hop____ ____ ____ ________ ____ ____ ________ ho_e fl_n ________ ____ ____ ____Creature (flytrap north 2 2) takes action:Instruction 3: go 1Instruction 1: ifenemy 4Instruction 2: left____ ____ ____ ____ ____ ____ ____ ________ ho_e fl_w ________ ____ ____ ____In the concise mode, you print the initial state of the world in the same way as in the verbosemode. When printing the simulation information for the i-th round, you first print “Round <i>”followed by the newline. Then you print the final action of each creature in turn, with onecreature per line. The format is:Creature (<SPECIES> <DIR> <R> <C>) takes action: <LAST_INSTR>Same as in the verbose mode, the four-tuple (<SPECIES> <DIR> <R> <C>) shows thestate of the creature right before it takes the action. <LAST_INSTR> should be replaced withthe last instruction the creature executes for its turn, which is one of the hop, left, right, andinfect instruction.After printing the final actions for all the creatures, you print the updated layout at the end ofthis round.For the same world file as above:44hop east 2 0flytrap east 2 2In the concise mode, the simulation information for the first round is printed asRound 1Creature (hop east 2 0) takes action: hopCreature (flytrap east 2 2) takes action: left____ ____ ____ ________ ____ ____ ________ ho_e fl_n ________ ____ ____ ____The simulation information for the second round is printed asRound 2Creature (hop east 2 1) takes action: hopCreature (flytrap north 2 2) takes action: left____ ____ ____ ________ ____ ____ ________ ho_e fl_w ________ ____ ____ ____There are no blank lines in the output for both the verbose and concise mode.VIII. Source Code Files and CompilingThere is a source code file located in the Project-3-Related-Files.zip from ourCanvas Resources:world_type.h: The header file which defines a number of types for you to use.You should copy this file into your working directory. DO NOT modify it!You need to write three other source code files. The first file is named as simulation.h,which contains the declarations for all the functions you write, just like the p2.h in our projecttwo. The second file is named as simulation.cpp, which contains all the implementations ofthose functions declared in the simulation.h. The third file is named as p3.cpp, whichcontains only the main function. After you have written these files, you can type the followingcommand in the terminal to compile the program:g++ -Wall -o p3 p3.cpp simulation.cppThis will generate a program called p3 in your working directory. In order to ensure that theonline judge compiles your program successfully, you should name you source code files exactlylike how they are specified above.IX. Implementation Requirements and Restrictions1. In writing your code, you may use the following standard header files: <iostream>,<fstream>, <sstream>, <iomanip>, <string>, <cstdlib>, and <cassert>. Noother header files can be included.2. You may not define any global variables yourself. You can only use the global constant intsand string arrays defined in world_type.h.3. Pass large structs by reference rather than value. Where appropriate, pass const references /pointers-to-const. Do not pass lots of little arguments when you can pass an appropriate, largerstructure instead.4. All required output should be sent to the standard output stream; none to the standard errorstream.5. You should strive not to duplicate identical or nearly‐identical code, and instead collect suchcode into a single function that can be called from various places. Each function should do asingle job, though the definition of "job" is obviously open to interpretation. Most students writetoo few functions that are too large.X. Hints and Tips1. This project will take you longer than project two did, so start early!2. Do this project in stages. First, be able to read the species summary file. Second, be able toread the programs for all the species. Third, be able to read the world file. Write some diagnosticcode that can print out the species summary, the program for each species, and the creatures, tomake sure that you are reading them correctly. Implement the error checking and test it withdifferent illegal inputs. Once you can read the structures in, implement the simple moves such asleft and right. Once you have that working, implement moves such as hop and infect. Finally,implement if*** and go instructions.3. Take advantage of the fact that enumerations are sequentially numbered from 0 to N‐1.4. Use the right methods of input file stream to read file. In some cases, you may first use thegetline() function to read the entire line of a file and then use an input string stream toextract the content from that line.5. The hop instruction will only cause the creature to move forward when the square it is facingis empty. If moving forward would put the creature outside the boundaries of the grid or wouldcause it to land on top of another creature, the hop instruction does nothing. However, althoughthe hop action is not executed successfully, you should update the program counter so that itpoints to the next instruction after this hop instruction. The similar situation also applies to theinfect instruction. If there is no enemy to infect, the infect operation does nothing. However, youshould update the program counter to its next instruction.6. As a hint, you probably need to write the following eight functions or some variations of them.However, these are not the only functions you have to write. You probably need to write morefunctions for different jobs.bool initWorld(world_t &world, const string &speciesFile, const string &creaturesFile);// MODIFIES: world//// EFFECTS: Initialize "world" given the species summary file// "speciesFile" and the world description file// "creaturesFile". This initializes all the components of// "world". Returns true if initialization is successful.void simulateCreature(creature_t &creature, grid_t &grid, boolverbose);// REQUIRES: creature is inside the grid.//// MODIFIES: creature, grid, cout.//// EFFECTS: Simulate one turn of "creature" and update the creature,// the infected creature, and the grid if necessary.// The creature programID is always updated. The function// also prints to the stdout the procedure. If verbose is// true, it prints more information.void printGrid(const grid_t &grid);// MODIFIES: cout.//// EFFECTS: print a grid representation of the creature world.point_t adjacentPoint(point_t pt, direction_t dir);// EFFECTS: Returns a point that results from moving one square// in the direction "dir" from the point "pt".direction_t leftFrom(direction_t dir);// EFFECTS: Returns the direction that results from turning// left from the given direction "dir".direction_t rightFrom(direction_t dir);// EFFECTS: Returns the direction that results from turning// right from the given direction "dir".instruction_t getInstruction(const creature_t &creature);// EFFECTS: Returns the current instruction of "creature".creature_t *getCreature(const grid_t &grid, point_t location);// REQUIRES: location is inside the grid.//// EFFECTS: Returns a pointer to the creature at "location" in "grid".XI. TestingWe provide you with a few test cases in the directory called tests, which can be found insideProject-3-Related-Files.zip from our Canvas Resources.Inside the tests directory, there is an example species summary file called species and twosubdirectories called creatures and world-tests. The creatures directory contains anumber of species program files. The world-tests directory contains five world files and thefiles recording the correct outputs.The first world file is called outside-world, which describes an illegal world with onecreature located outside the boundary of the grid.To run this test case, type the following commands:./p3 species world-tests/outside-world 5 > outside-world.outThen the output of your program is redirected to a file named outside-world.out. Thecorrect output is recorded in the file outside-world.answer in the directory worldtests.You can use the diff command to check whether the file outside-world.out issame as the file outside-world.answer.The second world file is called overlap-world, which describes an illegal world with twocreatures located at the same square in the grid. You can run this test case using a similarcommand as shown above and compare your output with the correct output recorded in the fileoverlap-world.answer.The next three world files world1, world2, and world3 are legal world files. You can runthese test cases in the similar way. The number of simulation rounds for world1, world2, andworld3 are 5, 20, and 40, respectively. For these test cases, we provide you with both theverbose and the concise output files. The verbose output files are these files named as*-verbose.answer and the concise output files are these files named as*-concise.answer.These are the minimal amount of tests you should run to check your program. Those programsthat do not pass these tests are not likely to receive much credit. You should also write otherdifferent test cases yourself to test your program extensively. In doing so, you need to write yourown legal/illegal species summary files, legal/illegal world files, and species program files.Indeed, it will be very interesting to create new species yourself and observe what kind ofspecies will finally dominate the SIMPLE WORLD given different initial layout!XII. Submitting and Due DateYou should submit your source code files simulation.h, simulation.cpp, and p3.cpp.These files should be submitted via the online judgment system. See announcement from theTAs for details about submission. The due date is 11:59 pm on July 2, 2019.XIII. GradingYour program will be graded along three criteria:1. Functional Correctness2. Implementation Constraints3. General StyleFunctional Correctness is determined by running a variety of test cases against your program,checking against our reference solution. We will grade Implementation Constraints to see if youhave met all of the implementation requirements and restrictions. General Style refers to the easewith which TAs can read and understand your program, and the cleanliness and elegance of yourcode. For example, significant code duplication will lead to General Style deductions.因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:
微信:codehelp