Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Semaphore seats;
- static Semaphore semph;
- static int counter;
- static Semaphore playable;
- static Semaphore finished;
- public static void init() {
- seats = new Semaphore(6);
- semph = new Semaphore(1);
- counter = 0;
- playable = new Semaphore(0);
- finished = new Semaphore(0);
- }
- public static class Player extends TemplateThread {
- public Player(int numRuns) {
- super(numRuns);
- }
- @Override
- public void execute() throws InterruptedException {
- seats.acquire();
- state.playerSeat();
- semph.acquire();
- counter++;
- if(counter==6) {
- semph.release();
- state.dealCards();
- playable.release(5);
- state.play();
- finished.acquire(5);
- counter = 0;
- state.endRound();
- seats.release(6);
- } else {
- semph.release();
- playable.acquire();
- state.play();
- finished.release();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement