Added back ability to shuffle matchmaker

This commit is contained in:
Bas de Jong
2026-01-11 01:54:40 +01:00
parent 013dd90705
commit 955cb6109c
4 changed files with 17 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ import org.toop.framework.networking.server.stores.TurnBasedGameTypeStore;
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.shufflers.RandomShuffle;
import org.toop.framework.utils.ImmutablePair;
import java.util.*;
@@ -284,7 +285,7 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
return true;
}
public void startTournament(String gameType, NettyClient requestor) {
public void startTournament(String gameType, NettyClient requestor, boolean shuffle) {
if (!admins.contains(requestor)) {
requestor.send("ERR you do not have the privileges to start a tournament");
return;
@@ -293,10 +294,15 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
var tournamentUsers = new ArrayList<>(onlineUsers());
tournamentUsers.removeIf(admins::contains);
var matchMaker = new RoundRobinMatchMaker(tournamentUsers);
if (shuffle) {
matchMaker.shuffle(new RandomShuffle()); // Remove if not wanting to shuffle
}
Tournament tournament = new BasicTournament(new TournamentBuilder(
this,
new AsyncTournamentRunner(),
new RoundRobinMatchMaker(tournamentUsers),
matchMaker,
new BasicScoreSystem(tournamentUsers)
));

View File

@@ -119,7 +119,7 @@ public class MessageHandler implements Handler<ParsedMessage> {
if(!hasArgs(p.args())) return;
if (p.args()[0].equalsIgnoreCase("start") && p.args().length > 1) {
server.startTournament(p.args()[1], client);
server.startTournament(p.args()[1], client, false); // TODO add shuffle to msg
}
}
}

View File

@@ -2,9 +2,11 @@ package org.toop.framework.networking.server.tournaments.matchmakers;
import org.toop.framework.networking.server.client.NettyClient;
import org.toop.framework.networking.server.tournaments.TournamentMatch;
import org.toop.framework.networking.server.tournaments.shufflers.Shuffler;
import java.util.List;
public interface MatchMaker extends Iterable<TournamentMatch> {
List<NettyClient> getPlayers();
void shuffle(Shuffler shuffler);
}

View File

@@ -2,6 +2,7 @@ package org.toop.framework.networking.server.tournaments.matchmakers;
import org.toop.framework.networking.server.client.NettyClient;
import org.toop.framework.networking.server.tournaments.TournamentMatch;
import org.toop.framework.networking.server.tournaments.shufflers.Shuffler;
import java.util.Iterator;
import java.util.List;
@@ -15,6 +16,11 @@ public class RoundRobinMatchMaker implements MatchMaker {
this.players = players;
}
@Override
public void shuffle(Shuffler shuffler) {
shuffler.shuffle(players);
}
@Override
public List<NettyClient> getPlayers() {
return players;