mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
289 server (#308) Incremental server update, with working tournament and player input timeout
* Server update with new dev changes (#305) * merge widgets with development * readd previous game thread code * Revert "readd previous game thread code" This reverts commitd24feef73e. * Revert "Merge remote-tracking branch 'origin/Development' into Development" This reverts commit59d46cb73c, reversing changes made to38681c5db0. * Revert "merge widgets with development" This reverts commit38681c5db0. * Merge 292 into development (#293) Applied template method pattern to abstract player * Added documentation to player classes and improved method names (#295) * mcts v1 * bitboard optimization * bitboard fix & mcts v2 & mcts v3. v3 still in progress and v4 coming soon * main --------- Co-authored-by: ramollia <> Co-authored-by: Stef <stbuwalda@gmail.com> Co-authored-by: Stef <48526421+StefBuwalda@users.noreply.github.com> * Hotfix for stuff * Logging and fixed user input getting stuck * Fixed merge mistakes * Working tournament * GlobalEventBus is now async instead * Shuffle now changeable, host can now switch tournament gametype * Tournament results are now send back to the clients connected to the server * Tournament now returns result to clients * Refactored tournament to use interfaces and builders * Removed unnecessary imports * Tournament refactor for better naming and easier to understand code * Starting a tournament now requires to be admin * Request admin list * Added admins to games * Tournament is now without admins * Added result comeback with a draw * Async tournament runner * Added back ability to shuffle matchmaker * Moved scoring calculation into scoring system * Tournament now uses propper builder pattern * Null handling * Removed input mistake, removed print * Refactored Tournament to use matchExecutor and ResultBroadcaster. Added turnTime and players are now added through Tournament creation instead of on MatchMaker/ScoreSystem creation * Added shuffle to builder * Removed unnecessary throw * More adaptable scoring system * Moved async runner to virtual thread * Timeout added * AI player given time change --------- Co-authored-by: Stef <stbuwalda@gmail.com> Co-authored-by: Stef <48526421+StefBuwalda@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
94e3fc71b8
commit
d078a70950
@@ -11,6 +11,7 @@ import org.toop.app.widget.popup.ErrorPopup;
|
||||
import org.toop.app.widget.popup.SendChallengePopup;
|
||||
import org.toop.app.widget.view.ServerView;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.game.players.ArtificialPlayer;
|
||||
import org.toop.framework.game.players.OnlinePlayer;
|
||||
import org.toop.framework.gameFramework.controller.GameController;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
@@ -20,8 +21,10 @@ import org.toop.framework.networking.connection.events.NetworkEvents;
|
||||
import org.toop.framework.networking.connection.types.NetworkingConnector;
|
||||
import org.toop.framework.networking.server.gateway.NettyGatewayServer;
|
||||
import org.toop.framework.game.players.LocalPlayer;
|
||||
import org.toop.game.players.ai.MCTSAI3;
|
||||
import org.toop.local.AppContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -117,7 +120,8 @@ public final class Server {
|
||||
return;
|
||||
}
|
||||
|
||||
primary = new ServerView(user, this::sendChallenge, clientId);
|
||||
primary = new ServerView(user, this::sendChallenge, user, clientId);
|
||||
|
||||
WidgetContainer.getCurrentView().transitionNextCustom(primary, "disconnect", this::disconnect);
|
||||
|
||||
a.unsubscribe("connecting");
|
||||
@@ -159,7 +163,8 @@ public final class Server {
|
||||
.listen(NetworkEvents.GameResultResponse.class, this::handleGameResult, false, "game-result")
|
||||
.listen(NetworkEvents.GameMoveResponse.class, this::handleReceivedMove, false, "game-move")
|
||||
.listen(NetworkEvents.YourTurnResponse.class, this::handleYourTurn, false, "your-turn")
|
||||
.listen(NetworkEvents.ClosedConnection.class, this::closedConnection, false, "closed-connection");
|
||||
.listen(NetworkEvents.ClosedConnection.class, this::closedConnection, false, "closed-connection")
|
||||
.listen(NetworkEvents.TournamentResultResponse.class, this::handleTournamentResult, false, "tournament-result");
|
||||
|
||||
connectFlow = a;
|
||||
}
|
||||
@@ -205,7 +210,8 @@ public final class Server {
|
||||
information.players[opponentStartingTurn].name = response.opponent();
|
||||
|
||||
Player[] players = new Player[2];
|
||||
players[userStartingTurn] = new LocalPlayer(user);
|
||||
|
||||
players[userStartingTurn] = new ArtificialPlayer(new MCTSAI3(1000), user);
|
||||
players[opponentStartingTurn] = new OnlinePlayer(response.opponent());
|
||||
|
||||
switch (type) {
|
||||
@@ -238,6 +244,13 @@ public final class Server {
|
||||
gameController.gameFinished(response);
|
||||
}
|
||||
|
||||
private void handleTournamentResult(NetworkEvents.TournamentResultResponse response) {
|
||||
IO.println(response.gameType());
|
||||
IO.println(Arrays.toString(response.names()));
|
||||
IO.println(Arrays.toString(response.scoreTypes()));
|
||||
IO.println(Arrays.toString(response.scores().toArray()));
|
||||
}
|
||||
|
||||
private void handleReceivedMove(NetworkEvents.GameMoveResponse response) {
|
||||
if (gameController == null) {
|
||||
return;
|
||||
@@ -337,7 +350,8 @@ public final class Server {
|
||||
|
||||
private void gamesListFromServerHandler(NetworkEvents.GamelistResponse event) {
|
||||
gameList.clear();
|
||||
var gl = List.of(event.gamelist());
|
||||
var gl = new java.util.ArrayList<>(List.of(event.gamelist()));
|
||||
gl.sort(String::compareTo);
|
||||
gameList.addAll(gl);
|
||||
primary.updateGameList(gl);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ import javafx.scene.control.ComboBox;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.complex.ViewWidget;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
@@ -15,6 +17,7 @@ import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ListView;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.eventbus.GlobalEventBus;
|
||||
import org.toop.framework.networking.connection.events.NetworkEvents;
|
||||
|
||||
public final class ServerView extends ViewWidget {
|
||||
@@ -22,46 +25,65 @@ public final class ServerView extends ViewWidget {
|
||||
private final Consumer<String> onPlayerClicked;
|
||||
private final long clientId;
|
||||
|
||||
private final ComboBox<String> gameList;
|
||||
private final ComboBox<String> gameListSub;
|
||||
private final ComboBox<String> gameListTour;
|
||||
private final ListView<Button> listView;
|
||||
private Button subscribeButton;
|
||||
|
||||
public ServerView(String user, Consumer<String> onPlayerClicked, long clientId) {
|
||||
public ServerView(String user, Consumer<String> onPlayerClicked, String userName, long clientId) {
|
||||
this.user = user;
|
||||
this.onPlayerClicked = onPlayerClicked;
|
||||
this.clientId = clientId;
|
||||
|
||||
this.gameList = new ComboBox<>();
|
||||
this.gameListSub = new ComboBox<>();
|
||||
this.gameListTour = new ComboBox<>();
|
||||
this.listView = new ListView<>();
|
||||
|
||||
setupLayout();
|
||||
setupLayout(userName);
|
||||
}
|
||||
|
||||
private void setupLayout() {
|
||||
private void setupLayout(String userName) {
|
||||
var playerHeader = Primitive.header(user, false);
|
||||
|
||||
subscribeButton = Primitive.button(
|
||||
"subscribe",
|
||||
() -> new EventFlow().addPostEvent(new NetworkEvents.SendSubscribe(clientId, gameList.getValue())).postEvent(),
|
||||
false,
|
||||
true
|
||||
); // TODO localize
|
||||
if (userName.equals("host")) { // TODO is fragile
|
||||
var tournamentButton = Primitive.hbox(
|
||||
gameListTour,
|
||||
Primitive.button(
|
||||
"tournament",
|
||||
() -> GlobalEventBus.get().post(new NetworkEvents.SendCommand(clientId, "tournament", "start", gameListTour.getValue())),
|
||||
false,
|
||||
false
|
||||
)
|
||||
);
|
||||
|
||||
var subscribe = Primitive.hbox(gameList, subscribeButton);
|
||||
add(Pos.BOTTOM_CENTER, tournamentButton);
|
||||
} else {
|
||||
subscribeButton = Primitive.button(
|
||||
"subscribe",
|
||||
() -> new EventFlow().addPostEvent(new NetworkEvents.SendSubscribe(clientId, gameListSub.getValue())).postEvent(),
|
||||
false,
|
||||
true
|
||||
); // TODO localize
|
||||
|
||||
var playerListSection = Primitive.vbox(
|
||||
playerHeader,
|
||||
Primitive.separator(),
|
||||
subscribe,
|
||||
listView
|
||||
);
|
||||
var subscribe = Primitive.hbox(gameListSub, subscribeButton);
|
||||
|
||||
add(Pos.CENTER, playerListSection);
|
||||
var playerListSection = Primitive.vbox(
|
||||
playerHeader,
|
||||
Primitive.separator(),
|
||||
subscribe,
|
||||
listView
|
||||
);
|
||||
|
||||
var disconnectButton = Primitive.button(
|
||||
"disconnect", () -> transitionPrevious(), false);
|
||||
add(Pos.CENTER, playerListSection);
|
||||
|
||||
add(Pos.BOTTOM_LEFT, Primitive.vbox(disconnectButton));
|
||||
var disconnectButton = Primitive.button(
|
||||
"disconnect",
|
||||
this::transitionPrevious,
|
||||
false
|
||||
);
|
||||
|
||||
add(Pos.BOTTOM_LEFT, Primitive.vbox(disconnectButton));
|
||||
}
|
||||
}
|
||||
|
||||
public void update(List<String> players) {
|
||||
@@ -77,9 +99,13 @@ public final class ServerView extends ViewWidget {
|
||||
|
||||
public void updateGameList(List<String> games) {
|
||||
Platform.runLater(() -> {
|
||||
gameList.getItems().clear();
|
||||
gameList.setItems(FXCollections.observableArrayList(games));
|
||||
gameList.getSelectionModel().select(0);
|
||||
gameListSub.getItems().clear();
|
||||
gameListSub.setItems(FXCollections.observableArrayList(games));
|
||||
gameListSub.getSelectionModel().select(0);
|
||||
|
||||
gameListTour.getItems().clear();
|
||||
gameListTour.setItems(FXCollections.observableArrayList(games));
|
||||
gameListTour.getSelectionModel().select(0);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user