Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with java program, the task is break up a floor plan into rooms that are no smaller than 3 by 3 using recursion.

Need help with java program, the task is break up a floor plan into rooms that are no smaller than 3 by 3 using recursion.
Okay, so hear me out: I want to design layouts for the floor plans of buildings, but I also want to express my appreciation
for Piet Mondrian and neoplasticism! This means I need to divide up the floors of a building, but I wont be going for the
traditional hallways and functional workplace approaches (because those are boring).
Lets look at a couple quick examples:
Here, youll see that weve broken the floors up into arbitrarily-separated rooms. As noted above theres no hallways, but
theres still the ability to travel from anywhere on the floor to anywhere else.
The principle is actually pretty simple:
We treat the available space on a floor as effectively a grid of cells
That grid may have arbitrary granularity (hence the two examples above: same dimensions; different cell sizes)
The grid does not include the walls; instead the walls are boundaries between spaces
We start with initially one large room
Any given room may be split up into two rooms, with a door along the newly-added wall separating them
Since its recursive, those two rooms may themselves each be split up into two... you get the idea
A wider room will be split horizontally by a vertical wall, a taller room will be split vertically by a horizontal
wall. Since theres no compelling reason to pick either for a square room, well just say that also gets split
horizontally by a vertical wall
Well get to the cut-off(stopping point) a bit further down
Lets walk through a couple of the first steps to start one:
Here, weve decided to divide our space into 16\times 16 spaces. As its a square, well favour a vertical line. We have 15
possible positions for a wall (between any two cells). Just for ha-has, lets start with the middle?
Here you can see weve added the door (depicted as a gap for now) roughly of the way up.
We would then recurse onto both of these rooms.
The left room is taller, so we split it vertically with a horizontal wall:
(The colours and letters are just for easier reference)
Notice that:
The doors may be placed anywhere along the wall, so long as theyre within the grid boundaries, and always one
space
Though we can further and further subdivide A/B, well eventually need to return to C to split it up too
Well eventually run out of spaces for further subdivisions (and doors)
Because doors are cut into newly-added walls, well never need to touch a wall again after its creation
So, whats left? Sooner or later, theyll all be divided enough. e.g.:
Were still missing three things: doors, the cutoff for when to stop dividing, and the Piet Mondrian part.
Doors are easy; we couldve been doing them the whole time: when installing a wall and leaving a gap, simply make
an orange line instead of the gap
The cutoff is relatively simple: allow for a cutoff value where a room having either dimension at or below that value
will never be further divided; also include some probability to stop even sooner than that. When testing, below 3 is
a nice cutoff to try using, along with a quitting proclivity of ~5%
This doesnt mean its impossible for a room to have e.g. a height of 2: a room 20 tall could be divided into one
of 18 and one of 2(or even one of 19 and one of 1!)
Some of the final room-floors will have their floor painted a random colour
This will occur with some probability, to be decided specifically when a room will no longer be further divided
Overall, it seems pretty doable, right? Or maybe not? This task is specifically designed to require significant planning
before coding.
Some basic requirements are included, but as always: this is a continuation from COSC1P03(and also 1P02). Youre
expected to know basic standards. If not, ask.
Basic requirements:
First and foremost: this is a recursive algorithm. It must be done recursively, with recursion
It must also be done correctly with recursion. e.g. dont be peppering instance variables about, willy-nilly. Thats
objectively bad. Instead, remember that parameters are a thing!
Some closely-related values need to be defined. e.g. the width and height of the floor, both in pixels and in cells;
but also the size of a cell, and the number of cells in each direction. Some of those will be calculated from the others
Let the user select the non-calculated ones. To be clear: this doesnt mean let the user edit/fix your code,
recompile, and do all the actual work
All UI elements are based on the Brock library you used for 1P02/1P03. To ensure were on

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Theory And Applications 27th Australasian Database Conference Adc 20 Sydney Nsw September 28 29 20 Proceedings Lncs 9877

Authors: Muhammad Aamir Cheema ,Wenjie Zhang ,Lijun Chang

1st Edition

3319469215, 978-3319469218

More Books

Students also viewed these Databases questions