package uulm.teamname.marvelous.gamelibrary.gamelogic; import net.jqwik.api.*; import org.junit.jupiter.api.Test; import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.json.config.CharacterConfig; import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig; import uulm.teamname.marvelous.gamelibrary.json.config.ScenarioConfig; import uulm.teamname.marvelous.gamelibrary.requests.*; import java.util.ArrayList; import java.util.List; class GameLogicTest { @Test void executeRequest() { GameState state = new GameState(new PartyConfig(), new CharacterConfig(), new ScenarioConfig()); //build a nice state (add entities and stuff) ArrayList result = GameLogic.executeRequest(state, new RequestBuilder(RequestType.MeleeAttackRequest) //build a nice request to check //.withOriginEntity() .buildCharacterRequest()); //check if result contains the right events } @Test void buildGameStateEvent() { } @Test void checkRequest() { } @Test void applyEvent() { } @Test void checkWinConditions() { } // @Provide("gamestate") // Arbitrary gamestate() { // var states = Arbitraries.integers() // .tuple2() // .map(x -> new IntVector2(x.get1(), x.get2())) // .map(GameState::new); // } // @Provide("entityManager") // Arbitrary entityManager() { // var managers = Arbitraries.of(EntityManager.class); // // } // @Provide("entity") // Arbitrary entity() { // var entities = Arbitraries.of(Entity.class); // } // Characters are kind of hard, but most prequisites are here // @Provide("character") // Arbitrary character() { // var characters = Combinators.combine( // anyStat(), // Arbitraries.integers() // ).as(x -> new Character()); // } @Provide("stat") Arbitrary anyStat() { var stats = Combinators.combine( Arbitraries.of(StatType.class), Arbitraries.integers()) .as(Stat::new); return Combinators.combine(stats, Arbitraries.integers().greaterOrEqual(0)) .as((stat, decrease) -> { stat.decreaseValue(decrease % (stat.getMax() + 1)); return stat; }); } @Provide("entityIDs") Arbitrary entityIDs() { return Combinators.combine( Arbitraries.of(EntityType.class), Arbitraries.integers() ).as((type, id) -> { EntityID eid; switch (type) { case NPC -> eid = new EntityID(type, id % 3); case P1, P2, InfinityStones -> eid = new EntityID(type, id % 6); case Rocks -> eid = new EntityID(type, id); default -> throw new IllegalStateException("Unexpected value: " + type); } return eid; }); } @Provide("positions") Arbitrary positions() { return Arbitraries.integers() .greaterOrEqual(0) .tuple2() .map(x -> new IntVector2(x.get1(), x.get2())); } @Provide("requests") Arbitrary requests() { return Combinators.combine( Arbitraries.of(true, false), gameRequests(), characterRequests()) .as((which, gameRequest, characterRequest) -> which ? gameRequest : characterRequest); } @Provide("gameRequests") Arbitrary gameRequests() { final var gameRequestTypes = List.of( RequestType.PauseStopRequest, RequestType.PauseStartRequest, RequestType.EndRoundRequest, RequestType.DisconnectRequest, RequestType.Req); return Arbitraries.of(RequestType.class) .filter(gameRequestTypes::contains) .map(x -> new RequestBuilder(x).buildGameRequest()); } @Provide("characterRequests") Arbitrary characterRequests() { final var characterRequestTypes = List.of( RequestType.MeleeAttackRequest, RequestType.RangedAttackRequest, RequestType.MoveRequest, RequestType.ExchangeInfinityStoneRequest, RequestType.UseInfinityStoneRequest); var positions = Arbitraries.integers() .greaterOrEqual(0) .tuple2() .map(x -> new IntVector2(x.get1(), x.get2())); var characterIDs = Combinators.combine(Arbitraries.of(true, false) .map(x -> x ? EntityType.P1 : EntityType.P2), Arbitraries.integers() .between(0, 5)) .as(EntityID::new); var rockIDs = Arbitraries.integers() .greaterOrEqual(0) .map(x -> new EntityID(EntityType.Rocks, x)); var targetIDs = Combinators.combine( Arbitraries.of(true, false), characterIDs, rockIDs) .as((which, characterID, rockID) -> which ? characterID : rockID); var stoneTypes = Arbitraries.of(StoneType.class); var values = Arbitraries.integers(); return Combinators.combine( Arbitraries.of(RequestType.class).filter(characterRequestTypes::contains), // types positions.tuple2(), characterIDs, targetIDs, stoneTypes, values ).as((type, pos, characterID, targetID, stoneType, val) -> { return new RequestBuilder(type) .withOriginField(pos.get1()) .withTargetField(pos.get2()) .withOriginEntity(characterID) .withTargetEntity(targetID) .withStoneType(stoneType) .withValue(val) .buildCharacterRequest(); }); } }