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