java代写: INFO1103 Assignment 3

INFO1103 Assignment 3

Task description

Due: 9:00pm Sunday, 5 June 2016

This assignment is worth 10% of your final assessment

Rural firefighters regularly backburn bushland in a controlled manner to reduce the risk of hazardous bushfires. In this assignment you will implement a simulation of a controlled burn within a region of land. Trees of varying heights are scattered throughout the region and fires are started at particular locations. The simulation operates on a daily time schedule where the fire spreads to neighbouring trees as each day passes according to the wind direction and keeps track of the amount of air pollution.

You are encouraged to ask questions on Ed using the assignments category. As with any assignment, make sure that your work is your own, and you do not share your code or solutions with other students.

Working on your assignment

You can work on this assignment on your own computer or the lab machines. It is important that you continually back up your assignment files onto your own machine, external drives, and in the cloud.

You are encouraged to submit your assignment on Ed while you are in the process of completing it. By submitting you will obtain some feedback of your progress on the sample test cases provided.

Academic declaration

By submitting this assignment you declare the following:

I declare that I have read and understood the University of Sydney Academic Dishonesty and Plagiarism in Coursework Policy, and except where specifically acknowledged, the work contained in this assignment or project is my own work, and has not been copied from other sources or been previously submitted for award or assessment.

I understand that failure to comply with the the Academic Dishonesty and Plagiarism in Coursework Policy, can lead to severe penalties as outlined under Chapter 8 of the University of Sydney By-Law 1999 (as amended). These penalties may be imposed in cases where any significant portion of my submitted work has been copied without proper acknowledgement from other sources, including published works, the internet, existing programs, the work of other students, or work previously submitted for other awards or assessments.

I realise that I may be asked to identify those portions of the work contributed by me and required to demonstrate my knowledge of the relevant material by answering oral questions or by undertaking supplementary work, either written or in the laboratory, in order to arrive at the final assessment mark.

I acknowledge that the School of Information Technologies, in assessing this assignment, may reproduce it entirely, may provide a copy to another member of faculty, and or communicate a copy of this assignment to a plagiarism checking service or in house computer program, and that a copy of the assignment may be maintained by the service or the School of IT for the purpose of future plagiarism checking.

1

INFO1103

Implementation details

Your task is to implement a controlled fire simulation based on the descriptions and examples below.

Your program must be contained in Firebot.java, Simulation.java, Tree.java and Perlin.java source files and produce no errors when compiled on the lab machines and Ed. The program will run with given arguments, reading from standard input and writing to standard output.

Important – your program will be marked automatically, so make sure that you follow the assignment specifications carefully. Your program output must match the exact output shown in the examples.

Tree attributes

Each tree has the following attributes:

• Fire – Fire intensity between 0 and 9. Tree with fire 0 indicates there is no fire at position.
• Height – Tree height between 0 and 9. Tree with height 0 indicates there is no tree at position. • Burnt down – Whether or not the tree has completely burnt down from a fire.

Command line arguments

Your program should read in three positive non zero integer command line arguments that specify the random number generator seed, width and height of the land. If any given arguments are missing or invalid then output the following error message and immediately terminate the program. For example:

The simulation starts at day 1 with no wind and no pollution.
Given this information, the program generates a rectangular region of land with trees of varying

heights. If you change the seed value then a different set of trees will be generated.
You interact with the simulation by entering commands, e.g. displaying the heights of the trees,

displaying the fires, starting a fire within a region, advancing the day, setting the wind direction, etc. The program terminates when the bye command is issued or there is no more input.

Usage: java Firebot <seed> <width> <height>

Introduction to Programming Page 2 of 14

INFO1103

Displaying the simulation

There are two ways to display the current state of the simulation. You can show the height of each treewiththeshow height,orthefireintensityofeachtreewiththeshow fire.Ineithercase, the trees are displayed in a rectangular fashion with a border around the entire region, like so:

$ java Firebot 0 8 5
Day: 1
Wind: none

