首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
讲解data编程、辅导java程序设计、Java编程调试 调试Matlab程序|辅导Python编程
项目预算:
开发周期:
发布时间:
要求地区:
Project 1
Due Date: Tuesday, November 17
THE KING IS DEAD, LONG LIVE THE KING!!!!
A castle starts with a certain number of defense points (number of defense points is
explained later in the ELSE IF section). If the castle defense value ever goes to <= 0, the
castle falls. There are G gates to a castle. For each entrance there are S free spaces.
The number of spaces is equal to the number of people that can hold the gate closed on
one side and equal to the number of people trying to break through the gate on the other
side.
Villagers have gotten angry at the sudden increase in taxes the King has set. They have
breached the outer castle walls and have taken over the armory. The attackers will, in
FCFS (first come first served) order, take a weapon from the armory and be assigned an
attack random integer value between 1 and 10 at the time the weapon is obtained.
(Note: Have the attackers block on the same object – armory). The defenders of the
castle can be assigned this value at runtime because they are already armed.
Upon receiving a weapon an attacker will head towards a gate and prepare to attack
(Note: In the beginning every attacker/defender searches for the least attacked/defended
gate to help out his friends. That is, an attacker compares every gates’ attackers and
picks the gate with the least attackers). No thread should be allowed to get to any of the
gates that are fully occupied. If no space to defend/attack is available at any gate, then
defenders/attackers just wait for free space. (Note: attackers/defenders wait in the order
of their arrival (FCFS). Use similar code to rwcv.java. Each attacker/defender gets an
object to wait on in that data structure - vectors). Upon arrival at the gate, the attacker
will wait for all of the defenders to arrive at the appropriate gate.
Likewise, the defenders will each choose a gate and wait for all of the attackers to arrive
at their gate.
Note: use the Gate as an object that both defenders and attackers will wait on. For each
gate there is an object named “Gate”.
Once all of the defenders and attackers are at the appropriate gate the battle can began.
The combined attack/defend values will be compared with the following conditions
below. The last thread to arrive at a gate notifies all waiting threads on the gate. While
the last thread will also execute sumUpAtackersDefendersValues() and do the
comparisons, the other threads will wait for the result on one object.
We will name a group of attackers/defenders gathered on a gate – company.
There may be other companies of threads that just finished attacking/defending and
want to do the comparison too. Make sure that multiple companies can do comparison
concurrently at company level but comparison is still synchronized within the same
company. You should use some identification for the same company (for example,
timestamp all company threads and assign company gate number, timestamp+gate#
would serve as unique id for company; each thread would carry that id within itself).
When a company is done with the comparison their gate status is either breached or
open for the king to try to escape (if attack/defend values matched, gate is as it was
before the siege began). Once the comparison is done and the threads start notifying
their respective reserve threads(first on line) and then rest. After rest they join the
reserves themselves.
IF:
Total defend value > total attack value: attackers are overwhelmed by defenders and
the gate is considered clear of attackers.
The King is a very sneaky person, when a gate is cleared of attackers, he will try to
escape. First he will need to gather his precious belongings and get ready. The King will
use the wait(long) method instead of the sleep method to simulate the packing time. If an
attacker arrives during this time, then the King will be signaled on the monitor wait(long)
and will retreat back into the castle.
If the gate at which the King is escaping through doesn’t have a new attacker when the
escape time elapses, then the King has succeeded in escaping and the attackers lose.
The time the king takes to get ready should be some factor less than the time an
attacker takes to rest.
Whenever an attacker that is coming to the siege sees a gate that was cleared of his
fellow attackers, he will try to attack that gate first. As soon as that attacker gets to that
gate, the defenders barricade it once more and the king has to wait for another
opportunity.
ELSE IF:
Total attack value > total defend value: attackers overwhelm defenders.
There's a number which represents the total castle defense. It is equal to the sum of
every single defender’s defense value. When attackers breach a gate, the sum of their
attack value is subtracted from the total castle defense (For example, if we have 100
defenders, their defense variable’s sum may equal 500, which means the castle’s
defense is also 500. If several attackers (with a total attack value of 50) breach one of
the gates, then the castle defense value is down to 450.)
Those attackers that were able to breach the gate and the defenders that failed to
protect the gate start attacking/defending again from the beginning. (Essentially, their
threads run in an infinite while (true) loop).
ELSE:
the battle is postponed.
If the castle’s defense value is at or below 0, the defenders lose.
---------------------------------------------------------------------------------------------------------------------
Develop a monitor(s) that will synchronize the threads (defenders, attackers, king) in the
context of the story described below. Closely follow the details of the story and the
synchronization requirements.
You can create any other methods/objects you may need. Make sure that any shared
variable/structure is accessed in a mutual exclusion fashion.
The number of attackers, defenders, gates to the castle, and free spaces for each
entrance can be read as command line arguments using the following format where a =
attackers, d = defenders, G = castle gates and S = free spaces:
Note that all command line arguments are optional. If they are not provided at run time,
your program should default to:
G*S+4 attackers, G*S+4 defenders; where G=3, and S=2.
Do NOT use busy waiting. If a thread needs to wait, it must wait on an object (class
object or notification object).
Use only basic monitors as the ones discussed in class (synchronized methods,
synchronized blocks, wait(), notify and notifyAll). Wait(long timeout) should be use once
only. NO other synchronization tools like locks, concurrent collections…..or even volatile
variables.
Use the age( ) method and appropriate println statements to show how synchronization
works. It is important to have print statements before, inside, and after critical events.
State clearly what the current thread executing the print statement is doing. Also, be
sure to include the name of the thread and a timestamp relative to the start time of the
program.
Suggestions:
The King’s thread should call
Method by which he’s waiting for the opportunity of escaping
Method by which he’s packing belongings.
Method by which he checks for a safe escape (if an attacker arrives during
that time the king should retreat back into the castle).
Attackers/Defenders call Castle’s methods:
Method(s) to find a defending/attacking position
or wait until all spaces are filled with attackers/defenders on both sides of the
gate
attack()/defend() should be simulated by sleep. Make sure that you give info
about the name of the thread and gate.
A method that will compute the attackers or defenders value
Between major events make sure you insert a sleep of random time. Also make sure
you give the information necessary to understand what that event is.
Choose the appropriate amount of time(s) that will agree with the content of the story. I
haven’t written the code for this project yet, but from the experience of grading previous
semesters’ projects, a project should take somewhere between 50 seconds and at most
2 minutes to run and complete. Set the time in such way that you don’t create only
exceptional situations.
Do not submit any code that does not compile and run. If there are parts of the code that
contain bugs, comment it out and leave the code in. A program that does not compile
nor run will not be graded.
Follow the story closely and cover the requirements of the project’s description. Besides
the synchronization details provided there are other synchronization aspects that need to
be covered. You can use synchronized methods or additional synchronized blocks to
make sure that mutual exclusion over shared variables is satisfied.
The Main class is run by the main thread. The other threads must be specified by either
implementing the Runnable interface or extending the Thread class. Separate the
classes into separate files. Do not leave all the classes in one file. Create a class for
each type of thread.
Add the following lines to all the threads you make:
public static long time = System.currentTimeMillis();
public void msg(String m) {
System.out.println("["+(System.currentTimeMillis()-time)+"] "+getName()+": "+m);
}
There should be printout messages indicating the execution interleaving. Whenever you
want to print something from that thread use: msg("some message here");
NAME YOUR THREADS or the above lines that were added would mean nothing.
Here's how the constructors could look like (you may use any variant of this as long as
each thread is unique and distinguishable):
// Default constructor
public RandomThread(int id) {
setName("RandomThread-" + id);
}
Design an OOP program. All thread-related tasks must be specified in their respective
classes, no class body should be empty.
DO NOT USE System.exit(0); the threads are supposed to terminate naturally by
running to the end of their run methods.
Javadoc is not required. Proper basic commenting explaining the program flow, selfexplanatory
variable names, correct whitespace and indentations are required.
Name your project as follows: LASTNAME_FIRSTNAME_CSXXX_PY
where LASTNAME is your last name, FIRSTNAME is your first name, XXX is your
course, and Y is the current project number.
For example: Fluture_Simina_CS344_p1
zip only the source files. Upload the project on BlackBoard.
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做 program、代写 c++设计程...
2024-12-23
comp2012j 代写、代做 java 设...
2024-12-23
代做 data 编程、代写 python/...
2024-12-23
代做en.553.413-613 applied s...
2024-12-23
代做steady-state analvsis代做...
2024-12-23
代写photo essay of a deciduo...
2024-12-23
代写gpa analyzer调试c/c++语言
2024-12-23
代做comp 330 (fall 2024): as...
2024-12-23
代写pstat 160a fall 2024 - a...
2024-12-23
代做pstat 160a: stochastic p...
2024-12-23
代做7ssgn110 environmental d...
2024-12-23
代做compsci 4039 programming...
2024-12-23
代做lab exercise 8: dictiona...
2024-12-23
热点标签
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
软件定制开发网!