Gamelib/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogicTest.java

192 lines
6.3 KiB
Java
Raw Normal View History

2021-05-18 17:03:34 +00:00
package uulm.teamname.marvelous.gamelibrary.gamelogic;
import net.jqwik.api.*;
2021-05-18 17:03:34 +00:00
import org.junit.jupiter.api.Test;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.*;
2021-05-18 17:03:34 +00:00
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.*;
2021-05-18 17:03:34 +00:00
import java.util.ArrayList;
import java.util.List;
2021-05-18 17:03:34 +00:00
class GameLogicTest {
@Test
void executeRequest() {
GameState state = new GameState(new PartyConfig(), new CharacterConfig(), new ScenarioConfig());
2021-05-18 17:03:34 +00:00
//build a nice state (add entities and stuff)
ArrayList<Event> 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> gamestate() {
// var states = Arbitraries.integers()
// .tuple2()
// .map(x -> new IntVector2(x.get1(), x.get2()))
// .map(GameState::new);
// }
// @Provide("entityManager")
// Arbitrary<EntityManager> entityManager() {
// var managers = Arbitraries.of(EntityManager.class);
//
// }
// @Provide("entity")
// Arbitrary<Entity> entity() {
// var entities = Arbitraries.of(Entity.class);
// }
// Characters are kind of hard, but most prequisites are here
// @Provide("character")
// Arbitrary<Character> character() {
// var characters = Combinators.combine(
// anyStat(),
// Arbitraries.integers()
// ).as(x -> new Character());
// }
@Provide("stat")
Arbitrary<Stat> 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) -> {
2021-05-31 20:54:13 +00:00
stat.decreaseValue(decrease % (stat.getMax() + 1));
return stat;
});
}
@Provide("entityIDs")
Arbitrary<EntityID> 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<IntVector2> positions() {
return Arbitraries.integers()
.greaterOrEqual(0)
.tuple2()
.map(x -> new IntVector2(x.get1(), x.get2()));
}
@Provide("requests")
Arbitrary<Request> requests() {
return Combinators.combine(
Arbitraries.of(true, false),
gameRequests(),
characterRequests())
.as((which, gameRequest, characterRequest) -> which ? gameRequest : characterRequest);
}
@Provide("gameRequests")
Arbitrary<GameRequest> 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<CharacterRequest> 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();
});
}
2021-05-18 17:03:34 +00:00
}