2021-05-18 17:03:34 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.gamelogic;
|
|
|
|
|
2021-05-28 15:25:49 +00:00
|
|
|
import net.jqwik.api.*;
|
2021-05-18 17:03:34 +00:00
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
2021-05-28 15:25:49 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.*;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.Character;
|
2021-05-18 17:03:34 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
2021-05-28 15:25:49 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.requests.*;
|
2021-05-18 17:03:34 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2021-05-28 15:25:49 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
2021-05-18 17:03:34 +00:00
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.*;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
|
|
|
|
class GameLogicTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
void executeRequest() {
|
|
|
|
GameState state = new GameState(new IntVector2(10, 10));
|
|
|
|
//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() {
|
|
|
|
}
|
2021-05-28 15:25:49 +00:00
|
|
|
|
|
|
|
// @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) -> {
|
|
|
|
stat.decreaseValue(decrease % (stat.max + 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
|
|
|
}
|