程序代写代做代考 algorithm chain C CSE240 – Assignment – World Building

CSE240 – Assignment – World Building
Topics:
• Dynamic 2D arrays
• Pointers
• Function use
• Procedural Generation based on Probabilities
Description:
This program will generate a Fantasy Land based on simple probability rules using a 2D Array of Characters. This program will feature several functions.
Use the following Guidelines:
• Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).
• Keep identifiers to a reasonably short length.
• Use upper case for constants. Use title case (first letter is upper case)
for classes. Use lower case with uppercase word separators for all other
identifiers (variables, methods, objects).
• Use tabs or spaces to indent code within blocks (code surrounded by braces).
This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.
• Use white space to make your program more readable.
Important Note:
All submitted assignments must begin with the descriptive comment block. To avoid losing trivial points, make sure this comment header is included in every assignment you submit, and that it is updated accordingly from assignment to assignment.

Specifications:
The software will generate a world using characters. You will store these objects in a 2D array. You will use existing information to produce new information to store in the array.
User Interface:
When the program starts you will ask the user to input a width and height for the world. This should be between 20 and 50. This will determine how big the world will be.
Required Functions:
You will create several functions for the purpose of generating the land. Our goal here will be to lean heavily into “a function should do one thing well.” Do not create side effects in the functions. Gather inputs externally and pass them in through parameters.
• char** GenerateLand(int width, int height)
• char PickLandType()
• char GenerateNeighbor(char item)
• void PrintLand(char** land, int width, int height)
You will write a function for each of the terrain types to generate a character. These functions should be called from GenerateNeighbor(char item):
• char NewFromRuralLand()
• char NewFromForest()
• char NewFromTown()
• char NewFromWater()
• char NewFromCity()
• char NewFromMountain()

RuralLand
• Should be represented with an ‘R’
• Should generate a neighbor object
with these probabilities:
with these probabilities:
with these probabilities:
with these probabilities:
with these probabilities:
with these probabilities:
Forests
Town
o 40%RuralLand o 25%Forest
o 15%Town
o 10%Water
o 0%City
o 10%Mountain
• Should be represented with an ‘F’
• Should generate a neighbor object
o 20%RuralLand o 40%Forest
o 5%Town
o 20%Water
o 0%City
o 15%Mountain
• Should be represented with a ‘T’
• Should generate a neighbor object
o 20%RuralLand o 5%Forest
o 40%Town
o 10%Water
o 20%City
o 5%Mountain
City/Castle
• Should be represented with a ‘C’
• Should generate a neighbor object
o 0%RuralLand o 15%Forest o 25%Town
o 10%Water
o 40%City
o 10%Mountain
Mountains
• Should be represented with a ‘M’
• Should generate a neighbor object
o 5%RuralLand o 15%Forest o 5%Town
o 15%Water
o 10%City
o 50%Mountain
Waters (lakes/ponds/rivers)
• Should be represented with a ‘W’
• Should generate a neighbor object
o 15%RuralLand o 20%Forest
o 5%Town
o 40%Water
o 10%City
o 10% Mountain

Algorithm breakdown:
Main:
1. Get width and height from user
2. Call GenerateLand with that input (don’t forget to capture the return value) 3. Call PrintLand with result
GenerateLand Algorithm Breakdown:
In generate land you’ll dynamically allocate a 2D character array based on user input passed in.
The upper left corner will be completely random (call PickLandType()) To generate the rest of the array:
First row:
1. Generate each character in the row by passing the character directly left (x-1) to it into GenerateNeighbor()
2. Assign the result from GenerateNeighbor into that element First Column:
1. Do the same algorithm, except use the data from the index above (y-1) Subsequent rows:
1. “Flip a coin”
2. Based on the “coin flip” generate the current item from the data above or
the date to the left 3. Continue
UH WHAT?!
Take your time and think about it. It’s not actually a hard algorithm. You’ll be building a nested for loop to generate your terrain. You’ll iterate the outer loop on the Y and the inner loop on the X
Then you build an if…else if…else chain to make sure you generate the terrain correctly.
C’mon Prof. Selgrad … this sounds daunting … Did you build this?
Yes … with color! Mine weighed in around 260 lines of code.
Most of the code is redoing the if-else if chains for each newFrom function
R
R
F
R
R
T
C
C
M
F
R
??

