Starting from:
$30

$24

Homework 1-Claw Machine

Description






























In the store there is one claw machine with good prizes therefore dozens of people want to give it a try. Assume that there are infinite prizes in the machine, and every customer takes the same time (assume = a time unit) to manipulate the machine once, we call it a ‘​round​’. While the machine is being used, others have to line up in sequential order. If a customer gets his own chance, he would play a few rounds in a row to try to win the prize. If he fails, he will leave the machine to other customers, get some rest and come back a certain time later; Otherwise, he will leave with his prize happily and will not come back again.

Assume that every customer has his own first arrive time, continuously play round number, rest time, and total play round number ​N​.​Acustomer will successfully get his prize on the Nth round he has played.

There is a guarantee system in the claw machine – ​the guarantee number G​.It means that if no one gets the prize for continuous n playing times, the number n will be always less than G. Remember that the guarantee number counter will be reset when anyone gets the prize, whether by achieving G or N.

Your goal is to use multi-threads to present the behavior of customers and claw machine.

Advanced(40%)

There are ​two machines​in the store, named #1 and #2, share one common G. If one come to the store with both machines are idle, he will randomly choose one to play. When any customer achieve G while both machines are being used, ​only he ​will get prize and leave. Notice that when both machines are being used, the guarantee number counter will be count twice in a round.




Requirement

    • Use multithreads to present the behavior of customers and claw machine

    • Read file as input and output the result in a correct format

requirement detail:

Input format

<the guarantee number G>

<total number of customers>

<customer1 arrive time><continuously play round><rest time><total play round number N> <customer2 arrive time><continuously play round><rest time><total play round number N>


ex:

15

3

0333

25310

4239

Output format

<time> <customer ID> <movement> (<get prize or not>)



ex:

0 1 start playing

2 2 start playing

3 1 finish playing YES



<time>: all integer, we will not use unusual number as test data

<movement>: ​start playing/finish playing/wait in line​,you only need to output these three kinds of movement
<get prize or not>: ​YES/NO​,you have to output the result after movement finish playing
Advanced Output format:

<time> <customer ID> <movement> (<get prize or not>)<machine ID> <machine ID>: ​#1/#2
ex:

0 1 start palying #1

2 2 start playing #2

...




Hint

    • For both input and output file, all information on the same line are separated by one space digit.

    • The test data may not have unique result. Every correct result is acceptable.

    • The time unit is ‘​round​’.




Grade

    • 60% - base part

    • 40% - advanced part

    • Copy will get 0 point






Submit

Please upload a zip file called “hw1_{$student_id}.zip” that includes your source code.

Submission that don’t follow the rule will get 20% punishment on the grade.

If you have any problem, please contact TA Wei-Wen Chen kxc0079@gmail.com

More products