wip: prepare ai for using action trees and boards with score calculation

This commit is contained in:
2021-06-05 05:19:07 +02:00
parent aa1d2c48df
commit c97ff03a68
9 changed files with 338 additions and 18 deletions

View File

@ -0,0 +1,73 @@
package uulm.teamname.marvelous.gamelibrary.ai;
import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.config.CharacterConfig;
import uulm.teamname.marvelous.gamelibrary.config.PartyConfig;
import uulm.teamname.marvelous.gamelibrary.config.ScenarioConfig;
import uulm.teamname.marvelous.gamelibrary.entities.*;
import uulm.teamname.marvelous.gamelibrary.entities.Character;
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameStateView;
import java.util.ArrayList;
class Board {
private final Piece[][] data;
private Board(Piece[][] data) {
this.data = data;
}
public static Board generate(GameStateView state, EntityType player) {
Piece[][] data = new Piece[state.getMapSize().getY()][state.getMapSize().getX()];
for(int x = 0; x < state.getMapSize().getX(); x++) {
for(int y = 0; y < state.getMapSize().getY(); y++) {
IntVector2 pos = new IntVector2(x, y);
ArrayList<Entity> entities = state.getEntities().findByPosition(pos);
if(entities.isEmpty()) {
data[y][x] = new Piece(PieceType.Empty);
}else {
Entity entity = entities.get(0);
switch(entity.id.type) {
case NPC -> {
if(entity.id.id == NPCType.Thanos.getID()) {
data[y][x] = new Piece(PieceType.Thanos);
}else {
data[y][x] = new Piece(PieceType.NPC);
}
}
case P1, P2 -> {
Character character = (Character)entity;
data[y][x] = new Piece(
entity.id.type == player ? PieceType.Friend : PieceType.Enemy,
entity.id,
character.hp.getValue(),
character.hp.getMax(),
character.mp.getValue(),
character.mp.getMax(),
character.ap.getValue(),
character.ap.getMax(),
character.inventory.getStonesAsArray()
);
}
case Rocks -> {
Rock rock = (Rock)entity;
data[y][x] = new Piece(PieceType.Rock, entity.id, rock.getHp(), rock.maxHP);
}
case InfinityStones -> {
InfinityStone stone = (InfinityStone)entity;
data[y][x] = new Piece(PieceType.InfinityStone, entity.id, stone.type);
}
case None -> {
data[y][x] = new Piece(PieceType.Empty);
}
}
}
}
}
return new Board(data);
}
public Action analyze(IntVector2 position, EntityType turn, PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) {
return new Action(ActionType.None);
}
}