fix: ignore enemies with unknown HP in rank prediction (poi-lib-battle 3.2.0) - #135
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes rank simulation when the game reports enemy HP as a non-numeric placeholder (e.g. 'N/A') by temporarily excluding such enemies from poi-lib-battle’s internal rank calculation, preventing NaN HP totals and incorrect non-S/SS outcomes. It also updates dependencies/overrides to resolve npm install peer conflicts and bumps poi-lib-battle.
Changes:
- Add
simulateResult()to null out enemies with non-finiteinitHP/nowHPduring rank simulation, then restore fleets. - Update battle packet simulation flow to use
simulateResult()instead of directly readingsimulator.result. - Add unit tests covering mixed numeric/unknown HP cases and fleet immutability.
- Update
package.json(@types/node,poi-lib-battle) and add an npmoverridesblock for Blueprint’s React peer constraints.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/utils/lib-battle-adapter.ts |
Adds simulateResult() plus helpers to ignore enemies with unknown HP during rank computation while restoring simulator state afterward. |
src/utils/lib-battle-adapter.test.ts |
Adds vitest coverage for rank behavior and ensuring fleets remain untouched post-simulation. |
src/battle/packet-controller.ts |
Switches result computation to simulateResult(simulator) before synthesizing display state. |
package.json |
Resolves peer conflicts via overrides and bumps types/lib versions as described in the PR. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+69
to
+77
| const hasNumericHP = (ship: Ship | null): boolean => | ||
| ship == null || (Number.isFinite(ship.initHP) && Number.isFinite(ship.nowHP)) | ||
|
|
||
| const withoutUnknownHP = (fleet: (Ship | null)[] | null): (Ship | null)[] | null => | ||
| fleet && fleet.map((ship) => (hasNumericHP(ship) ? ship : null)) | ||
|
|
||
| export const simulateResult = (simulator: Simulator): Result => { | ||
| const enemies = [...(simulator.enemyFleet ?? []), ...(simulator.enemyEscort ?? [])] | ||
| const known = enemies.filter((ship) => ship != null && hasNumericHP(ship)) |
KochiyaOcean
force-pushed
the
fix/rank-ignore-unknown-enemy-hp
branch
from
August 9, 2026 15:46
1d802c8 to
8fd8db1
Compare
The game reports the HP of some enemies as a non-numeric placeholder (currently 'N/A'). The rank formula used to count every enemy, so such an enemy was never seen as sunk and a battle where all other enemies went down could never be predicted as S. poi-lib-battle 3.2.0 fixes this at the source: it flags those ships as hpUnknown and skips them where HP matters. Prophet builds its own enemy ships for base defense, so set the same flag there to keep them consistent, and pin the behaviour with tests on the library contract. The bump also needed npm install to work again; it failed with ERESOLVE on two pre-existing peer conflicts: - @blueprintjs/core@4 peers react ^16.8 || 17 || 18 while the project is on React 19. Blueprint is a dev-only dep (poi supplies it at runtime), so override its react/react-dom peers with the root specs instead of bumping the major. - vite@8, pulled in by @storybook/react-vite, peer-optionals @types/node ^20.19 || >=22.12, so bump @types/node from 18 to 22. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
KochiyaOcean
force-pushed
the
fix/rank-ignore-unknown-enemy-hp
branch
from
August 9, 2026 15:49
8fd8db1 to
63fd403
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enemies with unknown HP no longer spoil the rank
The game reports the HP of some enemies as a non-numeric placeholder (currently the string
'N/A'). lib-battle'ssimulateBattleRankused to count every enemy:'N/A' <= 0is false, so such an enemy was never counted as sunk and the HP totals turned intoNaN. A battle where every other enemy was destroyed could therefore never be predicted as S.poi-lib-battle@3.2.0fixes this at the source —_initEnemyflags a ship ashpUnknownwhen the packet's maxhp/nowhp is not a number, and the rank formula skips those ships (it also guards the all-unknown case, where there is nothing left to judge by). This PR takes that version, so no workaround ships in the plugin.The one plugin-side change: Prophet builds its own enemy ships for base defense in
initEnemy, so it now sets the samehpUnknownflag, keeping those ships consistent with the ones lib-battle builds.src/utils/lib-battle-adapter.test.tskeeps the behaviour pinned as a regression check on the library contract Prophet now depends on: the flag is set for non-numeric HP; sinking every enemy with a known HP reaches SS (S when damaged); a surviving known-HP enemy does not; an all-unknown enemy fleet is no victory.Unblocking
npm installIndependent of the fix.
npm installfailed with ERESOLVE on two pre-existing peer conflicts:@blueprintjs/core@4peersreact ^16.8 || 17 || 18while the project is on React 19. Blueprint is a dev-only dependency (poi supplies it at runtime, and onlyCollapseis imported), so bumping the major would misalign with what poi actually ships — instead itsreact/react-dompeers are overridden with the root specs via$react/$react-dom, which stays in sync if React is bumped again.vite@8, pulled in through@storybook/react-vite, peer-optionals@types/node ^20.19 || >=22.12;@types/nodegoes from 18 to 22 (types only).Deliberately not
.npmrcwithlegacy-peer-deps=true, which would silence real conflicts too.Verification
Typecheck clean, lint clean (
--max-warnings=0), 35/35 tests pass, and both the plugin build and the Storybook build succeed.🤖 Generated with Claude Code