2021-06-04 05:47:54 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.ai;
|
|
|
|
|
2021-06-05 03:19:07 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
|
2021-06-04 05:47:54 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.Character;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
|
2021-06-05 02:19:58 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameStateView;
|
2021-06-04 05:47:54 +00:00
|
|
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestBuilder;
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2021-06-05 02:19:58 +00:00
|
|
|
/** Represents an AI instance for calculations. */
|
|
|
|
class AI {
|
|
|
|
/** The {@link GameStateView} the AI is playing on. */
|
|
|
|
private final GameStateView state;
|
|
|
|
|
|
|
|
/** The Player the AI is playing for. */
|
2021-06-04 05:47:54 +00:00
|
|
|
private final EntityType player;
|
|
|
|
|
2021-06-05 03:19:07 +00:00
|
|
|
/** The config data. */
|
|
|
|
private final PartyConfig partyConfig;
|
|
|
|
private final CharacterConfig characterConfig;
|
|
|
|
private final ScenarioConfig scenarioConfig;
|
|
|
|
|
2021-06-05 02:19:58 +00:00
|
|
|
/** Constructs a new {@link AI} playing the given player based on the given config values. */
|
2021-06-05 03:19:07 +00:00
|
|
|
public AI(GameStateView state, EntityType player, PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) {
|
2021-06-05 02:19:58 +00:00
|
|
|
this.state = state;
|
2021-06-04 05:47:54 +00:00
|
|
|
this.player = player;
|
2021-06-05 03:19:07 +00:00
|
|
|
this.partyConfig = partyConfig;
|
|
|
|
this.characterConfig = characterConfig;
|
|
|
|
this.scenarioConfig = scenarioConfig;
|
2021-06-04 05:47:54 +00:00
|
|
|
}
|
|
|
|
|
2021-06-05 02:19:58 +00:00
|
|
|
/**
|
|
|
|
* Calculates the appropriate actions for a turn of any of the characters the AI is playing for.
|
|
|
|
* @param turn The {@link EntityID} that currently has the turn
|
|
|
|
* @return A list of {@link Request Requests} with the actions the AI wants to perform
|
|
|
|
*/
|
|
|
|
public ArrayList<Request> performTurn(EntityID turn) {
|
2021-06-05 03:19:07 +00:00
|
|
|
System.out.println("[AI] Handling Character " + turn + " for Player " + player + ":");
|
|
|
|
|
2021-06-04 05:47:54 +00:00
|
|
|
ArrayList<Request> result = new ArrayList<>();
|
|
|
|
|
2021-06-05 02:19:58 +00:00
|
|
|
Character character = (Character)state.getEntities().findEntity(turn);
|
2021-06-04 05:47:54 +00:00
|
|
|
|
2021-06-05 03:19:07 +00:00
|
|
|
Board board = Board.generate(state, player);
|
|
|
|
Action action = board.analyze(character.getPosition(), player, partyConfig, characterConfig, scenarioConfig);
|
2021-06-04 05:47:54 +00:00
|
|
|
|
2021-06-05 03:19:07 +00:00
|
|
|
switch(action.type) {
|
|
|
|
case None -> {
|
|
|
|
System.out.println(" Result: doing nothing");
|
2021-06-04 05:47:54 +00:00
|
|
|
}
|
2021-06-05 03:19:07 +00:00
|
|
|
case Move -> {
|
|
|
|
System.out.println(" Result: moving to " + action.target);
|
2021-06-04 05:47:54 +00:00
|
|
|
result.add(new RequestBuilder(RequestType.MoveRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withOriginField(character.getPosition())
|
2021-06-05 03:19:07 +00:00
|
|
|
.withTargetField(action.target)
|
2021-06-04 05:47:54 +00:00
|
|
|
.buildCharacterRequest());
|
2021-06-05 03:19:07 +00:00
|
|
|
}
|
|
|
|
case MeleeAttack -> {
|
|
|
|
System.out.println(" Result: melee attacking " + action.targetEntity);
|
|
|
|
Character target = (Character)state.getEntities().findEntity(action.targetEntity);
|
|
|
|
if(target != null) {
|
|
|
|
result.add(new RequestBuilder(RequestType.MeleeAttackRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withTargetEntity(action.targetEntity)
|
|
|
|
.withOriginField(character.getPosition())
|
|
|
|
.withTargetField(action.target)
|
|
|
|
.withValue(character.meleeDamage)
|
|
|
|
.buildCharacterRequest());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case RangedAttack -> {
|
|
|
|
System.out.println(" Result: ranged attacking " + action.targetEntity);
|
|
|
|
Character target = (Character)state.getEntities().findEntity(action.targetEntity);
|
|
|
|
if(target != null) {
|
|
|
|
result.add(new RequestBuilder(RequestType.RangedAttackRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withTargetEntity(action.targetEntity)
|
|
|
|
.withOriginField(character.getPosition())
|
|
|
|
.withTargetField(action.target)
|
|
|
|
.withValue(character.rangedDamage)
|
|
|
|
.buildCharacterRequest());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case UseStone -> {
|
|
|
|
switch(action.stone) {
|
|
|
|
case SpaceStone -> {
|
|
|
|
System.out.println(" Result: using space stone to " + action.target);
|
|
|
|
result.add(new RequestBuilder(RequestType.UseInfinityStoneRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withOriginField(character.getPosition())
|
|
|
|
.withTargetField(action.target)
|
|
|
|
.withStoneType(action.stone)
|
|
|
|
.buildCharacterRequest());
|
|
|
|
}
|
|
|
|
case MindStone -> {
|
|
|
|
System.out.println(" Result: using mind stone to " + action.target);
|
|
|
|
result.add(new RequestBuilder(RequestType.UseInfinityStoneRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withOriginField(character.getPosition())
|
|
|
|
.withTargetField(action.target)
|
|
|
|
.withValue(partyConfig.mindStoneDMG)
|
|
|
|
.withStoneType(action.stone)
|
|
|
|
.buildCharacterRequest());
|
|
|
|
}
|
|
|
|
case RealityStone -> {
|
|
|
|
System.out.println(" Result: using reality stone at " + action.target);
|
|
|
|
result.add(new RequestBuilder(RequestType.UseInfinityStoneRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withTargetEntity(action.targetEntity)
|
|
|
|
.withOriginField(character.getPosition())
|
|
|
|
.withTargetField(action.target)
|
|
|
|
.withStoneType(action.stone)
|
|
|
|
.buildCharacterRequest());
|
|
|
|
}
|
|
|
|
case PowerStone -> {
|
|
|
|
System.out.println(" Result: using power stone against " + action.targetEntity);
|
|
|
|
result.add(new RequestBuilder(RequestType.UseInfinityStoneRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withTargetEntity(action.targetEntity)
|
|
|
|
.withOriginField(character.getPosition())
|
|
|
|
.withTargetField(action.target)
|
|
|
|
.withValue(character.rangedDamage * 2)
|
|
|
|
.withStoneType(action.stone)
|
|
|
|
.buildCharacterRequest());
|
|
|
|
}
|
|
|
|
case TimeStone -> {
|
|
|
|
System.out.println(" Result: using time stone");
|
|
|
|
result.add(new RequestBuilder(RequestType.UseInfinityStoneRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withOriginField(character.getPosition())
|
|
|
|
.withStoneType(action.stone)
|
|
|
|
.buildCharacterRequest());
|
|
|
|
}
|
|
|
|
case SoulStone -> {
|
|
|
|
System.out.println(" Result: using soul stone on " + action.targetEntity);
|
|
|
|
result.add(new RequestBuilder(RequestType.UseInfinityStoneRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withTargetEntity(action.targetEntity)
|
|
|
|
.withOriginField(character.getPosition())
|
|
|
|
.withTargetField(action.target)
|
|
|
|
.withStoneType(action.stone)
|
|
|
|
.buildCharacterRequest());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case GiveStone -> {
|
|
|
|
System.out.println(" Result: giving stone to " + action.targetEntity);
|
|
|
|
Character target = (Character)state.getEntities().findEntity(action.targetEntity);
|
|
|
|
if(target != null) {
|
|
|
|
result.add(new RequestBuilder(RequestType.ExchangeInfinityStoneRequest)
|
|
|
|
.withOriginEntity(turn)
|
|
|
|
.withTargetEntity(action.targetEntity)
|
|
|
|
.withOriginField(character.getPosition())
|
|
|
|
.withTargetField(action.target)
|
|
|
|
.withStoneType(action.stone)
|
|
|
|
.buildCharacterRequest());
|
|
|
|
}
|
2021-06-04 05:47:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.add(new RequestBuilder(RequestType.EndRoundRequest)
|
|
|
|
.buildGameRequest());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|