Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't rotate the player assigned to the role 'random' when generating… #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/main/java/org/ggp/base/apps/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,38 @@ public void actionPerformed(ActionEvent evt) {
thePlayers.add(playerSelector.getPlayerPresence(name));
}

StateMachine stateMachine = new ProverStateMachine();
stateMachine.initialize(theGame.getRules());
List<Role> roles = stateMachine.getRoles();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Role#computeRoles for this.

int randomPlayerIndex = -1;
PlayerPresence randomPlayer = null;
for (int i = 0; i < roles.size(); i++) {
if (roles.get(i).getName().toString().toLowerCase().equals("random")) {
randomPlayerIndex = i;
randomPlayer = thePlayers.get(i);
break;
}
}

synchronized (scheduler) {
for (int i = 0; i < (Integer)repetitionsSpinner.getValue(); i++) {
scheduler.addPendingMatch(new PendingMatch("Base", theGame, new ArrayList<PlayerPresence>(thePlayers), -1, startClock, playClock, shouldScramble.isSelected(), shouldQueue.isSelected(), shouldDetail.isSelected(), shouldSave.isSelected(), shouldPublish.isSelected()));
thePlayers.add(thePlayers.remove(0)); // rotate player roster for repeated matches
scheduler.addPendingMatch(
new PendingMatch("Base", theGame, new ArrayList<PlayerPresence>(thePlayers), -1,
startClock, playClock, shouldScramble.isSelected(),
shouldQueue.isSelected(), shouldDetail.isSelected(),
shouldSave.isSelected(), shouldPublish.isSelected()));

if (randomPlayerIndex == -1) {
// there is no random player
thePlayers.add(thePlayers.remove(0)); // rotate player roster for repeated matches
}
else {
// there is a player assigned to the 'random' role so don't rotate that player when you rotate the other players for repeated matches
thePlayers.remove(randomPlayerIndex);
thePlayers.add(thePlayers.remove(0)); // rotate non-random player roster for repeated matches
thePlayers.add(randomPlayerIndex, randomPlayer); // put the random player back in
}

try {
Thread.sleep(10);
} catch (InterruptedException ie) {
Expand Down