diff --git a/docs/prompts.md b/docs/prompts.md index 8f8a6c7..674366e 100644 --- a/docs/prompts.md +++ b/docs/prompts.md @@ -1,4 +1,7 @@ +@DeathBoxGameLogicService: Nachdem ein Spieler ein Ei verdienst hat, muss der nächste zwangsweise wieder in die Vollen, also auf alle 9 Pins werden. Dafür muss er ein X bekommen, was aktuell nicht der Fall ist. + + - neuer Tag -> optional Gäste und nicht alle Teilnehmer - Tag beendnden -> alle Teilnehmer hinzufügen, und strafen hinzufügen - offene Sachstrafen von einem Tag zum nächsten fortschreiben diff --git a/src/Koogle.Application/Games/DeathBox/DeathBoxGameLogicService.cs b/src/Koogle.Application/Games/DeathBox/DeathBoxGameLogicService.cs index ea5a1c3..916fb1e 100644 --- a/src/Koogle.Application/Games/DeathBox/DeathBoxGameLogicService.cs +++ b/src/Koogle.Application/Games/DeathBox/DeathBoxGameLogicService.cs @@ -60,6 +60,7 @@ public class DeathBoxGameLogicService : IGameLogicService var playerStates = new Dictionary(model.PlayerStates); var eliminatedPlayers = new List(model.EliminatedPlayers); var triggers = new List(); + var assignX = false; // Get current player state var currentState = playerStates[playerId]; @@ -83,8 +84,8 @@ public class DeathBoxGameLogicService : IGameLogicService if (isNewRound) { // Always collect X on new round - currentState.XCount++; - lastThrow = lastThrow with { EarnedX = true }; + //currentState.XCount++; + //lastThrow = lastThrow with { EarnedX = true }; // Penalty for <3 pins on new round if (pinsKnocked < 3) @@ -135,10 +136,10 @@ public class DeathBoxGameLogicService : IGameLogicService } // 3. CLEARED processing (all remaining pins hit) - Guid? previousPlayerPenalizedId = null; + //Guid? previousPlayerPenalizedId = null; bool previousPlayerEliminated = false; - if (afterThrow.IsCleared && !isNewRound) + if (afterThrow.IsCleared /*&& !isNewRound*/) { // Current player gets egg currentState.EggCount++; @@ -156,6 +157,9 @@ public class DeathBoxGameLogicService : IGameLogicService // Eggs expire if no marks to remove } + // in case eggs have been earned, next player will get another X + assignX = true; + // Previous player gets mark (if exists and not eliminated) if (model.PreviousPlayerId.HasValue && playerStates.TryGetValue(model.PreviousPlayerId.Value, out var prevState) && @@ -167,7 +171,7 @@ public class DeathBoxGameLogicService : IGameLogicService PreviousPlayerGotMark = true, PreviousPlayerPenalizedId = model.PreviousPlayerId.Value }; - previousPlayerPenalizedId = model.PreviousPlayerId.Value; + //previousPlayerPenalizedId = model.PreviousPlayerId.Value; // Check if previous player is eliminated if (prevState.Marks >= model.CoffinSize) @@ -238,6 +242,36 @@ public class DeathBoxGameLogicService : IGameLogicService if (currentIndex < 0) currentIndex = model.CurrentPlayerIndex; int nextPlayerIndex = GetNextActivePlayerIndex(model.PlayerOrder, currentIndex, playerStates); + var nextPlayerId = model.PlayerOrder[nextPlayerIndex]; + if (assignX) + { + var nextState = playerStates[nextPlayerId]; + nextState.XCount ++; + lastThrow = lastThrow with { EarnedX = true }; + + lastThrow = lastThrow with + { + EarnedX = true, + NextPlayerPenalizedId = nextPlayerId + }; + + // Check X conversion (3 X's -> 1 mark) + if (nextState.XCount >= 3) + { + lastThrow = lastThrow with + { + NextPlayerGotMark = true, + NextPlayerPenalizedId = nextPlayerId + }; + + + nextState.XCount = 0; + nextState.Marks++; + lastThrow = lastThrow with { ConvertedXsToMark = true }; + } + + playerStates[nextPlayerId] = nextState; + } // Update model model = model with diff --git a/src/Koogle.Application/Games/DeathBox/DeathBoxGameModel.cs b/src/Koogle.Application/Games/DeathBox/DeathBoxGameModel.cs index 060ce13..c004db2 100644 --- a/src/Koogle.Application/Games/DeathBox/DeathBoxGameModel.cs +++ b/src/Koogle.Application/Games/DeathBox/DeathBoxGameModel.cs @@ -149,6 +149,16 @@ public record DeathBoxLastThrow /// public bool ConvertedEggsToRemoveMark { get; init; } + /// + /// Whether the next player got a mark (cleared penalty). + /// + public bool NextPlayerGotMark { get; init; } + + /// + /// ID of next player who got a mark (if any). + /// + public Guid? NextPlayerPenalizedId { get; init; } + /// /// Whether the previous player got a mark (cleared penalty). /// diff --git a/src/Koogle.Web/Components/Game/DeathBox/DeathBoxBoard.razor b/src/Koogle.Web/Components/Game/DeathBox/DeathBoxBoard.razor index 31b72dc..15ed73f 100644 --- a/src/Koogle.Web/Components/Game/DeathBox/DeathBoxBoard.razor +++ b/src/Koogle.Web/Components/Game/DeathBox/DeathBoxBoard.razor @@ -283,10 +283,6 @@ // Pin count messages.Add($"{playerName}: {lt.PinsKnocked} Pin(s)"); - // X earned - if (lt.EarnedX) - messages.Add("X gesammelt"); - // Penalty for <3 pins if (lt.WasPenalty) messages.Add("Weniger als 3 Pins! +1 Strich"); @@ -308,12 +304,26 @@ messages.Add($"{prevName} bekommt +1 Strich"); } - // Conversions - if (lt.ConvertedXsToMark) - messages.Add("3 Xe → +1 Strich"); + // Conversions PreviousPlayer if (lt.ConvertedEggsToRemoveMark) messages.Add("3 Eier → -1 Strich!"); + // X earned + if (lt.EarnedX && lt.NextPlayerPenalizedId.HasValue) + { + var nextName = GetPlayerName(lt.NextPlayerPenalizedId.Value); + messages.Add($"{nextName}: X gesammelt"); + } + + // Conversions NextPlayer + if (lt.ConvertedXsToMark && lt.NextPlayerPenalizedId.HasValue) + { + var nextName = GetPlayerName(lt.NextPlayerPenalizedId.Value); + messages.Add($"{nextName} 3 Xe → +1 Strich"); + } + + + // Eliminations if (lt.PlayerEliminated) messages.Add($"{playerName} ist ausgeschieden!");