代写Theory and Practice – CSSE7610 – Semester 2, 2025 Assignment Two帮做Java编程

Assignment Two 25%

Concurrency:  Theory and Practice CSSE7610 Semester 2, 2025

Due: 4pm on Friday October 24 (Week 12)

Summary

The objective of this assignment is to explore a concurrent card game.  As part of this assignment, you will design concurrent algorithms, prove and validate different properties both manually and mechanically via TLA+.  Then, you will implement the card game in Java.

Scary Warnings

You should read this specification in its entirety. There are some aspects that will catch you out if not. For example, Section 4 has some critical information on expectations for referencing your code, details on some required files you must submit, and a list of penalties that can be applied to your assignment solution. Please be aware.

0 Speed

“Speed” is a real-time card game (as opposed to a turn-based game) where players (processors) interact via a shared state: four piles of cards.

Setup. Create a hand containing 5 cards for each of two players P and Q, and call these handP  and handQ.  Create a private deck of 15 cards for each player, and call these drawP and drawQ. Create two initial discard decks; a left and a right deck, and call these discardL and discardR . Each discard deck begins with just one card. Create two pickup decks of 5 cards on the left and right, and call these pickupL  and pickupR .

Assume pick(n) randomly draws n cards that are not currently in use.

handP  ← pick(5);       handQ  ← pick(5);        drawP  ← pick(15);    drawQ  ← pick(15);

discardL  ← pick(1);   discardR  ← pick(1);    pickupL  ← pick(5);   pickupR  ← pick(5);

Objective. The first player to empty both their hand and draw pile wins.

Rules.

1. If a player has a card in their hand with a value one greater or less than the top of either discard pile (discardL  or discardR ), they may transfer that card to that pile.

2. If a player has less than 5 cards in their hand, they must draw from their respective draw pile (drawP  or drawQ ).

3. If both players can not make one of the above moves, the players simultaneously draw a card from different pickup piles and play the card on the corresponding discard deck.

discardL.push(pickupL.pop())  ||  discardR.push(pickupR.pop())

4. Once the pickup piles are depleted, the discard and pickup piles are shuffled and re-dealt such that the discard piles have 1 card each and the pickup piles have an even (if odd, one pile will have exactly one more than the other) split of the remaining cards.

Tasks

In this assignment you will:

1. Design a monitor to enable safe concurrent game play.

a. Prove safety and liveness properties of the monitor.

b. Provide an example of live locking.

2. Model the monitor in TLA+.

3. Implement a Java simulation of the game.

a. Implement a blocking monitor based Java implementation.

b. (Bonus) Implement a non-blocking Java implementation.

1 Speed Monitor

Algorithm S below contains a partial implementation of a game of speed.

You can assume that the function canPlay(card, top) exists and returns true if card can be played on top of the card top.

Task 1. Complete the implementation of the Speed monitor according to the rules above.

Task 2. We want to ensure that the following two properties hold:

Safety: The sequence of cards in each discard deck is valid (according to canPlay(card, top)). Liveness: The player will always eventually make a move while the game is not finished.

Express these properties as formulas and prove that they hold for your monitor specification.

Task 3. Provide an example scenario where a live lock may occur.

Deliverable: A file speed.pdf containing your the completed Speed monitor, a proof of the above properties, and your livelock scenario. Include your name and student number at the top.

2 TLA+ Specification

Translate your monitor specification into a PlusCal algorithm in TLA+. You may use the provided macros and procedures to express your algorithm. Direct translation will cause a state space explosion. Your specification must model the game play more abstractly. Some examples of abstractions you can make include (but are not limited to):

1. Model only one discard and one pickup pile.

2. Decide non-deterministically a) whether a card can be played and b) which card to play. Do not model the card playing rules of the game. You may find the TLA+ either and with constructs useful.

3. You may reduce the size of the decks.

Use your specification to show that the algorithm

1. does not deadlock,

2. preserves mutual exclusion within the monitor, and

3. that both processes progress.

You may make other simplifications to the specification as long as the behaviour relevant to the desired properties above are preserved.

Deliverable:  A file speed .tla containing the TLA+ specification.  The algorithm must be specified by Spec, and safety and liveness properties should be specified by Safety and Liveness respectively. You should use commenting to describe the abstraction made to the algorithm and justify that it is safe. Again, ensure your name and student number are at the top.

3 Speed in Java

Implement your algorithm for the speed card game in Java.  You should first implement the algorithm using the Java monitor pattern.  Your Java implementation should match your algorithm from Part 1 as closely as possible while maintaining correctness using Java’s monitor implementation.

Your implementation must implement the provided ISpeed interface:

