AI leaves garrison when moving away from captured village#25
AI leaves garrison when moving away from captured village#25dmccoystephenson merged 6 commits intomainfrom
Conversation
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
# Conflicts: # backend/src/test/java/com/barony/backend/service/GameServiceTest.java
|
@copilot Unit tests for the backend are failing and the AI is splitting far too often:
|
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Fixed in ef4e0f1. Two issues addressed:
All 131 tests pass. |
There was a problem hiding this comment.
Pull request overview
This PR updates the AI turn logic so that when an AI army leaves an AI-owned village, it splits off a 1-soldier garrison (while avoiding repeated/duplicate garrison creation at the same village), and adds a deterministic regression test to validate the behavior.
Changes:
- Update
executeAI()to create a 1-soldier garrison when an AI army starts moving away from an AI-owned village. - Prevent garrison over-splitting by skipping garrison creation when a friendly non-moving army is already stationed at that village (including garrisons created earlier in the same tick).
- Add a new deterministic test using
getInternalStateForTest()to avoid randomness-related coordinate brittleness.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| backend/src/main/java/com/barony/backend/service/GameService.java | Adds AI garrison-splitting logic when moving away from AI-owned villages, with safeguards against duplicate garrisons. |
| backend/src/test/java/com/barony/backend/service/GameServiceTest.java | Adds a deterministic regression test for AI garrison behavior (and minor whitespace-only adjustments). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot The enemy is still splitting very often, causing trails of 1 man armies to pop up. The AI should decide to garrison at a village until it reaches a particular number of soldiers. Maybe a limit should be placed on how many armies can exist at one time too. |
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Fixed in dacfe1f. Two changes:
All 132 tests pass including a new test verifying that small garrisons stay at their village. |

When the AI captures a village, it now splits its army and leaves a 1-soldier garrison behind to build up forces, rather than moving on immediately with the full army and gaining no benefit from the village.
Changes Made
executeAI()to split off a 1-soldier garrison when an AI army moves away from an owned village, with safeguards against duplicate garrisons at the same village (checks both existing armies and garrisons created earlier in the same tick).AI_MIN_SOLDIERS_TO_MOVE), preventing small garrison armies from immediately wandering off and creating trails of 1-soldier armies.AI_MAX_ARMIES). Garrison creation is skipped if the cap would be exceeded.getInternalStateForTest()to validate both garrison creation on departure and garrison staying behavior below the soldier threshold.Testing
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.