From bd7588c0d8277a981cc8074e9aa0646bb5db711c Mon Sep 17 00:00:00 2001 From: Jonah Bauer Date: Tue, 1 Feb 2022 00:50:47 +0100 Subject: [PATCH] modularized common and core --- .../eu/jonahbauer/wizard/client/cli/.gitkeep | 0 .../client/cli/commands/ShowCommand.java | 2 +- .../wizard/client/cli/state/Game.java | 2 +- .../wizard/client/cli/util/Pair.java | 24 ------- .../client/cli/util/StateAwareFactory.java | 1 - .../src/main/resources/.gitkeep | 0 .../common/messages/client/ClientMessage.java | 2 +- .../messages/observer/ObserverMessage.java | 2 +- .../common/messages/player/PlayerMessage.java | 2 +- .../common/messages/server/ServerMessage.java | 2 +- .../util/SerializationUtil.java | 6 +- .../jonahbauer/wizard/common}/util/Pair.java | 2 +- .../wizard/common/util/StringUtil.java | 4 +- wizard-common/src/main/java/module-info.java | 23 ++++++ .../java/eu/jonahbauer/wizard/core/.gitkeep | 0 .../java/eu/jonahbauer/wizard/core/CLI.java | 72 ------------------- .../wizard/core/{machine => }/Game.java | 46 ++++++++---- .../wizard/core/{messages => }/Observer.java | 2 +- .../core/machine/states/TransientState.java | 4 -- .../core/machine/states/game/Starting.java | 22 ------ .../wizard/core/model/card/CardUtils.java | 2 +- .../core/model/card/ChangelingJesterCard.java | 2 +- .../core/model/card/ChangelingWizardCard.java | 2 +- .../wizard/core/model/card/ColoredCard.java | 2 +- .../core/model/card/ColoredSubcard.java | 2 +- .../wizard/core/model/card/GameCard.java | 2 +- .../core/model/card/NonPlayableCard.java | 2 +- .../core/{machine => }/states/GameData.java | 4 +- .../core/{machine => states}/GameState.java | 9 ++- .../states/InvalidDataException.java | 2 +- .../core/{machine => }/states/SyncState.java | 7 +- .../wizard/core/states/TransientState.java | 4 ++ .../{machine => }/states/game/Created.java | 8 +-- .../core/{machine => }/states/game/Error.java | 6 +- .../{machine => }/states/game/Finished.java | 8 +-- .../{machine => }/states/game/Finishing.java | 10 +-- .../wizard/core/states/game/Starting.java | 22 ++++++ .../states/round/ChangingPrediction.java | 12 ++-- .../{machine => }/states/round/Dealing.java | 10 +-- .../states/round/DeterminingTrump.java | 10 +-- .../round/DeterminingTrumpUserInput.java | 14 ++-- .../states/round/FinishingRound.java | 12 ++-- .../states/round/Predicting.java | 12 ++-- .../states/round/RoundState.java | 8 +-- .../states/round/StartingRound.java | 8 +-- .../states/trick/FinishingTrick.java | 18 ++--- .../{machine => }/states/trick/Juggling.java | 10 +-- .../states/trick/PlayingCard.java | 14 ++-- .../states/trick/StartingTrick.java | 8 +-- .../states/trick/TrickState.java | 8 +-- wizard-core/src/main/java/module-info.java | 8 +++ wizard-core/src/main/resources/.gitkeep | 0 .../wizard/core/{machine => }/GameTest.java | 11 +-- .../core/{machine => }/GameTestUtils.java | 4 +- .../core/{machine => }/MessageQueue.java | 6 +- .../wizard/core/model/card/CardUtilsTest.java | 2 +- .../{machine => }/states/GameStateTest.java | 3 +- .../states/round/DeterminingTrumpTest.java | 33 +++++---- .../states/round/PredictingTest.java | 33 +++++---- .../{machine => }/states/round/RoundTest.java | 27 ++++--- .../{machine => }/states/trick/TrickTest.java | 39 +++++----- .../java/eu/jonahbauer/wizard/server/.gitkeep | 0 .../eu/jonahbauer/wizard/server/Session.java | 15 ++-- 63 files changed, 288 insertions(+), 349 deletions(-) delete mode 100644 wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/.gitkeep delete mode 100644 wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/util/Pair.java delete mode 100644 wizard-client/wizard-client-cli/src/main/resources/.gitkeep rename wizard-common/src/main/java/eu/jonahbauer/wizard/common/{ => messages}/util/SerializationUtil.java (95%) rename {wizard-core/src/main/java/eu/jonahbauer/wizard/core => wizard-common/src/main/java/eu/jonahbauer/wizard/common}/util/Pair.java (91%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/util/Util.java => wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/StringUtil.java (76%) create mode 100644 wizard-common/src/main/java/module-info.java delete mode 100644 wizard-core/src/main/java/eu/jonahbauer/wizard/core/.gitkeep delete mode 100644 wizard-core/src/main/java/eu/jonahbauer/wizard/core/CLI.java rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/Game.java (61%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{messages => }/Observer.java (85%) delete mode 100644 wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/TransientState.java delete mode 100644 wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Starting.java rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/GameData.java (99%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => states}/GameState.java (90%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/InvalidDataException.java (74%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/SyncState.java (88%) create mode 100644 wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/TransientState.java rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/game/Created.java (68%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/game/Error.java (56%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/game/Finished.java (57%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/game/Finishing.java (58%) create mode 100644 wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Starting.java rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/round/ChangingPrediction.java (88%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/round/Dealing.java (81%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/round/DeterminingTrump.java (86%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/round/DeterminingTrumpUserInput.java (89%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/round/FinishingRound.java (80%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/round/Predicting.java (90%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/round/RoundState.java (61%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/round/StartingRound.java (55%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/trick/FinishingTrick.java (84%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/trick/Juggling.java (91%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/trick/PlayingCard.java (90%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/trick/StartingTrick.java (55%) rename wizard-core/src/main/java/eu/jonahbauer/wizard/core/{machine => }/states/trick/TrickState.java (62%) create mode 100644 wizard-core/src/main/java/module-info.java delete mode 100644 wizard-core/src/main/resources/.gitkeep rename wizard-core/src/test/java/eu/jonahbauer/wizard/core/{machine => }/GameTest.java (84%) rename wizard-core/src/test/java/eu/jonahbauer/wizard/core/{machine => }/GameTestUtils.java (88%) rename wizard-core/src/test/java/eu/jonahbauer/wizard/core/{machine => }/MessageQueue.java (97%) rename wizard-core/src/test/java/eu/jonahbauer/wizard/core/{machine => }/states/GameStateTest.java (90%) rename wizard-core/src/test/java/eu/jonahbauer/wizard/core/{machine => }/states/round/DeterminingTrumpTest.java (83%) rename wizard-core/src/test/java/eu/jonahbauer/wizard/core/{machine => }/states/round/PredictingTest.java (87%) rename wizard-core/src/test/java/eu/jonahbauer/wizard/core/{machine => }/states/round/RoundTest.java (92%) rename wizard-core/src/test/java/eu/jonahbauer/wizard/core/{machine => }/states/trick/TrickTest.java (90%) delete mode 100644 wizard-server/src/main/java/eu/jonahbauer/wizard/server/.gitkeep diff --git a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/.gitkeep b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/commands/ShowCommand.java b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/commands/ShowCommand.java index cf049cc..065f88b 100644 --- a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/commands/ShowCommand.java +++ b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/commands/ShowCommand.java @@ -2,8 +2,8 @@ package eu.jonahbauer.wizard.client.cli.commands; import eu.jonahbauer.wizard.client.cli.Client; import eu.jonahbauer.wizard.client.cli.state.Game; -import eu.jonahbauer.wizard.client.cli.util.Pair; import eu.jonahbauer.wizard.common.model.Card; +import eu.jonahbauer.wizard.common.util.Pair; import java.util.List; import java.util.Map; diff --git a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/state/Game.java b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/state/Game.java index 4ca3928..f3cf4fb 100644 --- a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/state/Game.java +++ b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/state/Game.java @@ -2,7 +2,6 @@ package eu.jonahbauer.wizard.client.cli.state; import eu.jonahbauer.wizard.client.cli.Client; import eu.jonahbauer.wizard.client.cli.commands.GameCommand; -import eu.jonahbauer.wizard.client.cli.util.Pair; import eu.jonahbauer.wizard.common.messages.client.InteractionMessage; import eu.jonahbauer.wizard.common.messages.data.PlayerData; import eu.jonahbauer.wizard.common.messages.observer.*; @@ -12,6 +11,7 @@ import eu.jonahbauer.wizard.common.messages.server.GameMessage; import eu.jonahbauer.wizard.common.messages.server.NackMessage; import eu.jonahbauer.wizard.common.messages.server.ServerMessage; import eu.jonahbauer.wizard.common.model.Card; +import eu.jonahbauer.wizard.common.util.Pair; import lombok.Getter; import java.time.Instant; diff --git a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/util/Pair.java b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/util/Pair.java deleted file mode 100644 index 9050e1b..0000000 --- a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/util/Pair.java +++ /dev/null @@ -1,24 +0,0 @@ -package eu.jonahbauer.wizard.client.cli.util; - -import java.util.Map; - -public record Pair(F first, S second) implements Map.Entry { - public static Pair of(F first, S second) { - return new Pair<>(first, second); - } - - @Override - public F getKey() { - return first(); - } - - @Override - public S getValue() { - return second(); - } - - @Override - public S setValue(S value) { - throw new UnsupportedOperationException(); - } -} diff --git a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/util/StateAwareFactory.java b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/util/StateAwareFactory.java index ca1553c..a634cf7 100644 --- a/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/util/StateAwareFactory.java +++ b/wizard-client/wizard-client-cli/src/main/java/eu/jonahbauer/wizard/client/cli/util/StateAwareFactory.java @@ -1,6 +1,5 @@ package eu.jonahbauer.wizard.client.cli.util; - import eu.jonahbauer.wizard.client.cli.Client; import eu.jonahbauer.wizard.client.cli.state.ClientState; import picocli.CommandLine; diff --git a/wizard-client/wizard-client-cli/src/main/resources/.gitkeep b/wizard-client/wizard-client-cli/src/main/resources/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ClientMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ClientMessage.java index 34d64e9..f0f6aad 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ClientMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/client/ClientMessage.java @@ -3,7 +3,7 @@ package eu.jonahbauer.wizard.common.messages.client; import com.fasterxml.jackson.databind.ObjectMapper; import eu.jonahbauer.wizard.common.messages.ParseException; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; -import eu.jonahbauer.wizard.common.util.SerializationUtil; +import eu.jonahbauer.wizard.common.messages.util.SerializationUtil; import lombok.EqualsAndHashCode; import lombok.SneakyThrows; diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/ObserverMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/ObserverMessage.java index e667640..71ad2b9 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/ObserverMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/observer/ObserverMessage.java @@ -2,7 +2,7 @@ package eu.jonahbauer.wizard.common.messages.observer; import com.fasterxml.jackson.databind.ObjectMapper; import eu.jonahbauer.wizard.common.messages.ParseException; -import eu.jonahbauer.wizard.common.util.SerializationUtil; +import eu.jonahbauer.wizard.common.messages.util.SerializationUtil; import lombok.EqualsAndHashCode; import lombok.SneakyThrows; diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PlayerMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PlayerMessage.java index f906231..496e427 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PlayerMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/player/PlayerMessage.java @@ -2,7 +2,7 @@ package eu.jonahbauer.wizard.common.messages.player; import com.fasterxml.jackson.databind.ObjectMapper; import eu.jonahbauer.wizard.common.messages.ParseException; -import eu.jonahbauer.wizard.common.util.SerializationUtil; +import eu.jonahbauer.wizard.common.messages.util.SerializationUtil; import lombok.EqualsAndHashCode; import lombok.SneakyThrows; diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java index ebd255e..fae219f 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/server/ServerMessage.java @@ -3,7 +3,7 @@ package eu.jonahbauer.wizard.common.messages.server; import com.fasterxml.jackson.databind.ObjectMapper; import eu.jonahbauer.wizard.common.messages.ParseException; import eu.jonahbauer.wizard.common.messages.observer.ObserverMessage; -import eu.jonahbauer.wizard.common.util.SerializationUtil; +import eu.jonahbauer.wizard.common.messages.util.SerializationUtil; import lombok.EqualsAndHashCode; import lombok.SneakyThrows; diff --git a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/SerializationUtil.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/util/SerializationUtil.java similarity index 95% rename from wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/SerializationUtil.java rename to wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/util/SerializationUtil.java index c8babeb..d147b07 100644 --- a/wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/SerializationUtil.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/messages/util/SerializationUtil.java @@ -1,4 +1,4 @@ -package eu.jonahbauer.wizard.common.util; +package eu.jonahbauer.wizard.common.messages.util; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonTypeInfo; @@ -10,10 +10,10 @@ import com.fasterxml.jackson.databind.jsontype.NamedType; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; import eu.jonahbauer.wizard.common.messages.ParseException; +import eu.jonahbauer.wizard.common.util.StringUtil; import lombok.experimental.UtilityClass; import java.lang.reflect.Modifier; -import java.util.Locale; @UtilityClass public class SerializationUtil { @@ -61,7 +61,7 @@ public class SerializationUtil { if (Modifier.isFinal(modifiers) || subclass.isSealed() && !Modifier.isAbstract(modifiers)) { var name = subclass.getSimpleName(); if (name.endsWith(suffix)) name = name.substring(0, name.length() - suffix.length()); - name = name.replaceAll("([a-z])([A-Z]+)", "$1_$2").toLowerCase(Locale.ROOT); + name = StringUtil.toSnakeCase(name); objectMapper.registerSubtypes(new NamedType(subclass, name)); } diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/util/Pair.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/Pair.java similarity index 91% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/util/Pair.java rename to wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/Pair.java index 4d2cd48..a4db3e3 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/util/Pair.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/Pair.java @@ -1,4 +1,4 @@ -package eu.jonahbauer.wizard.core.util; +package eu.jonahbauer.wizard.common.util; import java.util.Map; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/util/Util.java b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/StringUtil.java similarity index 76% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/util/Util.java rename to wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/StringUtil.java index 0d572c3..a7572ae 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/util/Util.java +++ b/wizard-common/src/main/java/eu/jonahbauer/wizard/common/util/StringUtil.java @@ -1,11 +1,11 @@ -package eu.jonahbauer.wizard.core.util; +package eu.jonahbauer.wizard.common.util; import lombok.experimental.UtilityClass; import java.util.Locale; @UtilityClass -public class Util { +public class StringUtil { public static String toSnakeCase(String str) { return str.replaceAll("([a-z])([A-Z]+)", "$1_$2").toLowerCase(Locale.ROOT); } diff --git a/wizard-common/src/main/java/module-info.java b/wizard-common/src/main/java/module-info.java new file mode 100644 index 0000000..761dacb --- /dev/null +++ b/wizard-common/src/main/java/module-info.java @@ -0,0 +1,23 @@ +module eu.jonahbauer.wizard.common { + exports eu.jonahbauer.wizard.common.machine; + exports eu.jonahbauer.wizard.common.messages; + exports eu.jonahbauer.wizard.common.messages.client; + exports eu.jonahbauer.wizard.common.messages.data; + exports eu.jonahbauer.wizard.common.messages.observer; + exports eu.jonahbauer.wizard.common.messages.player; + exports eu.jonahbauer.wizard.common.messages.server; + exports eu.jonahbauer.wizard.common.model; + exports eu.jonahbauer.wizard.common.util; + + opens eu.jonahbauer.wizard.common.messages.client to com.fasterxml.jackson.databind; + opens eu.jonahbauer.wizard.common.messages.data to com.fasterxml.jackson.databind; + opens eu.jonahbauer.wizard.common.messages.observer to com.fasterxml.jackson.databind; + opens eu.jonahbauer.wizard.common.messages.player to com.fasterxml.jackson.databind; + opens eu.jonahbauer.wizard.common.messages.server to com.fasterxml.jackson.databind; + + requires com.fasterxml.jackson.databind; + requires com.fasterxml.jackson.module.paramnames; + + requires static lombok; + requires static org.jetbrains.annotations; +} \ No newline at end of file diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/.gitkeep b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/CLI.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/CLI.java deleted file mode 100644 index 65148d0..0000000 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/CLI.java +++ /dev/null @@ -1,72 +0,0 @@ -package eu.jonahbauer.wizard.core; - -import eu.jonahbauer.wizard.common.messages.player.PickTrumpMessage; -import eu.jonahbauer.wizard.common.messages.player.PlayCardMessage; -import eu.jonahbauer.wizard.common.messages.player.PredictMessage; -import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.messages.Observer; -import eu.jonahbauer.wizard.core.model.GameConfiguration; -import eu.jonahbauer.wizard.core.model.Configurations; - -import java.util.List; -import java.util.Scanner; -import java.util.UUID; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class CLI { - public static void main(String[] args) { - GameConfiguration config = Configurations.DEFAULT; - Observer observer = (player, msg) -> System.out.println(msg); - Game game = new Game(config, observer); - var players = List.of( - UUID.randomUUID(), - UUID.randomUUID(), - UUID.randomUUID(), - UUID.randomUUID() - ); - - game.start(players); - - Scanner scanner = new Scanner(System.in); - Pattern pattern = Pattern.compile("(\\d) ([a-z]+) (.*)"); - while (scanner.hasNextLine()) { - try { - Matcher matcher = pattern.matcher(scanner.nextLine()); - if (!matcher.find()) { - System.err.println("Format is \"(\\d) ([a-z]+) (.*)\""); - continue; - } - String player = matcher.group(1); - String command = matcher.group(2); - String param = matcher.group(3); - - int id = Integer.parseInt(player); - - if (id > players.size()) { - System.err.println("ID must be between 0 and " + (players.size() - 1)); - continue; - } - - switch (command) { - case "predict" -> { - int prediction = Integer.parseInt(param); - game.onMessage(players.get(id), new PredictMessage(prediction)); - } - case "play" -> { - Card card = Card.valueOf(param); - game.onMessage(players.get(id), new PlayCardMessage(card)); - } - case "trump" -> { - Card.Suit suit = Card.Suit.valueOf(param); - game.onMessage(players.get(id), new PickTrumpMessage(suit)); - } - default -> System.err.println("Unknown command: " + command); - } - } catch (Exception e) { - System.err.println(e.getMessage()); - } - } - } -} diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/Game.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/Game.java similarity index 61% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/Game.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/Game.java index 30058c1..f089e61 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/Game.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/Game.java @@ -1,18 +1,22 @@ -package eu.jonahbauer.wizard.core.machine; +package eu.jonahbauer.wizard.core; import eu.jonahbauer.wizard.common.machine.TimeoutContext; import eu.jonahbauer.wizard.common.messages.observer.ObserverMessage; import eu.jonahbauer.wizard.common.messages.observer.StateMessage; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; -import eu.jonahbauer.wizard.core.machine.states.TransientState; -import eu.jonahbauer.wizard.core.machine.states.game.Created; -import eu.jonahbauer.wizard.core.machine.states.game.Error; -import eu.jonahbauer.wizard.core.messages.Observer; +import eu.jonahbauer.wizard.common.model.Configuration; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.TransientState; +import eu.jonahbauer.wizard.core.states.game.Created; +import eu.jonahbauer.wizard.core.states.game.Error; +import eu.jonahbauer.wizard.core.model.Configurations; import eu.jonahbauer.wizard.core.model.GameConfiguration; -import eu.jonahbauer.wizard.core.util.Util; +import eu.jonahbauer.wizard.common.util.StringUtil; import lombok.Getter; import org.jetbrains.annotations.Blocking; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; +import org.jetbrains.annotations.VisibleForTesting; import java.util.List; import java.util.Random; @@ -30,20 +34,25 @@ public final class Game extends TimeoutContext { private final CompletableFuture future = new CompletableFuture<>(); - public Game(GameConfiguration config, Observer observer) { + private Game(Random random, Configuration config, long timeout, long syncTimeout, Observer observer) { super(new Created()); - this.random = new Random(); - this.config = config; + this.random = random; + this.config = Configurations.get(config).withTimeout(timeout).withSyncTimeout(syncTimeout); this.observer = observer; } - public Game(long seed, GameConfiguration config, Observer observer) { - super(new Created()); - this.random = new Random(seed); - this.config = config; - this.observer = observer; + public Game(Configuration config, long timeout, long syncTimeout, Observer observer) { + this(new Random(), config, timeout, syncTimeout, observer); + } + + @TestOnly + public Game(long seed, Configuration config, long timeout, long syncTimeout, Observer observer) { + this(new Random(seed), config, timeout, syncTimeout, observer); } + @TestOnly + @VisibleForTesting + @SuppressWarnings("ClassEscapesDefinedScope") public void resume(GameState state) { transition(new Created(), state); } @@ -56,10 +65,17 @@ public final class Game extends TimeoutContext { execute(s -> s.onMessage(this, player, message)); } + public void onMessage(UUID player, PlayerMessage message, Runnable preHandleMessage) { + execute(s -> { + preHandleMessage.run(); + return s.onMessage(this, player, message); + }); + } + @Override protected void onTransition(GameState from, GameState to) { if (!(to instanceof TransientState)) { - notify(new StateMessage(to != null ? Util.toSnakeCase(to.getClass().getSimpleName()) : "null")); + notify(new StateMessage(to != null ? StringUtil.toSnakeCase(to.getClass().getSimpleName()) : "null")); } } diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/messages/Observer.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/Observer.java similarity index 85% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/messages/Observer.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/Observer.java index f46cfcd..5ec6764 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/messages/Observer.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/Observer.java @@ -1,4 +1,4 @@ -package eu.jonahbauer.wizard.core.messages; +package eu.jonahbauer.wizard.core; import eu.jonahbauer.wizard.common.messages.observer.ObserverMessage; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/TransientState.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/TransientState.java deleted file mode 100644 index 277db74..0000000 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/TransientState.java +++ /dev/null @@ -1,4 +0,0 @@ -package eu.jonahbauer.wizard.core.machine.states; - -public interface TransientState { -} diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Starting.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Starting.java deleted file mode 100644 index 1920225..0000000 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Starting.java +++ /dev/null @@ -1,22 +0,0 @@ -package eu.jonahbauer.wizard.core.machine.states.game; - -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.round.StartingRound; - -import java.util.Optional; - -import static eu.jonahbauer.wizard.core.machine.states.GameData.PLAYERS; - -public final class Starting extends GameState { - - public Starting(GameData data) { - super(data.require(PLAYERS)); - } - - @Override - public Optional onEnter(Game game) { - return transition(new StartingRound(getData())); - } -} diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/CardUtils.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/CardUtils.java index b08db63..6542aa5 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/CardUtils.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/CardUtils.java @@ -1,7 +1,7 @@ package eu.jonahbauer.wizard.core.model.card; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import lombok.experimental.UtilityClass; import java.util.Comparator; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ChangelingJesterCard.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ChangelingJesterCard.java index 90f4559..0202b45 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ChangelingJesterCard.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ChangelingJesterCard.java @@ -1,7 +1,7 @@ package eu.jonahbauer.wizard.core.model.card; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import java.util.List; import java.util.UUID; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ChangelingWizardCard.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ChangelingWizardCard.java index 35f30fb..64fb0e8 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ChangelingWizardCard.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ChangelingWizardCard.java @@ -1,7 +1,7 @@ package eu.jonahbauer.wizard.core.model.card; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import java.util.List; import java.util.UUID; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ColoredCard.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ColoredCard.java index b3fa807..d673946 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ColoredCard.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ColoredCard.java @@ -1,7 +1,7 @@ package eu.jonahbauer.wizard.core.model.card; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import lombok.Getter; import java.util.List; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ColoredSubcard.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ColoredSubcard.java index a09ecf0..e279758 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ColoredSubcard.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/ColoredSubcard.java @@ -1,7 +1,7 @@ package eu.jonahbauer.wizard.core.model.card; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import lombok.Getter; import java.util.List; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/GameCard.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/GameCard.java index 76ec70d..f5697fd 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/GameCard.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/GameCard.java @@ -1,7 +1,7 @@ package eu.jonahbauer.wizard.core.model.card; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.Contract; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/NonPlayableCard.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/NonPlayableCard.java index 715c6e6..26b4a4a 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/NonPlayableCard.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/model/card/NonPlayableCard.java @@ -1,7 +1,7 @@ package eu.jonahbauer.wizard.core.model.card; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import lombok.Getter; import java.util.List; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/GameData.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/GameData.java similarity index 99% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/GameData.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/GameData.java index 28adf96..b3682df 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/GameData.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/GameData.java @@ -1,7 +1,7 @@ -package eu.jonahbauer.wizard.core.machine.states; +package eu.jonahbauer.wizard.core.states; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/GameState.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/GameState.java similarity index 90% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/GameState.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/GameState.java index 23c1044..e886a15 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/GameState.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/GameState.java @@ -1,10 +1,9 @@ -package eu.jonahbauer.wizard.core.machine; +package eu.jonahbauer.wizard.core.states; import eu.jonahbauer.wizard.common.machine.TimeoutState; import eu.jonahbauer.wizard.common.messages.player.ContinueMessage; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.states.SyncState; +import eu.jonahbauer.wizard.core.Game; import lombok.Getter; import org.jetbrains.annotations.Unmodifiable; @@ -13,8 +12,8 @@ import java.util.Optional; import java.util.UUID; import java.util.function.Function; -import static eu.jonahbauer.wizard.core.machine.states.GameData.CURRENT_PLAYER; -import static eu.jonahbauer.wizard.core.machine.states.GameData.PLAYERS; +import static eu.jonahbauer.wizard.core.states.GameData.CURRENT_PLAYER; +import static eu.jonahbauer.wizard.core.states.GameData.PLAYERS; @Unmodifiable public abstract class GameState implements TimeoutState { diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/InvalidDataException.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/InvalidDataException.java similarity index 74% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/InvalidDataException.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/InvalidDataException.java index 8eb034c..afed05b 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/InvalidDataException.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/InvalidDataException.java @@ -1,4 +1,4 @@ -package eu.jonahbauer.wizard.core.machine.states; +package eu.jonahbauer.wizard.core.states; public class InvalidDataException extends RuntimeException { public InvalidDataException(String message) { diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/SyncState.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/SyncState.java similarity index 88% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/SyncState.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/SyncState.java index 38126d1..2ed8669 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/SyncState.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/SyncState.java @@ -1,11 +1,10 @@ -package eu.jonahbauer.wizard.core.machine.states; +package eu.jonahbauer.wizard.core.states; import eu.jonahbauer.wizard.common.messages.observer.TimeoutMessage; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.messages.player.ContinueMessage; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameState; +import eu.jonahbauer.wizard.core.Game; import java.util.HashSet; import java.util.Optional; @@ -14,7 +13,7 @@ import java.util.UUID; import java.util.function.Function; import static eu.jonahbauer.wizard.common.messages.observer.UserInputMessage.Action.SYNC; -import static eu.jonahbauer.wizard.core.machine.states.GameData.PLAYERS; +import static eu.jonahbauer.wizard.core.states.GameData.PLAYERS; public final class SyncState extends GameState implements TransientState { private final transient Set ready = new HashSet<>(); diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/TransientState.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/TransientState.java new file mode 100644 index 0000000..c60b176 --- /dev/null +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/TransientState.java @@ -0,0 +1,4 @@ +package eu.jonahbauer.wizard.core.states; + +public interface TransientState { +} diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Created.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Created.java similarity index 68% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Created.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Created.java index 1665e2b..91aac2f 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Created.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Created.java @@ -1,8 +1,8 @@ -package eu.jonahbauer.wizard.core.machine.states.game; +package eu.jonahbauer.wizard.core.states.game; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.GameState; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.GameState; import java.util.List; import java.util.Optional; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Error.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Error.java similarity index 56% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Error.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Error.java index d5832a9..9ae960a 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Error.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Error.java @@ -1,7 +1,7 @@ -package eu.jonahbauer.wizard.core.machine.states.game; +package eu.jonahbauer.wizard.core.states.game; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.GameData; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.GameData; import lombok.Getter; @Getter diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Finished.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Finished.java similarity index 57% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Finished.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Finished.java index 519cd68..3caeb8f 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Finished.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Finished.java @@ -1,8 +1,8 @@ -package eu.jonahbauer.wizard.core.machine.states.game; +package eu.jonahbauer.wizard.core.states.game; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.GameState; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.GameState; import java.util.Optional; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Finishing.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Finishing.java similarity index 58% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Finishing.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Finishing.java index fc00dc7..491a4ae 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/game/Finishing.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Finishing.java @@ -1,13 +1,13 @@ -package eu.jonahbauer.wizard.core.machine.states.game; +package eu.jonahbauer.wizard.core.states.game; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameState; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameState; import eu.jonahbauer.wizard.common.messages.observer.ScoreMessage; import java.util.Optional; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; public final class Finishing extends GameState { diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Starting.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Starting.java new file mode 100644 index 0000000..8e81daf --- /dev/null +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/game/Starting.java @@ -0,0 +1,22 @@ +package eu.jonahbauer.wizard.core.states.game; + +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.round.StartingRound; + +import java.util.Optional; + +import static eu.jonahbauer.wizard.core.states.GameData.PLAYERS; + +public final class Starting extends GameState { + + public Starting(GameData data) { + super(data.require(PLAYERS)); + } + + @Override + public Optional onEnter(Game game) { + return transition(new StartingRound(getData())); + } +} diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/ChangingPrediction.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/ChangingPrediction.java similarity index 88% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/ChangingPrediction.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/ChangingPrediction.java index 9244564..4832477 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/ChangingPrediction.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/ChangingPrediction.java @@ -1,14 +1,14 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; import eu.jonahbauer.wizard.common.messages.observer.PredictionMessage; import eu.jonahbauer.wizard.common.messages.observer.TimeoutMessage; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; import eu.jonahbauer.wizard.common.messages.player.PredictMessage; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.InvalidDataException; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.InvalidDataException; import java.util.HashMap; import java.util.Map; @@ -16,7 +16,7 @@ import java.util.Optional; import java.util.UUID; import static eu.jonahbauer.wizard.common.messages.observer.UserInputMessage.Action.CHANGE_PREDICTION; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; public final class ChangingPrediction extends RoundState { private transient final int oldPrediction; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/Dealing.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/Dealing.java similarity index 81% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/Dealing.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/Dealing.java index 86d8f7d..8f2cb6f 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/Dealing.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/Dealing.java @@ -1,15 +1,15 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; import eu.jonahbauer.wizard.common.messages.observer.HandMessage; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.GameState; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.GameState; import eu.jonahbauer.wizard.core.model.deck.Deck; import java.util.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; public final class Dealing extends RoundState { diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrump.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/DeterminingTrump.java similarity index 86% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrump.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/DeterminingTrump.java index 108e263..ae78d50 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrump.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/DeterminingTrump.java @@ -1,15 +1,15 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.Game; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.Game; import eu.jonahbauer.wizard.common.messages.observer.TrumpMessage; -import eu.jonahbauer.wizard.core.machine.GameState; +import eu.jonahbauer.wizard.core.states.GameState; import eu.jonahbauer.wizard.core.model.card.GameCards; import java.util.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; public final class DeterminingTrump extends RoundState { diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrumpUserInput.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/DeterminingTrumpUserInput.java similarity index 89% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrumpUserInput.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/DeterminingTrumpUserInput.java index 0c3328d..53c5e09 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrumpUserInput.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/DeterminingTrumpUserInput.java @@ -1,4 +1,4 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; import eu.jonahbauer.wizard.common.messages.observer.HandMessage; import eu.jonahbauer.wizard.common.messages.observer.TimeoutMessage; @@ -7,17 +7,17 @@ import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.messages.player.PickTrumpMessage; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.states.TransientState; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.TransientState; import org.jetbrains.annotations.NotNull; import java.util.*; import static eu.jonahbauer.wizard.common.messages.observer.UserInputMessage.Action.PICK_TRUMP; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.TRUMP_CARD; +import static eu.jonahbauer.wizard.core.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.TRUMP_CARD; public final class DeterminingTrumpUserInput extends RoundState implements TransientState { private final transient UUID player; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/FinishingRound.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/FinishingRound.java similarity index 80% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/FinishingRound.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/FinishingRound.java index 12f446d..1b79b4e 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/FinishingRound.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/FinishingRound.java @@ -1,9 +1,9 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.game.Finishing; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.game.Finishing; import eu.jonahbauer.wizard.common.messages.observer.ScoreMessage; import java.util.HashMap; @@ -11,7 +11,7 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; public final class FinishingRound extends RoundState { diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/Predicting.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/Predicting.java similarity index 90% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/Predicting.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/Predicting.java index 8c12217..e6cfb8d 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/Predicting.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/Predicting.java @@ -1,10 +1,10 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; import eu.jonahbauer.wizard.common.messages.observer.TimeoutMessage; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.trick.StartingTrick; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.trick.StartingTrick; import eu.jonahbauer.wizard.common.messages.observer.PredictionMessage; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; @@ -16,7 +16,7 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; import static eu.jonahbauer.wizard.common.messages.observer.UserInputMessage.Action.MAKE_PREDICTION; @Getter diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/RoundState.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/RoundState.java similarity index 61% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/RoundState.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/RoundState.java index b261c88..8cb2903 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/RoundState.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/RoundState.java @@ -1,11 +1,11 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.GameState; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.GameState; import java.util.UUID; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; public abstract class RoundState extends GameState { public static GameData requirements(GameData data) { diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/StartingRound.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/StartingRound.java similarity index 55% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/StartingRound.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/StartingRound.java index 08c3649..264320b 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/round/StartingRound.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/round/StartingRound.java @@ -1,8 +1,8 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.GameData; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.GameData; import java.util.Optional; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/FinishingTrick.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/FinishingTrick.java similarity index 84% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/FinishingTrick.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/FinishingTrick.java index ea8ae50..f2c7c5d 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/FinishingTrick.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/FinishingTrick.java @@ -1,19 +1,19 @@ -package eu.jonahbauer.wizard.core.machine.states.trick; +package eu.jonahbauer.wizard.core.states.trick; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.InvalidDataException; -import eu.jonahbauer.wizard.core.machine.states.round.ChangingPrediction; -import eu.jonahbauer.wizard.core.machine.states.round.FinishingRound; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.InvalidDataException; +import eu.jonahbauer.wizard.core.states.round.ChangingPrediction; +import eu.jonahbauer.wizard.core.states.round.FinishingRound; import eu.jonahbauer.wizard.common.messages.observer.TrickMessage; import eu.jonahbauer.wizard.core.model.card.*; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import java.util.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; public final class FinishingTrick extends TrickState { diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/Juggling.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/Juggling.java similarity index 91% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/Juggling.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/Juggling.java index ea64c6c..af95bac 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/Juggling.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/Juggling.java @@ -1,4 +1,4 @@ -package eu.jonahbauer.wizard.core.machine.states.trick; +package eu.jonahbauer.wizard.core.states.trick; import eu.jonahbauer.wizard.common.messages.observer.HandMessage; import eu.jonahbauer.wizard.common.messages.observer.TimeoutMessage; @@ -6,15 +6,15 @@ import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.messages.player.JuggleMessage; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.GameState; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.GameState; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import static eu.jonahbauer.wizard.common.messages.observer.UserInputMessage.Action.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; public final class Juggling extends TrickState { private final transient Map juggledCards = new ConcurrentHashMap<>(); diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/PlayingCard.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/PlayingCard.java similarity index 90% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/PlayingCard.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/PlayingCard.java index b7e87e3..721b44c 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/PlayingCard.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/PlayingCard.java @@ -1,22 +1,22 @@ -package eu.jonahbauer.wizard.core.machine.states.trick; +package eu.jonahbauer.wizard.core.states.trick; import eu.jonahbauer.wizard.common.messages.observer.TimeoutMessage; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.InvalidDataException; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.InvalidDataException; import eu.jonahbauer.wizard.common.messages.observer.CardMessage; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.messages.player.PlayCardMessage; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; import eu.jonahbauer.wizard.core.model.card.GameCards; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import org.jetbrains.annotations.NotNull; import java.util.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; import static eu.jonahbauer.wizard.common.messages.observer.UserInputMessage.Action.PLAY_CARD; public final class PlayingCard extends TrickState { diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/StartingTrick.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/StartingTrick.java similarity index 55% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/StartingTrick.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/StartingTrick.java index a37f8c5..1ea0199 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/StartingTrick.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/StartingTrick.java @@ -1,8 +1,8 @@ -package eu.jonahbauer.wizard.core.machine.states.trick; +package eu.jonahbauer.wizard.core.states.trick; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameState; -import eu.jonahbauer.wizard.core.machine.states.GameData; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.states.GameState; +import eu.jonahbauer.wizard.core.states.GameData; import java.util.Optional; diff --git a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/TrickState.java b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/TrickState.java similarity index 62% rename from wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/TrickState.java rename to wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/TrickState.java index 4102172..f5a6396 100644 --- a/wizard-core/src/main/java/eu/jonahbauer/wizard/core/machine/states/trick/TrickState.java +++ b/wizard-core/src/main/java/eu/jonahbauer/wizard/core/states/trick/TrickState.java @@ -1,9 +1,9 @@ -package eu.jonahbauer.wizard.core.machine.states.trick; +package eu.jonahbauer.wizard.core.states.trick; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.states.round.RoundState; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.round.RoundState; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.*; public abstract class TrickState extends RoundState { public static GameData requirements(GameData data) { diff --git a/wizard-core/src/main/java/module-info.java b/wizard-core/src/main/java/module-info.java new file mode 100644 index 0000000..2130caa --- /dev/null +++ b/wizard-core/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module eu.jonahbauer.wizard.core { + exports eu.jonahbauer.wizard.core; + + requires eu.jonahbauer.wizard.common; + + requires static lombok; + requires static org.jetbrains.annotations; +} \ No newline at end of file diff --git a/wizard-core/src/main/resources/.gitkeep b/wizard-core/src/main/resources/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/GameTest.java b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/GameTest.java similarity index 84% rename from wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/GameTest.java rename to wizard-core/src/test/java/eu/jonahbauer/wizard/core/GameTest.java index 670ca76..afe1674 100644 --- a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/GameTest.java +++ b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/GameTest.java @@ -1,6 +1,7 @@ -package eu.jonahbauer.wizard.core.machine; +package eu.jonahbauer.wizard.core; -import eu.jonahbauer.wizard.core.model.Configurations; +import eu.jonahbauer.wizard.common.model.Configuration; +import eu.jonahbauer.wizard.core.Game; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.RepetitionInfo; @@ -13,7 +14,7 @@ public class GameTest { public void runDefault(RepetitionInfo repetitionInfo) throws InterruptedException, ExecutionException { Game game = new Game( repetitionInfo.getCurrentRepetition(), - Configurations.DEFAULT.withTimeout(0).withSyncTimeout(0), + Configuration.DEFAULT, 0, 0, (player, msg) -> System.out.println(msg) ); var players = List.of( @@ -31,7 +32,7 @@ public class GameTest { public void runAnniversary2016(RepetitionInfo repetitionInfo) throws InterruptedException, ExecutionException { Game game = new Game( repetitionInfo.getCurrentRepetition(), - Configurations.ANNIVERSARY_2016.withTimeout(0).withSyncTimeout(0), + Configuration.ANNIVERSARY_2016, 0, 0, (player, msg) -> System.out.println(msg) ); var players = List.of( @@ -49,7 +50,7 @@ public class GameTest { public void runAnniversary2021(RepetitionInfo repetitionInfo) throws InterruptedException, ExecutionException { Game game = new Game( repetitionInfo.getCurrentRepetition(), - Configurations.ANNIVERSARY_2021.withTimeout(0).withSyncTimeout(0), + Configuration.ANNIVERSARY_2021, 0, 0, (player, msg) -> System.out.println(msg) ); var players = List.of( diff --git a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/GameTestUtils.java b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/GameTestUtils.java similarity index 88% rename from wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/GameTestUtils.java rename to wizard-core/src/test/java/eu/jonahbauer/wizard/core/GameTestUtils.java index 44dd2c3..27cecdc 100644 --- a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/GameTestUtils.java +++ b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/GameTestUtils.java @@ -1,6 +1,6 @@ -package eu.jonahbauer.wizard.core.machine; +package eu.jonahbauer.wizard.core; -import eu.jonahbauer.wizard.core.machine.states.game.Finished; +import eu.jonahbauer.wizard.core.states.game.Finished; import lombok.experimental.UtilityClass; import org.mockito.Mockito; import org.mockito.stubbing.Answer; diff --git a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/MessageQueue.java b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/MessageQueue.java similarity index 97% rename from wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/MessageQueue.java rename to wizard-core/src/test/java/eu/jonahbauer/wizard/core/MessageQueue.java index 182ec2f..aace182 100644 --- a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/MessageQueue.java +++ b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/MessageQueue.java @@ -1,11 +1,11 @@ -package eu.jonahbauer.wizard.core.machine; +package eu.jonahbauer.wizard.core; import eu.jonahbauer.wizard.common.messages.observer.ObserverMessage; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.messages.player.*; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.messages.Observer; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.GameState; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; diff --git a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/model/card/CardUtilsTest.java b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/model/card/CardUtilsTest.java index 7d7b345..54aada2 100644 --- a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/model/card/CardUtilsTest.java +++ b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/model/card/CardUtilsTest.java @@ -1,7 +1,7 @@ package eu.jonahbauer.wizard.core.model.card; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.common.util.Pair; import org.junit.jupiter.api.Test; import java.util.List; diff --git a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/GameStateTest.java b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/GameStateTest.java similarity index 90% rename from wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/GameStateTest.java rename to wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/GameStateTest.java index 6907b60..7771f58 100644 --- a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/GameStateTest.java +++ b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/GameStateTest.java @@ -1,6 +1,5 @@ -package eu.jonahbauer.wizard.core.machine.states; +package eu.jonahbauer.wizard.core.states; -import eu.jonahbauer.wizard.core.machine.GameState; import org.junit.jupiter.api.Test; import java.util.HashSet; diff --git a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrumpTest.java b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/round/DeterminingTrumpTest.java similarity index 83% rename from wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrumpTest.java rename to wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/round/DeterminingTrumpTest.java index 727dbf5..a51f4e0 100644 --- a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/round/DeterminingTrumpTest.java +++ b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/round/DeterminingTrumpTest.java @@ -1,17 +1,16 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; import eu.jonahbauer.wizard.common.messages.observer.HandMessage; import eu.jonahbauer.wizard.common.messages.observer.StateMessage; import eu.jonahbauer.wizard.common.messages.observer.TrumpMessage; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.MessageQueue; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.states.SyncState; -import eu.jonahbauer.wizard.core.machine.states.game.Finished; -import eu.jonahbauer.wizard.core.model.GameConfiguration; -import eu.jonahbauer.wizard.core.model.Configurations; +import eu.jonahbauer.wizard.common.model.Configuration; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.MessageQueue; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.SyncState; +import eu.jonahbauer.wizard.core.states.game.Finished; import lombok.SneakyThrows; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -20,9 +19,9 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import static eu.jonahbauer.wizard.core.machine.GameTestUtils.doFinish; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.TypedValue.entry; +import static eu.jonahbauer.wizard.core.GameTestUtils.doFinish; +import static eu.jonahbauer.wizard.core.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.TypedValue.entry; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -36,8 +35,8 @@ public class DeterminingTrumpTest { @SneakyThrows @SuppressWarnings("SameParameterValue") - private Game performTest(GameConfiguration configuration, int round, Map> hands, Card trumpCard, MessageQueue queue) { - Game game = spy(new Game(configuration, queue)); + private Game performTest(Configuration configuration, int round, Map> hands, Card trumpCard, MessageQueue queue) { + Game game = spy(new Game(configuration, 10 * 60 * 1000, 10 * 60 * 1000, queue)); doFinish().when(game).transition(argThat(argument -> argument instanceof SyncState && argument.getData().has(TRUMP_SUIT))); queue.setGame(game); @@ -70,7 +69,7 @@ public class DeterminingTrumpTest { // play cards in given order MessageQueue queue = new MessageQueue(); - Game game = performTest(Configurations.ANNIVERSARY_2021, 0, hands, Card.YELLOW_1, queue); + Game game = performTest(Configuration.ANNIVERSARY_2021, 0, hands, Card.YELLOW_1, queue); // validate messages InOrder order = inOrder(game); @@ -95,7 +94,7 @@ public class DeterminingTrumpTest { MessageQueue queue = new MessageQueue() .sync(players); - Game game = performTest(Configurations.ANNIVERSARY_2021, 0, hands, Card.GREEN_JESTER, queue); + Game game = performTest(Configuration.ANNIVERSARY_2021, 0, hands, Card.GREEN_JESTER, queue); // validate messages InOrder order = inOrder(game); @@ -121,7 +120,7 @@ public class DeterminingTrumpTest { .sync(players) .addPickTrump(players[0], Card.Suit.GREEN); - Game game = performTest(Configurations.ANNIVERSARY_2021, 0, hands, Card.BLUE_WIZARD, queue); + Game game = performTest(Configuration.ANNIVERSARY_2021, 0, hands, Card.BLUE_WIZARD, queue); // validate messages InOrder order = inOrder(game); @@ -149,7 +148,7 @@ public class DeterminingTrumpTest { .sync(players) .addPickTrump(players[3], Card.Suit.YELLOW); - Game game = performTest(Configurations.ANNIVERSARY_2021, 0, hands, Card.GREEN_1, queue); + Game game = performTest(Configuration.ANNIVERSARY_2021, 0, hands, Card.GREEN_1, queue); // validate messages InOrder order = inOrder(game); diff --git a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/round/PredictingTest.java b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/round/PredictingTest.java similarity index 87% rename from wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/round/PredictingTest.java rename to wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/round/PredictingTest.java index e0f92d0..2d3c461 100644 --- a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/round/PredictingTest.java +++ b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/round/PredictingTest.java @@ -1,17 +1,16 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; import eu.jonahbauer.wizard.common.messages.observer.PredictionMessage; import eu.jonahbauer.wizard.common.messages.observer.StateMessage; import eu.jonahbauer.wizard.common.messages.observer.UserInputMessage; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameTestUtils; -import eu.jonahbauer.wizard.core.machine.MessageQueue; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.states.game.Finished; -import eu.jonahbauer.wizard.core.machine.states.trick.StartingTrick; -import eu.jonahbauer.wizard.core.model.GameConfiguration; -import eu.jonahbauer.wizard.core.model.Configurations; +import eu.jonahbauer.wizard.common.model.Configuration; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.GameTestUtils; +import eu.jonahbauer.wizard.core.MessageQueue; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.game.Finished; +import eu.jonahbauer.wizard.core.states.trick.StartingTrick; import lombok.SneakyThrows; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -21,9 +20,9 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import static eu.jonahbauer.wizard.core.machine.GameTestUtils.doFinish; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.TypedValue.entry; +import static eu.jonahbauer.wizard.core.GameTestUtils.doFinish; +import static eu.jonahbauer.wizard.core.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.TypedValue.entry; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -37,7 +36,7 @@ public class PredictingTest { @SneakyThrows @SuppressWarnings("SameParameterValue") - private Game performTest(GameConfiguration configuration, int round, MessageQueue queue) { + private Game performTest(Configuration configuration, int round, MessageQueue queue) { Map> hands = Map.of( players[0], Collections.nCopies(round + 1, Card.HIDDEN), players[1], Collections.nCopies(round + 1, Card.HIDDEN), @@ -45,7 +44,7 @@ public class PredictingTest { players[3], Collections.nCopies(round + 1, Card.HIDDEN) ); - Game game = spy(new Game(configuration, queue)); + Game game = spy(new Game(configuration, 10 * 60 * 1000, 10 * 60 * 1000, queue)); doFinish().when(game).transition(any(StartingTrick.class)); queue.setGame(game); @@ -77,7 +76,7 @@ public class PredictingTest { .addPrediction(players[2], 3) .addPrediction(players[3], 0); - Game game = performTest(Configurations.ANNIVERSARY_2021, 3, queue); + Game game = performTest(Configuration.ANNIVERSARY_2021, 3, queue); // validate messages InOrder order = inOrder(game); @@ -119,7 +118,7 @@ public class PredictingTest { .addPrediction(players[3], 0) .end(); - Game game = performTest(Configurations.ANNIVERSARY_2021, 3, queue); + Game game = performTest(Configuration.ANNIVERSARY_2021, 3, queue); // validate messages InOrder order = inOrder(game); @@ -153,7 +152,7 @@ public class PredictingTest { .addPrediction(players[3], 0) .end(); - Game game = performTest(Configurations.ANNIVERSARY_2021_PM1, 3, queue); + Game game = performTest(Configuration.ANNIVERSARY_2021_PM1, 3, queue); // validate messages InOrder order = inOrder(game); diff --git a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/round/RoundTest.java b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/round/RoundTest.java similarity index 92% rename from wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/round/RoundTest.java rename to wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/round/RoundTest.java index 8965f4b..c25d097 100644 --- a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/round/RoundTest.java +++ b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/round/RoundTest.java @@ -1,13 +1,12 @@ -package eu.jonahbauer.wizard.core.machine.states.round; +package eu.jonahbauer.wizard.core.states.round; import eu.jonahbauer.wizard.common.messages.observer.*; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.MessageQueue; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.states.game.Finished; -import eu.jonahbauer.wizard.core.model.Configurations; -import eu.jonahbauer.wizard.core.model.GameConfiguration; +import eu.jonahbauer.wizard.common.model.Configuration; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.MessageQueue; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.game.Finished; import lombok.SneakyThrows; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -17,9 +16,9 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.ExecutionException; -import static eu.jonahbauer.wizard.core.machine.GameTestUtils.finish; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.TypedValue.entry; +import static eu.jonahbauer.wizard.core.GameTestUtils.finish; +import static eu.jonahbauer.wizard.core.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.TypedValue.entry; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -32,8 +31,8 @@ public class RoundTest { }; @SneakyThrows - private Game performTest(long seed, GameConfiguration configuration, int round, MessageQueue queue) { - Game game = spy(new Game(seed, configuration, queue)); + private Game performTest(long seed, Configuration configuration, int round, MessageQueue queue) { + Game game = spy(new Game(seed, configuration, 10 * 60 * 1000, 10 * 60 * 1000, queue)); doCallRealMethod().doAnswer(finish()).when(game).transition(any(StartingRound.class)); queue.setGame(game); @@ -106,7 +105,7 @@ public class RoundTest { .addCard(players[2], Card.BLUE_6); int round = 6; - Game game = performTest(0L, Configurations.DEFAULT, round, queue); + Game game = performTest(0L, Configuration.DEFAULT, round, queue); game.await(); InOrder order = inOrder(game); @@ -232,7 +231,7 @@ public class RoundTest { .end(); int round = 6; - Game game = performTest(227L, Configurations.ANNIVERSARY_2021_PM1, round, queue); + Game game = performTest(227L, Configuration.ANNIVERSARY_2021_PM1, round, queue); game.await(); InOrder order = inOrder(game); diff --git a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/trick/TrickTest.java b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/trick/TrickTest.java similarity index 90% rename from wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/trick/TrickTest.java rename to wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/trick/TrickTest.java index dec642f..d9278e5 100644 --- a/wizard-core/src/test/java/eu/jonahbauer/wizard/core/machine/states/trick/TrickTest.java +++ b/wizard-core/src/test/java/eu/jonahbauer/wizard/core/states/trick/TrickTest.java @@ -1,14 +1,13 @@ -package eu.jonahbauer.wizard.core.machine.states.trick; +package eu.jonahbauer.wizard.core.states.trick; import eu.jonahbauer.wizard.common.messages.observer.*; import eu.jonahbauer.wizard.common.model.Card; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.machine.GameTestUtils; -import eu.jonahbauer.wizard.core.machine.MessageQueue; -import eu.jonahbauer.wizard.core.machine.states.GameData; -import eu.jonahbauer.wizard.core.machine.states.round.FinishingRound; -import eu.jonahbauer.wizard.core.model.GameConfiguration; -import eu.jonahbauer.wizard.core.model.Configurations; +import eu.jonahbauer.wizard.common.model.Configuration; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.GameTestUtils; +import eu.jonahbauer.wizard.core.MessageQueue; +import eu.jonahbauer.wizard.core.states.GameData; +import eu.jonahbauer.wizard.core.states.round.FinishingRound; import lombok.SneakyThrows; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -17,10 +16,10 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import static eu.jonahbauer.wizard.core.machine.GameTestUtils.doFinish; -import static eu.jonahbauer.wizard.core.machine.GameTestUtils.finish; -import static eu.jonahbauer.wizard.core.machine.states.GameData.*; -import static eu.jonahbauer.wizard.core.machine.states.GameData.TypedValue.entry; +import static eu.jonahbauer.wizard.core.GameTestUtils.doFinish; +import static eu.jonahbauer.wizard.core.GameTestUtils.finish; +import static eu.jonahbauer.wizard.core.states.GameData.*; +import static eu.jonahbauer.wizard.core.states.GameData.TypedValue.entry; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @@ -35,8 +34,8 @@ public class TrickTest { @SneakyThrows @SuppressWarnings("SameParameterValue") - private Game performTest(GameConfiguration configuration, int round, int trick, Map> hands, Card.Suit trump, MessageQueue queue) { - Game game = spy(new Game(configuration, queue)); + private Game performTest(Configuration configuration, int round, int trick, Map> hands, Card.Suit trump, MessageQueue queue) { + Game game = spy(new Game(configuration, 10 * 60 * 1000, 10 * 60 * 1000, queue)); doCallRealMethod().doAnswer(finish()).when(game).transition(any(StartingTrick.class)); doFinish().when(game).transition(any(FinishingRound.class)); queue.setGame(game); @@ -75,7 +74,7 @@ public class TrickTest { .sync(players) .addCards(List.of(players), hands, 0); - Game game = performTest(Configurations.DEFAULT, 0, 0, hands, Card.Suit.BLUE, queue); + Game game = performTest(Configuration.DEFAULT, 0, 0, hands, Card.Suit.BLUE, queue); // validate messages InOrder order = inOrder(game); @@ -116,7 +115,7 @@ public class TrickTest { .addCard(players[3], Card.BLUE_1) .end(); - Game game = performTest(Configurations.DEFAULT, 0, 0, hands, Card.Suit.BLUE, queue); + Game game = performTest(Configuration.DEFAULT, 0, 0, hands, Card.Suit.BLUE, queue); // validate messages InOrder order = inOrder(game); @@ -159,7 +158,7 @@ public class TrickTest { .addCard(players[3], Card.BLUE_1) .addChangePrediction(players[2], 1); - Game game = performTest(Configurations.ANNIVERSARY_2021, 0, 0, hands, Card.Suit.GREEN, queue); + Game game = performTest(Configuration.ANNIVERSARY_2021, 0, 0, hands, Card.Suit.GREEN, queue); // validate messages InOrder order = inOrder(game); @@ -203,7 +202,7 @@ public class TrickTest { .addJuggle(players[3], Card.BLUE_1) .end(); - Game game = performTest(Configurations.ANNIVERSARY_2021, 1, 0, hands, Card.Suit.YELLOW, queue); + Game game = performTest(Configuration.ANNIVERSARY_2021, 1, 0, hands, Card.Suit.YELLOW, queue); // validate messages InOrder order = inOrder(game); @@ -248,7 +247,7 @@ public class TrickTest { .addCard(players[2], Card.GREEN_1) .addCard(players[3], Card.BLUE_1); - Game game = performTest(Configurations.DEFAULT, 0, 0, hands, Card.Suit.BLUE, queue); + Game game = performTest(Configuration.DEFAULT, 0, 0, hands, Card.Suit.BLUE, queue); // validate messages InOrder order = inOrder(game); @@ -290,7 +289,7 @@ public class TrickTest { .addCard(players[2], Card.GREEN_WIZARD) .addCard(players[3], Card.BLUE_1); - Game game = performTest(Configurations.DEFAULT, 0, 0, hands, Card.Suit.BLUE, queue); + Game game = performTest(Configuration.DEFAULT, 0, 0, hands, Card.Suit.BLUE, queue); // validate messages InOrder order = inOrder(game); diff --git a/wizard-server/src/main/java/eu/jonahbauer/wizard/server/.gitkeep b/wizard-server/src/main/java/eu/jonahbauer/wizard/server/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/wizard-server/src/main/java/eu/jonahbauer/wizard/server/Session.java b/wizard-server/src/main/java/eu/jonahbauer/wizard/server/Session.java index 406f40e..f98b8d6 100644 --- a/wizard-server/src/main/java/eu/jonahbauer/wizard/server/Session.java +++ b/wizard-server/src/main/java/eu/jonahbauer/wizard/server/Session.java @@ -8,10 +8,9 @@ import eu.jonahbauer.wizard.common.messages.player.ContinueMessage; import eu.jonahbauer.wizard.common.messages.player.PlayerMessage; import eu.jonahbauer.wizard.common.messages.server.*; import eu.jonahbauer.wizard.common.model.Configuration; -import eu.jonahbauer.wizard.core.machine.Game; -import eu.jonahbauer.wizard.core.messages.Observer; -import eu.jonahbauer.wizard.core.model.Configurations; -import eu.jonahbauer.wizard.core.util.Pair; +import eu.jonahbauer.wizard.core.Game; +import eu.jonahbauer.wizard.core.Observer; +import eu.jonahbauer.wizard.common.util.Pair; import eu.jonahbauer.wizard.server.machine.Player; import eu.jonahbauer.wizard.server.management.SessionMBean; import lombok.AccessLevel; @@ -169,11 +168,7 @@ public class Session implements Observer, SessionMBean { throw new NackException(NackMessage.GAME_NOT_YET_STARTED, "Game hat not yet started."); } else { try { - game.execute(s -> { - // start buffering while game is locked - player.buffer(); - return s.onMessage(game, uuid, message); - }); + game.onMessage(uuid, message, player::buffer); player.send(new AckMessage()); } catch (IllegalStateException e) { throw new NackException(NackMessage.ILLEGAL_STATE, e.getMessage()); @@ -186,7 +181,7 @@ public class Session implements Observer, SessionMBean { protected void startGame() { notifyPlayers(new StartingGameMessage()); messages.add(Pair.of(null, new StartingGameMessage())); - game = new Game(Configurations.get(configuration).withTimeout(timeout), this); + game = new Game(configuration, timeout, 10 * 60 * 1000, this); game.start(List.copyOf(players.keySet())); CompletableFuture.runAsync(() -> { while (true) {