> show height +—————+ | 2213 2| |63 2| |5 4 1 3 1 5| |33 13| |5 2 2 1 2 4| +—————+

> show fire +—————+ | …. .| |.. .| |. . . . . .| |.. ..| |. . . . . .| +—————+

> fire 4 0
Started a fire

> show fire +—————+ | ..1. .| |.. .| |. . . . . .| |.. ..| |. . . . . .| +—————+

• Trees that have been burnt down will display x for both height and fire views.

• Trees with height 0 indicates there is no tree at that location, so be sure not to display 0.

• For the fire view, if there is a tree at that location and no fire then display . otherwise display a number indicating the intensity of the fire. Do not display anything when the tree height is 0.

Introduction to Programming Page 3 of 14

Fire spreading simulation

Initially there will be no fires, but you can start a fire in a particular region by using the fire command. This will start a fire with intensity 1 at each tree within the specified rectangular region. Thetoplefttreeisat(0, 0),andthebottomrighttreeisat(width – 1, height – 1).

Each day that progresses, two things will happen: existing fires will continue to burn down the trees, and the fires will spread onto neighbouring trees in the direction of the wind.

Fire spreading simulation

  • Initially the tree will not be on fire (fire = 0).
  • The tree can be lit on fire (fire = 1) in two ways: by the fire command, or from spreading

    from a neighbouring tree. If a tree has height 0, it cannot be lit on fire.

  • Each day that passes, the fire intensity will increase by 1 until it reaches 9 (thus trees that have been burning for longer will have a higher fire value). At that time, the fire intensity cannot increase any more, so the tree will start to burn down by decreasing the height of the tree by 1 for each subsequent day.
  • As soon as the height of the tree reaches 0, the tree has completely burnt down and so the fire existsnolonger(fire = 0,height = 0andisBurntDown = true).

    Fire spreading process

    The fire will spread each day according to the current wind direction. There are 6 different wind directions: all, none, north, south, east and west.

    A tree with height > 0 can be lit on fire the next day by spreading from a neighbouring tree. If the windisintheeastdirectionandatreeatlocation(5, 5)isonfire(fire > 0),thenthenextday thetree(ifany)atlocation(6, 5)willbelitonfire(fire = 1).

    The fires will only spread to neighbouring trees if the wind is in any direction of: all, north, south, east or west. Fires cannot spread to diagonal trees, trees already on fire, or burnt down trees. If the wind direction is all then the fires will spread in all four directions each day.

    When applying these rules you should create a copy of the grid that contains the next state. The next state of the grid should be calculated based on the previous state of the grid.

INFO1103

Introduction to Programming Page 4 of 14

INFO1103

$ java Firebot 2 8 5
Day: 1
Wind: none
> fire 1 3
Started a fire
> wind east
Set wind to east
> show fire
+---------------+

|. ..
| ..
|
|. 1.
|. +—————+

> next
Day: 2
Wind: east

> show fire +—————+ |……|

> next
Day: 4
Wind: north

> show fire +—————+ |……| |. .. | | 1. .| |.4 32. .| |. ..| +—————+

> wind all
Set wind to all
> next
Day: 5
Wind: all

> show fire +—————+ |… . ..| |…| |21.| |15431.| |1 ..| +—————+

> wind none
Set wind to none

>next8 Day: 13 Wind: none

> show height +—————+ |764 1 11| |161| |376| |3×1122 | |3 32| +—————+

> next
Day: 14
Wind: none
> show fire
+---------------+

. ..|

. .

. . .

| .| .| ..|

|…. |… |99 |9xxx9
|9 +—————+

. .| | .| .| ..|

> show height
+---------------+

|… |.. |.21..
|. +—————+

1 1| | 6| 2| 32|

|7641 |161
| 26 |2xxx1
|2 +—————+

| .| .| ..|

> next
Day: 3
Wind: east

> show fire
+—————+
|… . ..| |…||…|

> show fire +—————+ |… . ..|

| .. .| |.321.. | |. ..| +—————+

> wind north
Set wind to north

