mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Added shuffle to builder
This commit is contained in:
@@ -14,6 +14,7 @@ import org.toop.framework.networking.server.tournaments.*;
|
||||
import org.toop.framework.networking.server.tournaments.matchmakers.RoundRobinMatchMaker;
|
||||
import org.toop.framework.networking.server.tournaments.scoresystems.BasicScoreSystem;
|
||||
import org.toop.framework.networking.server.tournaments.scoresystems.IntegerScoreSystem;
|
||||
import org.toop.framework.networking.server.tournaments.shufflers.RandomShuffle;
|
||||
import org.toop.framework.utils.ImmutablePair;
|
||||
|
||||
import java.util.*;
|
||||
@@ -300,9 +301,10 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
|
||||
.matchMaker(new RoundRobinMatchMaker())
|
||||
.scoreSystem(new BasicScoreSystem())
|
||||
.resultBroadcaster(this::endTournament)
|
||||
.turnTimeout(Duration.ofSeconds(5))
|
||||
.turnTimeout(Duration.ofSeconds(10))
|
||||
.addPlayers(tournamentUsers.toArray(NettyClient[]::new))
|
||||
.addAdmins(admins.toArray(NettyClient[]::new))
|
||||
.addMatchShuffler(new RandomShuffle())
|
||||
.build();
|
||||
|
||||
new Thread(() -> tournament.run(gameType)).start();
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.toop.framework.networking.server.MatchExecutor;
|
||||
import org.toop.framework.networking.server.client.NettyClient;
|
||||
import org.toop.framework.networking.server.tournaments.matchmakers.MatchMaker;
|
||||
import org.toop.framework.networking.server.tournaments.scoresystems.IntegerScoreSystem;
|
||||
import org.toop.framework.networking.server.tournaments.shufflers.Shuffler;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
@@ -18,6 +19,7 @@ public class Tournament {
|
||||
private final ResultBroadcaster<IntegerScoreSystem> broadcaster;
|
||||
private final NettyClient[] players;
|
||||
private final Duration turnTime;
|
||||
private final Shuffler shuffler;
|
||||
|
||||
private Tournament(Tournament.Builder builder) {
|
||||
matchExecutor = builder.matchExecutor;
|
||||
@@ -27,6 +29,7 @@ public class Tournament {
|
||||
broadcaster = builder.broadcaster;
|
||||
players = builder.players;
|
||||
turnTime = builder.turnTime;
|
||||
shuffler = builder.shuffler;
|
||||
}
|
||||
|
||||
public void run(String gameType) throws IllegalArgumentException {
|
||||
@@ -36,6 +39,8 @@ public class Tournament {
|
||||
scoreSystem.addPlayer(e);
|
||||
});
|
||||
|
||||
if (shuffler != null) matchMaker.shuffle(shuffler);
|
||||
|
||||
tournamentRunner.run(matchExecutor, matchMaker, scoreSystem, broadcaster, turnTime, gameType);
|
||||
|
||||
}
|
||||
@@ -50,6 +55,7 @@ public class Tournament {
|
||||
private NettyClient[] observors;
|
||||
private NettyClient[] admins;
|
||||
private Duration turnTime = Duration.ofSeconds(10);
|
||||
private Shuffler shuffler;
|
||||
|
||||
public Builder matchExecutor(MatchExecutor matchExecutor) {
|
||||
this.matchExecutor = matchExecutor;
|
||||
@@ -96,6 +102,11 @@ public class Tournament {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addMatchShuffler(Shuffler shuffler) {
|
||||
this.shuffler = shuffler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Tournament build() {
|
||||
Objects.requireNonNull(matchExecutor, "matchExecutor");
|
||||
Objects.requireNonNull(scoreSystem, "scoreSystem");
|
||||
|
||||
Reference in New Issue
Block a user