mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Added back ability to shuffle matchmaker
This commit is contained in:
@@ -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.*;
|
||||||
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.shufflers.RandomShuffle;
|
||||||
import org.toop.framework.utils.ImmutablePair;
|
import org.toop.framework.utils.ImmutablePair;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -284,7 +285,7 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTournament(String gameType, NettyClient requestor) {
|
public void startTournament(String gameType, NettyClient requestor, boolean shuffle) {
|
||||||
if (!admins.contains(requestor)) {
|
if (!admins.contains(requestor)) {
|
||||||
requestor.send("ERR you do not have the privileges to start a tournament");
|
requestor.send("ERR you do not have the privileges to start a tournament");
|
||||||
return;
|
return;
|
||||||
@@ -293,10 +294,15 @@ public class Server implements GameServer<TurnBasedGame, NettyClient, Long> {
|
|||||||
var tournamentUsers = new ArrayList<>(onlineUsers());
|
var tournamentUsers = new ArrayList<>(onlineUsers());
|
||||||
tournamentUsers.removeIf(admins::contains);
|
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(
|
Tournament tournament = new BasicTournament(new TournamentBuilder(
|
||||||
this,
|
this,
|
||||||
new AsyncTournamentRunner(),
|
new AsyncTournamentRunner(),
|
||||||
new RoundRobinMatchMaker(tournamentUsers),
|
matchMaker,
|
||||||
new BasicScoreSystem(tournamentUsers)
|
new BasicScoreSystem(tournamentUsers)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class MessageHandler implements Handler<ParsedMessage> {
|
|||||||
if(!hasArgs(p.args())) return;
|
if(!hasArgs(p.args())) return;
|
||||||
|
|
||||||
if (p.args()[0].equalsIgnoreCase("start") && p.args().length > 1) {
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.client.NettyClient;
|
||||||
import org.toop.framework.networking.server.tournaments.TournamentMatch;
|
import org.toop.framework.networking.server.tournaments.TournamentMatch;
|
||||||
|
import org.toop.framework.networking.server.tournaments.shufflers.Shuffler;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface MatchMaker extends Iterable<TournamentMatch> {
|
public interface MatchMaker extends Iterable<TournamentMatch> {
|
||||||
List<NettyClient> getPlayers();
|
List<NettyClient> getPlayers();
|
||||||
|
void shuffle(Shuffler shuffler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.client.NettyClient;
|
||||||
import org.toop.framework.networking.server.tournaments.TournamentMatch;
|
import org.toop.framework.networking.server.tournaments.TournamentMatch;
|
||||||
|
import org.toop.framework.networking.server.tournaments.shufflers.Shuffler;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -15,6 +16,11 @@ public class RoundRobinMatchMaker implements MatchMaker {
|
|||||||
this.players = players;
|
this.players = players;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void shuffle(Shuffler shuffler) {
|
||||||
|
shuffler.shuffle(players);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<NettyClient> getPlayers() {
|
public List<NettyClient> getPlayers() {
|
||||||
return players;
|
return players;
|
||||||
|
|||||||
Reference in New Issue
Block a user