Output
Sample output:
Welcome to Fantasy Land Generator! Enter width of land: 30
Enter height of land: 30
MMWRTFWWWWRFWFTMMCTTMRRFMMTRRM CFMMCCWMMRMWCFWWWFFRWFFRTCFFTC TMMMMCFMCCFRFFWRFFRRRTRRFMRMMM CWMMMTRWTWRRRRRRRMTTCMMTRFFWMM TRMWWMFFTRTRFTWWCTFTMMRRFRFRMM WFWWFMMFTTTRFWCWWMMMMMFRMRMRRR RFWCMWWWTMMMCCCCCCRTRRWRMRMFMR TRRTTFWRRWMTCCFCTRMCFMFWMMMFFR MRFRCCWFWWMTTFRTTMMFFRRFMMCTRF WTCCFCCFRWMRRRTFTTWFWMFRMTTTMF MCCCFFFWWFFFFFTRTCMWWMMMFFTRTF RMWWRRRWWMMMMMCRMMRTMCMMWRRRRF RMWFTMWRRFFMMFMFFWRMMMFCWTRWWW RRRRTMRRRRFFCFCMFFFCCTTTTCCTFW RFRRFFWWWWFFWRRTWTRCTCRRRRMTMF TRRRRFRRRFFTRFRCCCFFCFWWRWMFFT TRFRRFWRFFRCWCWWFFWWWRFFRWWWFT TTCCRMFWWFFRTCWFFRRFFRRRRWTRWM RMCFMWTFMWFRTCWWWRFRMMMFWFTRFW FFFFFTTWMMFMTCTFFRFFFWWFFFMFMW WTTTRCTWMMFWWWRRRRFMRMCWFWRTFC WMCRFCTCFMFCCTTRRFRFFWWCCWCTWF WFTCMTCWWMMTTMRRRFFRFFMCCRTCFW WWWMWWCWCWMMRMFWFRTRFRMCFWWCFF WFFWRTCCWRCTTCTCFFCMMMMTTMMMFT TTMCMRTCWRTMCTTFWWWWMTRTTFFFTT TRWMMFRWWWFMMCCRWWWCMMWWMFFFWF FWWWMCFTCCWMMFCTRFWCTFRMTRRRFF FRTCCCFTWWCMMMTTRTWCFFFFTFTFRT FWTCMCWCCWCCCCCRFWMTFRWRRWFRMC
Extra Credit:
+3 – Put all of the required function prototypes in a .h file and all the function definitions in a .cpp file and your main in a separate .cpp file. Write a Makefile for general.asu.edu to compile them.
+2 – Color your output. Find a console-color library that works across all Operating Systems and integrate it.
NOTE – this should be stand alone and not require any installation on the grader’s part, just the library files in the proper location.
Any required compilation should be accounted for in a Makefile.
MAKE SURE you put any instruction for building/running your code in your submission notes.
Figure 1 – Colored output with termcolor library

What to turn in:
Create a zip file to submit:
__hw3.cpp (or .c)
• If doing extra credit
o __LandGeneration.h
o __LandGeneration.cpp (or .c) o Makefile
o Any files needed to make the color work
Name your zip file __hw3.zip
Submit to the course shell.
Grading of Programming Assignment
The grader will grade your program following these steps:
(1) Compile the code. If it does not compile you will receive a U on the Specifications in the Rubric
(2) The grader will read your program and give points based on the points allocated to each component, the readability of your code (organization of the code and comments), logic, inclusion of the required functions, and correctness of the implementations of each function.