首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
讲解CIT594编程、辅导java程序、java编程辅导 辅导Python编程|解析R语言编程
项目预算:
开发周期:
发布时间:
要求地区:
HW4: Blocky
Learning goals
Topics: Spatial Data Structures/QuadTree, Recursive data structures, Tree Search,
Algorithm analysis, Testing
By the end of this assignment, you should be able to:
• Model hierarchical and spatial data using trees
• Implement recursive operations on trees (both non-mutating and mutating)
• Convert a tree into a flat, two-dimensional structure
• Explain and perform runtime analysis of the code you wrote
Introduction: The Blocky game
Blocky is a game with simple moves on a simple structure, but like a Rubik’s Cube, it is quite
challenging to play. The game is played on a randomly-generated game board made of squares of
different colors, such as this:
The goal of the game called Perimeter goal is to put the most possible units of a given color c on
the outer perimeter of the board. The player’s score is the total number of unit cells of color c
that are on the perimeter. There is a premium on corner cells: they count twice towards the score.
After each move, the player sees their score, determined by how well they have achieved their
goal. The game continues for a certain number of turns or until the user runs out of moves (in
this assignment, we will allow an unlimited number of moves).
Now let’s look in more detail at the rules of the game and the different ways it can be configured
for play.
The Blocky board
We call the game board a ‘block’. It is best defined recursively. A block is either:
• a square of one color, or
• a square that is subdivided into 4 equal-sized blocks.
The largest block of all, containing the whole structure, is called the top-level block. We say that
the top-level block is at level 0. If the top-level block is subdivided, we say that its four subblocks
are at level 1. More generally, if a block at level k is subdivided, its four sub-blocks are at
level k+1.
A Blocky board has a maximum allowed depth, which is the number of levels down it can go.
A board with maximum allowed depth 0 would not be fun to play on – it couldn’t be subdivided
beyond the top level, meaning that it would be of one solid color.
This board was generated with a maximum depth of 2:
This board was generated with a maximum depth of 3:
This board was generated with a maximum depth of 4:
As you can see the deeper the board the more blocks you might have.
For simplicity, we recommend limiting the maximum depth to 3 or 4.
For scoring, the units of measure are squares the size of the blocks at the maximum allowed
depth. We will call these blocks unit cells.
Choosing a block and levels
The moves that can be made are things like rotating clockwise a block. What makes moves
interesting is that they can be applied to any block at any level. For example, if the user selects
the entire top-level block for this board:
and chooses to rotate it, the resulting board is this:
But if instead, on the original board, they rotated the block with id 3 (at level 1) (one level down
from the top-level block) in the bottom right-hand corner, the resulting board is this:
Of course, there are many other blocks within the board at various levels that the player could
have chosen.
Moves
These are the moves that are allowed on a Blocky board:
• Rotate the selected block (90 degrees) clockwise. Implemented in Block.java
• Swap two blocks (and their sub-blocks if any). Implemented in Game.java
• Smash the selected block, giving it four new, randomly generated sub-blocks. Smashing
the top-level block is not allowed – that would be creating a whole new game. And
smashing a unit cell is also not allowed since it's already at the maximum allowed depth.
Implemented in Block.java
Goals and scoring
At the beginning of the game, the player is assigned a target color for the perimeter goal.
Perimeter goal:
The player must aim to put the most possible blocks of a given target color c on the outer
perimeter of the board. The player’s score is the total number of cells of color c that are on the
perimeter. There is a premium on corner cells: they count twice towards the score.
Players
This version of Blocky is single player.
Configurations of the game
A Blocky game can be configured in several ways:
• Maximum allowed depth.
While the specific color pattern for the board is randomly generated, we control how
finely subdivided the squares can be.
• Target color.
Setup and starter code
Please download the starter code files. Do not forget to test your code as you implement your
solution.
Task 1: Understand the Block data structure and the Game class
Surprise, surprise: we will use a tree (QuadTree) to represent the nested structure of a block. Our
trees will have some very strong restrictions on their structure and contents, however. For
example, a node cannot have 3 children. This is because a block is either solid-colored or
subdivided; if it is solid-colored, it is represented by a node with no children, and if it is
subdivided, it is subdivided into exactly four subblocks.
How are the blocks numbered?
The blocks are numbered using a breadth-first traversal. The image below shows the mapping
of quadtree nodes to blocks ids. The maximum depth of this blocky game is 3:
Open the IBlock interface. Read through the class documentation carefully.
Create a Block class that will implement IBlock. The Block class has quite a few attributes
to understand. The attributes are listed in the IBlock documentation. You must name your data
fields exactly as they are named in IBlock’s documentation (bullet listed).
Open the IGame interface. Read through the class documentation carefully. The Game class
represents an instance of the Blocky game. It creates and maintains the Quadtree. The Game
class performs the swap operation and computes the score of the player.
1. Open Block.java and implement the constructor and the attributes’ accessors and
mutators.
2. Manually draw (construct) the Block data structure corresponding to the game board
below, assuming the maximum depth was 2 (and notice that it was indeed reached). In
this assignment, we will assume that the top-level block’s top-left point is at (0,0)
and its bottom-right point is at (8, 8).
Use the TestBlocky class to check your code. Comment out the lines raising errors as
we have not yet implemented Game. To display the Block data structure, add it to the
GameFrame instance (using the addQuad method) and call display().
Task 2: Initialize the game
With a good understanding of the data structure, you are ready to implement the Game and the
Block classes.
1. Open Block.java and implement the smash() method. Verify that smash randomly
assign colors to subblocks.
2. Now that we have the smash method ready, we can generate random boards. This is what
function random_init is for.
3. Create a Game.java class that implements IGame.java. Implement the constructor and
random_init. The method is outside the Block class because it doesn’t need to refer to a
specific Block.
Here is the strategy to use in random_init: If a Block is not yet at its maximum depth, it
can be subdivided; this function must decide whether or not to do so. To decide:
o Use the function Math.random to generate a random number to randomly select a
Block in the tree.
o Subdivide if the Block at the random index is not already at max_depth.
o If a Block is not going to be subdivided (smashed), use a random integer to pick a
color for it from the list of colors in IBlocks.COLORS.
Notice that the randomly generated Block may not reach its maximum allowed depth. It
all depends on what random numbers are generated.
Check your work: Use TestBlocky.java to confirm that your smash() and random_init()
methods work correctly.
Task 3: Complete the Block class
Implement the rest of the methods in the Block class
Check your work: Thoroughly test your Block class and use TestBlocky.java to verify that your
implementation is correct. Name your test class BlockTest.java
Task 4: Complete Game class
Now we have enough pieces to assemble a rudimentary game!
Implement all the methods in Game.java except for flatten() and perimeter_score.
Check your work: Thoroughly test your Game class and use TestBlocky.java to verify that
your implementation is correct. Name your test class GameTest.java
At the end of Task 4, you should have a functioning game without the scores.
Task 5: Implement scoring for perimeter goal
Now let’s get scoring working.
The unit we use when scoring against a goal is a unit cell. The size of a unit cell depends on the
maximum depth in the Block. For example, with a maximum depth of 4, we might get this
board:
If you count down through the levels, you'll see that the smallest blocks are at level 4. Those
blocks are unit cells. It would be possible to generate that same board even if the maximum
depth was 5. In that case, the unit cells would be one size smaller, even though no Block has
been divided to that level.
Notice that the perimeter may include unit cells of the target color as well as larger blocks of that
color. For a larger block, only the unit-cell-sized portions on the perimeter count. For example,
suppose maximum depth was 3, the target color was red, and the board was in this state:
Only the red blocks on the edge would contribute, and the score would be 4: one for each of the
two unit cells on the right edge, and two for the unit cells inside the larger red block that are
actually on the edge. (Notice that the larger red block isn’t divided into four unit cells, but we
still score as if it were.)
Remember that corner cells count twice towards the score. So, if the player rotated the lower
right block to put the big red block on the corner:
the score would rise to 6.
Now that we understand these details of scoring for a perimeter goal, we can implement it.
1. It is very difficult to compute a score for a perimeter goal through the tree structure.
(Think about that!) The goal is much more easily assessed by walking through a twodimensional
representation of the game board. Your next task is to provide that
possibility: In the Game class, define the method flatten.
2. Now implement the perimeter_score method in class Game to truly calculate the score.
Begin by flattening the board to make your job easier!
Check your work: Now when you play the game, you should see the score changing. Check to
confirm that it is changing correctly.
Polish!
Take some time to polish up. This step will improve your mark, but it also feels so good. Here
are some things you can do:
• Pay attention to style and documentation warnings raised by the IDE. Fix them!
• Read through and polish your internal comments.
• Remove any code you added just for debugging, such as print statements.
• Remove the word “TODO” wherever you have completed the task.
• Take pride in your gorgeous code!
Grading: The assignment is worth 212 points
Description Points
Autograder Tests 130
Algorithm Analysis Document 12
Testing: Point.java, Block.java, Game.java 50 (90% code coverage for full credit)
Documentation/Style 15
Readme file 5
This Assignment was adapted by Eric Fouh, it was originally developed by Diane Horton and
David Liu.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
urba6006代写、java/c++编程语...
2024-12-26
代做program、代写python编程语...
2024-12-26
代写dts207tc、sql编程语言代做
2024-12-25
cs209a代做、java程序设计代写
2024-12-25
cs305程序代做、代写python程序...
2024-12-25
代写csc1001、代做python设计程...
2024-12-24
代写practice test preparatio...
2024-12-24
代写bre2031 – environmental...
2024-12-24
代写ece5550: applied kalman ...
2024-12-24
代做conmgnt 7049 – measurem...
2024-12-24
代写ece3700j introduction to...
2024-12-24
代做adad9311 designing the e...
2024-12-24
代做comp5618 - applied cyber...
2024-12-24
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!