| 99 .| |9×999. | |9 ..| +—————+

Introduction to Programming

Page 5 of 14

Pollution

The simulation will keep track of the amount of pollution in the air each day. Pollution is initially 0. After the fire burning and spreading procedures are carried out, the pollution level is updated.

For each tree:

• The pollution is lowered by an amount equal to the height of the tree.
• The pollution is raised by an amount equal to the fire intensity of the tree.

After processing all trees, if the pollution level is negative, then set it to 0.

INFO1103

Introduction to Programming Page 6 of 14

Commands

Your program should implement the following commands, that are all case insensitive.

• If any command that is inputted is unknown or invalid then output: Invalid command • The fire and extinguish commands accept a region like so:

– <x> <y> <width> <height> – Rectangular region with top left at (x, y) and size (width, height). width and height must be positive and the region must not extend outside the bounds of the land.

– <x> <y> – Single tree at location (x, y). – all – All trees.

bye

Displays bye and terminates the program.

help

Displays the help message.

INFO1103

> bye bye

> help
BYE
HELP

DATA STATUS

NEXT <days>
SHOW <attribute>
FIRE <region>
WIND <direction>
EXTINGUISH <region>

status

Displays the current day and wind direction.

> status
Day: 1
Wind: none

Introduction to Programming

Page 7 of 14

data

Displays the fire damage and air pollution statistics.

• Fire damage is the percentage of trees that have burnt down, rounded to 2 decimal places. • Pollution is a non negative integer value and is updated after every day as explained above.

next [<days>]

Advances to the next day and carries out the fire burning and pollution rules described above. It can optionally accept a positive integer argument which indicates the number of days to advance by.

The status current day and wind direction are displayed after the next command is run.

INFO1103

> data
Damage: 12.34%
Pollution: 420
> next
Day: 2
Wind: none
> next 5
Day: 7
Wind: none

show <attribute>

Displays the state of the trees.
A border is displayed around the land and each tree in each row is separated by a space.

If a tree is burnt down, it is displayed as x, otherwise depending on the attribute: • fire – shows the fire intensity level of each tree:

– Trees with height 0 should display nothing. – If fire = 0 then display .
– Otherwise display the fire intensity level.

• height – shows the height level of each tree:
– Trees with height 0 should display a space instead of 0.

Introduction to Programming

Page 8 of 14

wind <direction>

Sets the wind direction. The direction can be set to: all, none, north, south, east or west.

fire <region>

Ignites every tree witin the given region by setting fire to 1 for those trees. Only trees that are not alreadyonfirecanbelit.DisplayStarted a fireorNo fires were starteddepending on the outcome.

See above for an explanation of how the region can be specified.

INFO1103

> wind north
Set wind to north
Day: 1
Wind: none

> show fire +—————+ |. . . . . .| |…| | .. .| |. . . . . . | |. ..| +—————+

> fire 2 2 3 3
Started a fire

> show fire +—————+ |. . . . . .| |…| | 11 .| |. . 1 1 1 . | |. ..| +—————+

> fire 2 2 3 3
No fires were started

Introduction to Programming Page 9 of 14

INFO1103

extinguish <region>

Extinguishes all fires in the given region.
Iftherearenofireswithintheregion,thenoutputNo fires to extinguish,otherwiseextin-

guishallfiresintheregionbysettingfiretoandthendisplayExtinguished fires.

> fire 0 0
Started a fire

> show fire +—————+ |1 . . . . .| |…| | .. .| |. . . . . . | |. ..| +—————+

> extinguish 1 0
No fires to extinguish
> extinguish 0 0 1 1
Extinguished fires
> extinguish all
No fires to extinguish

> show fire +—————+ |. . . . . .| |…| | .. .| |. . . . . . | |. ..| +—————+

Introduction to Programming Page 10 of 14

INFO1103

Examples

Burning one tree

 $ java Firebot 0 4 3
 Day: 1
 Wind: none

> show height +——-+
| 1 3| |241| |224| +——-+

 > fire 1 1
 Started a fire