public interface ISpeed { void setListener ( EventListener listener ) ; void play ( String name , Set < Card > hand , Stack < Card > drawPile ) ; }

To record that a game event has occurred, you must call the appropriate method on the EventListener interface.

public interface SpeedEventListener { void cannotPlay ( String player ) ; void playCard ( String player , Card card , Side side ) ; void win ( String player ) ; void shuffle () ; void flip () ; }

3.1    Super Speed (Bonus)

A monitor implementation of speed requires synchronization; one process must obtain a lock before playing a card. This is a blocking solution. Implement a non-blocking implementation of speed, called super speed, that preserves the correctness.  Note that only playing cards from player hands to the discard pile should be non-blocking. Determining when to flip the pickup piles into the discard pile requires synchronization but this must be implemented without using a synchronized method.

4 Assessment

This section briefly describes how your assignment will be assessed.

Mark Allocation

Marks will be provided based on the correctness and readability of your answers to all questions.

Part One (8 marks)

◆   Monitor implementation                                                                                         (4 marks)

◆   Proof of safety                                                                                                          (1 mark)

◆   Proof of liveness                                                                                                     (2 mark)

◆   Livelock scenario                                                                                                    (1 mark)

Part Two (9 marks)

◆  TLA+ specification                                                                                                 (3 marks)

◆  Abstraction of algorithm                                                                                        (2 marks)

◆   Specification of non-determinism                                                                         (2 marks)

◆   Proof of mutual exclusion                                                                                        (1 mark)

◆   Proof of progression                                                                                               (1 mark)

Part Three (8 marks + 4 bonus)

◆  Java speed implementation                                                                                   (8 marks)

◆  Java super speed implementation                                                               (4 bonus marks)

Penalties Penalties will be computed and removed from your overall final mark as follows:

◆   If your code does not adhere to good style principles (such as those shown in the guide provided on the Blackboard (Course  Resources  >  Java  Resources), you will lose 2 marks;

◆   If your submission does not include the statement .txt file, or if the statement is empty, you will lose 25 marks, no exceptions – see the instructions regarding the statement below.

Plagiarism and Generative AI

If you want to actually learn something in this course, our recommendation is that you avoid using Generative AI tools: You need to think about what you are doing, and why, in order to put the theory (what we talk about in the lectures and tutorials) into practical knowledge that you can use, and this is often what makes things “click” when learning.  Mindlessly lifting code from an AI engine won’t teach you how to solve problems, and if you’re not caught here, you’ll be caught soon enough by prospective employers.

If you are still tempted, note that we will be running your assignments through sophistic- ated software similarity checking systems against a number of samples including including your classmates and our own solutions (including a number that have been developed with AI assistance). If we believe you may have used AI extensively in your solution, you may be called in for an interview to walk through your code.  Note also that the final exam may contain questions or scenarios derived from those presented in the assignment work, so cheating could weaken your chances of successfully passing the exam.

AI Statement As part of your submission, you must submit a text file statement .txt that provides attribution to any sources or tools used to help you with your assignment, including any prompts provided to AI tooling. If you did not use any such tooling, you can make a statement outlining that fact. Failing to submit this file, or submitting an empty file, will result in a 25 mark penalty.

Please refer to the referencing guide for assessments located in the “Assessment” tab on Blackboard for more information.

Interviews We will be conducting assignment interviews, where a subset of students will be invited to walk through their assignment submission with a member of staff. Your final assignment score will be weighted according to your demonstrated understanding of your submission, where the weight will be assigned in the range [0.0, 1.0]. Note that students who are not selected for interviews will have this weight set to 1.0 by default. For example:

◆   Student A scores 18 marks. They are not interviewed. Their final score remains at 18 marks.

◆   Student B scores 12 marks.  They are interviewed, and they are judged to have a full understanding of their submission giving them a weighting of 1.0, resulting in 12 marks.

◆   Student C scores 19 marks. They are interviewed, and they are judged to have a mostly complete understanding of their submission, but are lacking understanding of some parts of their algorithms, giving them a weighting of 0.75.  This means their final mark is 0.75 × 19 = 14.25.

Students may be selected for an interview according to their reported AI usage (or lack thereof) as noted in their statement file, their assignment similarity with other students and/or AI generated solutions, their mark as compared to their past performance, or totally randomly.

Submission Information

You need to submit your solution to Gradescope under the Assignment 2 link  in your dashboard. The easiest way to submit your solution is to submit a  .zip file. As described earlier, your zip file should contain the following files:

◆   speed.pdf – Part 1.

◆   speed .tla – Part 2.

◆   src/ – A subdirectory containing all code and the README for Part 3.

◆   statement .txt – The AI/reference statement.





热门主题

课程名

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
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图