Answered step by step
Verified Expert Solution
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 by 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 arbitrarilyseparated 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 newlyadded 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 cutoffstopping 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 times spaces. As its a square, well favour a vertical line. We have
possible positions for a wall between any two cells Just for hahas 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 AB 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 newlyadded walls, well never need to touch a wall again after its creation
So whats left? Sooner or later, theyll all be divided enough eg:
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 is
a nice cutoff to try using, along with a quitting proclivity of ~
This doesnt mean its impossible for a room to have eg a height of : a room tall could be divided into one
of and one of or even one of and one of
Some of the final roomfloors 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 COSCPand also P 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. eg dont be peppering instance variables about, willynilly. Thats
objectively bad. Instead, remember that parameters are a thing!
Some closelyrelated values need to be defined. eg 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 noncalculated ones. To be clear: this doesnt mean let the user editfix your code,
recompile, and do all the actual work
All UI elements are based on the Brock library you used for PP To ensure were on
Step 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