improvements logging

This commit is contained in:
2026-04-13 23:30:40 +02:00
parent 1fa17aa9b6
commit 5a29533736
6 changed files with 41 additions and 41 deletions

View File

@@ -228,9 +228,7 @@ public class DeckGridAppFX extends Application {
StackPane.setAlignment(debugLabel, Pos.TOP_LEFT); StackPane.setAlignment(debugLabel, Pos.TOP_LEFT);
// You can also use Pos.CENTER, Pos.BOTTOM_RIGHT, etc. // You can also use Pos.CENTER, Pos.BOTTOM_RIGHT, etc.
cardImage.setOnMouseClicked(event -> { cardImage.setOnMouseClicked(event -> {
logger.info("Bottom Card clicked");
Player p = game.getCurrentPlayer(); Player p = game.getCurrentPlayer();
//pickBottomCardAction(p, game.getGameBoard(), c.getCardId());
ActionResult result = game.resolveCardAction(p, false, c.getCardId()); ActionResult result = game.resolveCardAction(p, false, c.getCardId());
if (!result.isSuccess()) { if (!result.isSuccess()) {
new Alert(Alert.AlertType.ERROR, new Alert(Alert.AlertType.ERROR,
@@ -276,9 +274,7 @@ public class DeckGridAppFX extends Application {
StackPane.setAlignment(debugLabel, Pos.TOP_LEFT); StackPane.setAlignment(debugLabel, Pos.TOP_LEFT);
// You can also use Pos.CENTER, Pos.BOTTOM_RIGHT, etc. // You can also use Pos.CENTER, Pos.BOTTOM_RIGHT, etc.
cardImage.setOnMouseClicked(event -> { cardImage.setOnMouseClicked(event -> {
logger.info("Card clicked");
Player p = game.getCurrentPlayer(); Player p = game.getCurrentPlayer();
ActionResult result = game.resolveCardAction(p, true, c.getCardId()); ActionResult result = game.resolveCardAction(p, true, c.getCardId());
if (!result.isSuccess()) { if (!result.isSuccess()) {
new Alert(Alert.AlertType.ERROR, new Alert(Alert.AlertType.ERROR,

View File

@@ -197,7 +197,7 @@ public class GameBoard {
// Step 4: draw fresh cards into the top row // Step 4: draw fresh cards into the top row
List<Card> newCards = cardDeck.drawTribe(numPlayers + 4); List<Card> newCards = cardDeck.drawTribe(numPlayers + 4);
topRow.addAll(newCards); topRow.addAll(newCards);
logger.info("NEW CARDS ON TOP {} " , newCards); logger.info("New cards on top: {} " , newCards);
return isNewEraRevealed(eraBeforeDraw, newCards); return isNewEraRevealed(eraBeforeDraw, newCards);
} }

View File

@@ -93,10 +93,17 @@ public class Player {
//🔴👤 Red Player //🔴👤 Red Player
//🟢👤 Green Player //🟢👤 Green Player
//🟣👤 Purple Player //🟣👤 Purple Player
StringBuffer sb = new StringBuffer();
return ( "("+getAnsiColorIcon(getTotemColor()) +" " + nickname + sb.append("("+getAnsiColorIcon(getTotemColor()) +" " + nickname +
" - food=" + foodTokens + " - food=" + foodTokens +
", pp=" + prestigePoints + ")"); ", pp=" + prestigePoints + ")");
if (!this.getPlayerTribe().getCharacters().isEmpty())
sb.append(this.getPlayerTribe().getCharacters());
if (!this.getPlayerTribe().getBuildingCard().isEmpty())
sb.append(this.getPlayerTribe().getBuildingCard());
return sb.toString();
} }
public static String getAnsiColorIcon(TotemColor c) { public static String getAnsiColorIcon(TotemColor c) {

View File

@@ -127,7 +127,7 @@ public class TurnTile {
positions[slot] = player; positions[slot] = player;
nextFreeSlot++; nextFreeSlot++;
logger.info(player.getNickname() + " returned totem to slot " + slot logger.debug(player.getNickname() + " returned totem to slot " + slot
+ (positionFood > 0 ? " and received " + positionFood + " food" : "")); + (positionFood > 0 ? " and received " + positionFood + " food" : ""));
return slot; return slot;
} }

View File

@@ -99,7 +99,7 @@ public class Game {
*/ */
public void newGame(InputStream csvStream) { public void newGame(InputStream csvStream) {
try { try {
logger.info("STARTING NEW GAME"); logger.info(" ---- STARTING NEW GAME ----- ");
CardDeck deck = new CardDeck(); CardDeck deck = new CardDeck();
deck.setForNPlayer(csvStream, players.size()); deck.setForNPlayer(csvStream, players.size());
@@ -115,11 +115,10 @@ public class Game {
totemPlacedCount = 0; totemPlacedCount = 0;
state = GameState.TOTEM_PLACEMENT; state = GameState.TOTEM_PLACEMENT;
logger.info("Game started! Round 1.");
logTurnOrder(); logTurnOrder();
} catch (LoadingCardsException e) { } catch (LoadingCardsException e) {
System.err.println("Fatal: could not load cards — " + e.getMessage()); logger.error("Fatal: could not load cards — " + e.getMessage());
state = GameState.GAME_OVER; state = GameState.GAME_OVER;
} }
} }
@@ -129,7 +128,7 @@ public class Game {
for (int i = 0; i < order.length; i++) { for (int i = 0; i < order.length; i++) {
int food = (i == 0) ? 2 : (i <= 2) ? 3 : 4; int food = (i == 0) ? 2 : (i <= 2) ? 3 : 4;
order[i].addFood(food); order[i].addFood(food);
logger.info(" " + order[i].getNickname() + " starts with " + food + " food."); logger.debug(" " + order[i].getNickname() + " starts with " + food + " food.");
} }
} }
@@ -149,37 +148,37 @@ public class Game {
*/ */
public boolean placeTotem(Player player, int tileIndex) { public boolean placeTotem(Player player, int tileIndex) {
if (state != GameState.TOTEM_PLACEMENT) { if (state != GameState.TOTEM_PLACEMENT) {
logger.info("Error: not the totem-placement phase."); logger.error("Error: not the totem-placement phase.");
return false; return false;
} }
// Enforce turn order // Enforce turn order
Player expected = gameBoard.getTurnTile().getPositions()[totemPlacedCount]; Player expected = gameBoard.getTurnTile().getPositions()[totemPlacedCount];
if (expected != player) { if (expected != player) {
logger.info("Error: it is " + expected.getNickname() logger.error("Error: it is " + expected.getNickname()
+ "'s turn to place, not " + player.getNickname() + "."); + "'s turn to place, not " + player.getNickname() + ".");
return false; return false;
} }
List<OfferingTile> tiles = gameBoard.getOfferingTiles(); List<OfferingTile> tiles = gameBoard.getOfferingTiles();
if (tileIndex < 0 || tileIndex >= tiles.size()) { if (tileIndex < 0 || tileIndex >= tiles.size()) {
logger.info("Error: tile index " + tileIndex + " out of range."); logger.error("Error: tile index " + tileIndex + " out of range.");
return false; return false;
} }
OfferingTile chosen = tiles.get(tileIndex); OfferingTile chosen = tiles.get(tileIndex);
if (!gameBoard.placeTotem(player, chosen, gameBoard.getTurnTile())) { if (!gameBoard.placeTotem(player, chosen, gameBoard.getTurnTile())) {
logger.info("Tile " + chosen.getLetter() + " is already occupied."); logger.debug("Tile " + chosen.getLetter() + " is already occupied.");
return false; return false;
} }
totemPlacedCount++; totemPlacedCount++;
logger.info("player {} TOTEM PLACED ON TILE {}", player.getNickname() , chosen.getLetter()); logger.debug("player {} TOTEM PLACED ON TILE {}", player.getNickname() , chosen.getLetter());
// + " (" + totemPlacedCount + "/" + players.size() + ")."); // + " (" + totemPlacedCount + "/" + players.size() + ").");
if (totemPlacedCount == players.size()) { if (totemPlacedCount == players.size()) {
logger.info("START ACTION RESOLUTION"); logger.info(" ----- START ACTION RESOLUTION ---- ");
startActionResolution(); startActionResolution();
} }
return true; return true;
@@ -192,7 +191,7 @@ public class Game {
private void startActionResolution() { private void startActionResolution() {
state = GameState.ACTION_RESOLUTION; state = GameState.ACTION_RESOLUTION;
currentOfferingTileIndex = 0; currentOfferingTileIndex = 0;
logger.info("All totems placed — resolving actions left to right."); logger.info("ALL TOTEMS PLACED -> ACTION_RESOLUTION ");
loadNextPlayerActions(); loadNextPlayerActions();
} }
@@ -216,15 +215,15 @@ public class Game {
Player player = tile.getOccupant(); Player player = tile.getOccupant();
pendingActions = new ArrayList<>(tile.getActions()); pendingActions = new ArrayList<>(tile.getActions());
logger.info(" PLAYER {} PENDING_ACTIONS {} ", player.getNickname() , pendingActions ); logger.debug(" PLAYER {} PENDING_ACTIONS {} ", player.getNickname() , pendingActions );
// --- Food tile: resolve entirely without player input --- // --- Food tile: resolve entirely without player input ---
if (pendingActions.get(0) == Symbol.FOOD) { if (pendingActions.get(0) == Symbol.FOOD) {
int food = pendingActions.size(); int food = pendingActions.size();
player.addFood(food); player.addFood(food);
BuildingManager.bonusEndTurn(player, food); // BONUS_FOOD_ENDTURN building effect BuildingManager.bonusEndTurn(player, food); // BONUS_FOOD_ENDTURN building effect
logger.info(player.getNickname() + " receives " + food logger.info("ACTION FOOD {} GET {} ", player.getNickname() , food
+ " food from tile " + tile.getLetter() + "."); + " FROM TILE " + tile.getLetter() );
pendingActions.clear(); pendingActions.clear();
finishPlayerTurn(player); finishPlayerTurn(player);
currentOfferingTileIndex++; currentOfferingTileIndex++;
@@ -242,7 +241,7 @@ public class Game {
} }
// Wait for the player to call resolveCardAction() // Wait for the player to call resolveCardAction()
logger.info("player {} pending ACTIONS {}" , player.getNickname() , pendingActions); logger.debug("player {} pending ACTIONS {}" , player.getNickname() , pendingActions);
// logger.info("It is " + player.getNickname() + "'s turn — actions: " + pendingActions); // logger.info("It is " + player.getNickname() + "'s turn — actions: " + pendingActions);
return; return;
} }
@@ -294,20 +293,20 @@ public class Game {
*/ */
public ActionResult resolveCardAction(Player player, boolean fromTop, int cardId) { public ActionResult resolveCardAction(Player player, boolean fromTop, int cardId) {
if (state != GameState.ACTION_RESOLUTION) { if (state != GameState.ACTION_RESOLUTION) {
logger.info("Error: not in ACTION_RESOLUTION phase."); logger.error("Error: not in ACTION_RESOLUTION phase.");
return ActionResult.failure("Error: not in ACTION_RESOLUTION phase."); return ActionResult.failure("Error: not in ACTION_RESOLUTION phase.");
} }
OfferingTile currentTile = gameBoard.getOfferingTiles().get(currentOfferingTileIndex); OfferingTile currentTile = gameBoard.getOfferingTiles().get(currentOfferingTileIndex);
if (currentTile.getOccupant() != player) { if (currentTile.getOccupant() != player) {
logger.info("Error: it is not " + player.getNickname() + "'s turn to act."); logger.error("Error: it is not " + player.getNickname() + "'s turn to act.");
return ActionResult.failure("Error: it is not " + player.getNickname() + "'s turn to act."); return ActionResult.failure("Error: it is not " + player.getNickname() + "'s turn to act.");
} }
Symbol required = fromTop ? Symbol.UP : Symbol.DOWN; Symbol required = fromTop ? Symbol.UP : Symbol.DOWN;
if (!pendingActions.contains(required)) { if (!pendingActions.contains(required)) {
logger.info("Error: no " + required + " action available for " logger.error("Error: no " + required + " action available for "
+ player.getNickname() + "."); + player.getNickname() + ".");
return ActionResult.failure("Error: no " + required + " action available for " return ActionResult.failure("Error: no " + required + " action available for "
+ player.getNickname() + "."); + player.getNickname() + ".");
@@ -319,7 +318,7 @@ public class Game {
: gameBoard.takeFromBottomRow(cardId); : gameBoard.takeFromBottomRow(cardId);
if (card == null) { if (card == null) {
logger.info("Error: card " + cardId + " not found in the " logger.error("Error: card " + cardId + " not found in the "
+ (fromTop ? "top" : "bottom") + " row."); + (fromTop ? "top" : "bottom") + " row.");
return ActionResult.failure("Error: card " + cardId + " not found in the " return ActionResult.failure("Error: card " + cardId + " not found in the "
+ (fromTop ? "top" : "bottom") + " row."); + (fromTop ? "top" : "bottom") + " row.");
@@ -328,7 +327,7 @@ public class Game {
// Event cards can never be taken by players // Event cards can never be taken by players
if (card instanceof EventCard) { if (card instanceof EventCard) {
putCardBack(card, fromTop); putCardBack(card, fromTop);
logger.info("Error: Event cards cannot be taken."); logger.error("Error: Event cards cannot be taken.");
return ActionResult.failure("Error: Event cards cannot be taken."); return ActionResult.failure("Error: Event cards cannot be taken.");
} }
@@ -345,7 +344,7 @@ public class Game {
// Consume the action // Consume the action
pendingActions.remove(required); pendingActions.remove(required);
logger.info("player {} TOOK CARD {} --> PEDNING ACTIONS {}",player.getNickname(), cardId, pendingActions); logger.debug("player {} TOOK CARD {} --> PEDNING ACTIONS {}",player.getNickname(), cardId, pendingActions);
// A row may have become empty after this draw — re-check impossible actions // A row may have become empty after this draw — re-check impossible actions
@@ -414,8 +413,7 @@ public class Game {
&& character.getIconValue() > 0) { && character.getIconValue() > 0) {
int food = player.getPlayerTribe().huntersNumber() * character.getIconValue(); int food = player.getPlayerTribe().huntersNumber() * character.getIconValue();
player.addFood(food); player.addFood(food);
logger.info(player.getNickname() + "'s hunter (leg icon) grants +" logger.info("GET HUNTER FOOD {} for player {}",food, player.getNickname() );
+ food + " food.");
} }
// Building-triggered effects on character draw // Building-triggered effects on character draw
@@ -424,8 +422,7 @@ public class Game {
gameBoard.getBuildingManager().foodPerInventors(player, character); gameBoard.getBuildingManager().foodPerInventors(player, character);
} }
logger.info(player.getNickname() + " drew " logger.info("{} PICKED {}", player.getNickname() , character);
+ character.getCharacterType() + " (id " + character.getCardId() + ").");
} }
/** /**
@@ -436,9 +433,9 @@ public class Game {
private void finishPlayerTurn(Player player) { private void finishPlayerTurn(Player player) {
int slot = gameBoard.getTurnTile().returnTotem(player); int slot = gameBoard.getTurnTile().returnTotem(player);
OfferingTile off = gameBoard.getOfferingTile(player); OfferingTile off = gameBoard.getOfferingTile(player);
logger.info("player {} leaving offering {} " ,player.getNickname(), off); //logger.info("player {} leaving offering {} " ,player.getNickname(), off);
if(off!=null) off.setOccupant(null); if(off!=null) off.setOccupant(null);
logger.info("player {} left offering {} slot {} " ,player.getNickname(), off, slot); logger.debug("player {} left offering {} slot {} " ,player.getNickname(), off, slot);
} }
@@ -456,7 +453,7 @@ public class Game {
* Character or Building card (paying its cost) from the top row." * Character or Building card (paying its cost) from the top row."
*/ */
private void onAllActionsResolved() { private void onAllActionsResolved() {
logger.info("All actions resolved."); logger.info("--- ALL ACTIONS RESOLVED ---");
extraDrawQueue.clear(); extraDrawQueue.clear();
// Iterate in turn order so extra draws happen in a consistent sequence // Iterate in turn order so extra draws happen in a consistent sequence
@@ -563,7 +560,7 @@ public class Game {
state = GameState.EVENT_RESOLUTION; state = GameState.EVENT_RESOLUTION;
//notify( GameState.EVENT_RESOLUTION); //notify( GameState.EVENT_RESOLUTION);
logger.info("--- End of round " + round + " ---"); logger.info("--- START NEXT ROUND " + round + " ---");
boolean isFinalRound = (round == TOTAL_ROUNDS); boolean isFinalRound = (round == TOTAL_ROUNDS);
@@ -573,7 +570,7 @@ public class Game {
if (isFinalRound) { if (isFinalRound) {
state = GameState.GAME_OVER; state = GameState.GAME_OVER;
notify( GameState.GAME_OVER, endGame()); notify( GameState.GAME_OVER, endGame());
logger.info("Round 10 complete — game over!"); logger.info("============= GAME OVER ============");
return; return;
} }
@@ -605,7 +602,7 @@ public class Game {
: gameBoard.getVisibleEvents(); // already sorted by Era ordinal : gameBoard.getVisibleEvents(); // already sorted by Era ordinal
if (events.isEmpty()) { if (events.isEmpty()) {
logger.info("No events to resolve this round."); logger.info("NO EVENTS TO SOLVE");
return; return;
} }
@@ -634,7 +631,7 @@ public class Game {
round++; round++;
notify( GameState.NEXT_ROUND, "Round="+ round); notify( GameState.NEXT_ROUND, "Round="+ round);
logger.info("startNewRound: {}", round ); logger.debug("startNewRound: {}", round );
totemPlacedCount = 0; totemPlacedCount = 0;
currentOfferingTileIndex = 0; currentOfferingTileIndex = 0;
pendingActions.clear(); pendingActions.clear();

View File

@@ -29,7 +29,7 @@ public class GameUtils {
public static String formatTurnTile(TurnTile t) { public static String formatTurnTile(TurnTile t) {
//for (Player p : t.getPositions()){" : "occupied"); //for (Player p : t.getPositions()){" : "occupied");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("[TURN ORDER]\n"); sb.append("Turn Tile\n");
for (int i = 0; i < t.getPositions().length; i++) { for (int i = 0; i < t.getPositions().length; i++) {
Player p = t.getPositions()[i]; Player p = t.getPositions()[i];