> show fire +——-+ |..| |.1 .| |…| +——-+

 > next 8
 Day: 9
 Wind: none

> show fire +——-+
| . .| |.9 .| |. ..| +——-+

> show height +——-+ |13| |24 1| |224| +——-+

> next
Day: 10
Wind: none

> show fire +——-+
| . .| |.9.| |…| +——-+

> show height +——-+
| 1 3| |231| |224| +——-+

> next 3
Day: 13
Wind: none

> show fire +——-+
| . .| |.x .| |. ..| +——-+

> show height +——-+
| 1 3| |2x 1|

|2 24| +——-+

> bye bye

Introduction to Programming

Page 11 of 14

Burning east

 $ java Firebot 0 8 2
 Day: 1
 Wind: none

> show height +—————+ | 4332343| |361625| +—————+

 > fire 2 0
 Started a fire

> show fire +—————+ | .1…..| |……| +—————+

 > wind east
 Set wind to east
 > next 5
 Day: 6
 Wind: east

> show fire +—————+ | .654321| |. . . . . . | +—————+

> show height +—————+ | 4332343| |3 6 1 6 2 5 | +—————+

> next 6
Day: 12
Wind: east

> show fire +—————+ | .x99987| |……| +—————+

INFO1103

> show height +—————+ | 4×11343| |3 6 1 6 2 5 | +—————+

> next 9
Day: 21
Wind: east

> show fire +—————+ | .xxxxxx| |. . . . . . | +—————+

> show height +—————+ | 4xxxxxx| |3 6 1 6 2 5 | +—————+

> bye bye

Introduction to Programming

Page 12 of 14

Big fire

 $ java Firebot 1 8 8
 Day: 1
 Wind: none

> show fire +—————+ |. . .| |6 . .| |9987 . | |987 . .|

> extinguish all
Extinguished fires

INFO1103

> show fire +—————+ |…|

> show height
+—————+
| 314||7…||…| | 2 5 3| |56 .. | |xxxx . | |21121||4 ….||xx…|

|31331|

|3 ……| +—————+

>next4 Day: 14 Wind: all

> show fire +—————+ | …|

|x…| |….| |. ….| |. ……| +—————+

> show height +—————+ |314| | 153| |xxx x1| |xx1 31| |x 131| |5114| |5 1 1 3 3| |51 12321| +—————+

> bye bye

|2
|5 2
|5
|511 +—————+

131| 14| 1133| 2321|

> fire 0 2
Started a fire

> wind all |
Set wind to all |xxx |xx9

9 ..| x .| ..| . ..| . . | . . ..| |7. . . . ..| +—————+

> next 9 |x Day: 10 |99 Wind: all |8

Introduction to Programming

Page 13 of 14

Writing your own testcases

We have provided you with some sample testcases but these do not test all the functionality described in the assignment. It is important that you thoroughly test your code by writing your own testcases.

You should place all of your test cases in a tests/ directory. Ensure that each test case has the .in input file along with a corresponding .out output file. We recommend that the names of your test cases are descriptive so that you know what each is testing, e.g. fire.in and westwind.in

Submission details

Final deliverable for the correctness is due in week 13. Further details will be announced on Ed.
You must submit your code in the assignment page on Ed. To submit, simply place your code into the

workspace, then click the run button to check your program works and then click the submit button. You are encouraged to submit multiple times, but only your last submission will be marked.

Marking
10 marks are assigned based on automatic tests for the correctness of your program.

This component will use our own hidden test cases that cover every aspect of the specification.

Your program will be marked automatically, so make sure that you carefully follow the assignment specifications. Your program output must match the exact output shown in the examples. You are encouraged to submit your assignment while you are working on it, so you can obtain some feedback.

Warning: Anyattemptstodeceiveordisruptthemarkingsystemwillresultinanimmediatezerofor the entire assignment. Negative marks can be assigned if you do not properly follow the assignment specification, or your code is unnecessarily or deliberately obfuscated.

INFO1103

Introduction to Programming Page 14 of 14