finished ex Z4

This commit is contained in:
2025-01-20 23:52:55 +01:00
parent 886bf5a1cd
commit fd3af32c7c
3 changed files with 83 additions and 29 deletions

View File

@@ -30,16 +30,27 @@ public class Bidder implements Runnable {
if (state == BIDDING) {
Random rand = new Random();
double addon = rand.nextDouble(500);
double base = auctioneer.getMaximumBid().amount();
Bid maximumBid = auctioneer.getMaximumBid();
double base = maximumBid == null ? 0 : maximumBid.amount();
lastBid = base + addon;
auctioneer.placeBid(new Bid(this, lastBid));
long minSleep = (long) (base * 10);
try {
Utils.randomSleep(100, 5000);
Utils.randomSleep(minSleep, minSleep + 1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} else if (state == FINISHED) {
break;
} else {
auctioneer.stateLock.lock();
try {
auctioneer.stateCond.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
auctioneer.stateLock.unlock();
}
}
}
}