wip: create proper board analyzer for ai
This commit is contained in:
parent
b183f623d6
commit
220136af55
@ -47,8 +47,8 @@ class AI {
|
||||
|
||||
Character character = (Character)state.getEntities().findEntity(turn);
|
||||
|
||||
Board board = Board.generate(state, player);
|
||||
Action action = board.analyze(character.getPosition(), player, partyConfig, characterConfig, scenarioConfig);
|
||||
BoardAnalyzer analyzer = new BoardAnalyzer(state, player);
|
||||
Action action = analyzer.analyze(character.getPosition(), player, partyConfig, characterConfig, scenarioConfig);
|
||||
|
||||
switch(action.type) {
|
||||
case None -> {
|
||||
|
@ -1,20 +1,20 @@
|
||||
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;
|
||||
import java.util.Objects;
|
||||
|
||||
class Board {
|
||||
private final Piece[][] data;
|
||||
private final EntityType turn;
|
||||
|
||||
private Board(Piece[][] data) {
|
||||
private Board(Piece[][] data, EntityType turn) {
|
||||
this.data = data;
|
||||
this.turn = turn;
|
||||
}
|
||||
|
||||
public static Board generate(GameStateView state, EntityType player) {
|
||||
@ -38,7 +38,7 @@ class Board {
|
||||
case P1, P2 -> {
|
||||
Character character = (Character)entity;
|
||||
data[y][x] = new Piece(
|
||||
entity.id.type == player ? PieceType.Friend : PieceType.Enemy,
|
||||
PieceType.Character,
|
||||
entity.id,
|
||||
character.hp.getValue(),
|
||||
character.hp.getMax(),
|
||||
@ -64,10 +64,37 @@ class Board {
|
||||
}
|
||||
}
|
||||
}
|
||||
return new Board(data);
|
||||
return new Board(data, player);
|
||||
}
|
||||
|
||||
public Action analyze(IntVector2 position, EntityType turn, PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) {
|
||||
return new Action(ActionType.None);
|
||||
protected ArrayList<Action> generateActions() {
|
||||
ArrayList<Action> result = new ArrayList<>();
|
||||
|
||||
//TODO: generate possible actions
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Board applyAction(Action action) {
|
||||
Piece[][] clone = new Piece[this.data.length][this.data[0].length];
|
||||
|
||||
for(int x = 0; x < this.data[0].length; x++) {
|
||||
for(int y = 0; y < this.data.length; y++) {
|
||||
clone[y][x] = this.data[y][x].clone();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: apply action
|
||||
|
||||
return new Board(clone, turn == EntityType.P1 ? EntityType.P2 : EntityType.P1);
|
||||
}
|
||||
|
||||
protected int calculateScore() {
|
||||
//TODO: create score calculation
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected int calculateHash() {
|
||||
return Objects.hash(super.hashCode(), data);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
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.EntityType;
|
||||
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameStateView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
class BoardAnalyzer {
|
||||
private final Board origin;
|
||||
private final EntityType player;
|
||||
private final HashMap<Integer, Integer> cache = new HashMap<>();
|
||||
|
||||
public BoardAnalyzer(GameStateView state, EntityType player) {
|
||||
this.origin = Board.generate(state, player);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public Action analyze(IntVector2 position, EntityType turn, PartyConfig partyConfig, CharacterConfig characterConfig, ScenarioConfig scenarioConfig) {
|
||||
ArrayList<Action> actions = origin.generateActions();
|
||||
|
||||
//TODO: create minimax tree
|
||||
|
||||
return new Action(ActionType.None);
|
||||
}
|
||||
}
|
@ -57,4 +57,29 @@ class Piece {
|
||||
this.inventory = new HashSet<>(Arrays.asList(inventory));
|
||||
this.stone = null;
|
||||
}
|
||||
|
||||
private Piece(PieceType type, EntityID id, int hp, int maxHP, int mp, int maxMP, int ap, int maxAP, StoneType[] inventory, StoneType stone) {
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
this.hp = new Stat(StatType.HP, hp, maxHP);
|
||||
this.mp = new Stat(StatType.MP, mp, maxMP);
|
||||
this.ap = new Stat(StatType.AP, ap, maxAP);
|
||||
this.inventory = new HashSet<>(Arrays.asList(inventory));
|
||||
this.stone = stone;
|
||||
}
|
||||
|
||||
public Piece clone() {
|
||||
return new Piece(
|
||||
this.type,
|
||||
this.id,
|
||||
this.hp.getValue(),
|
||||
this.hp.getMax(),
|
||||
this.mp.getValue(),
|
||||
this.mp.getMax(),
|
||||
this.ap.getValue(),
|
||||
this.ap.getMax(),
|
||||
this.inventory.toArray(new StoneType[0]),
|
||||
this.stone
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,7 @@ package uulm.teamname.marvelous.gamelibrary.ai;
|
||||
enum PieceType {
|
||||
Empty,
|
||||
Rock,
|
||||
Enemy,
|
||||
Friend,
|
||||
Character,
|
||||
InfinityStone,
|
||||
Thanos,
|
||||
NPC
|
||||
|
Loading…
Reference in New Issue
Block a user