diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/AI.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/AI.java index dfa658a..dc686db 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/AI.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/AI.java @@ -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 -> { diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/Board.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/Board.java index 3a51fa5..3b2e320 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/Board.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/Board.java @@ -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 generateActions() { + ArrayList 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); } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/BoardAnalyzer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/BoardAnalyzer.java new file mode 100644 index 0000000..72e6b02 --- /dev/null +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/BoardAnalyzer.java @@ -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 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 actions = origin.generateActions(); + + //TODO: create minimax tree + + return new Action(ActionType.None); + } +} diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/Piece.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/Piece.java index c848051..49e8489 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/Piece.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/Piece.java @@ -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 + ); + } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/PieceType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/PieceType.java index 95eb4ba..3026c3a 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/PieceType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/ai/PieceType.java @@ -3,8 +3,7 @@ package uulm.teamname.marvelous.gamelibrary.ai; enum PieceType { Empty, Rock, - Enemy, - Friend, + Character, InfinityStone, Thanos, NPC