Skip to content

fix: ignore enemies with unknown HP in rank prediction (poi-lib-battle 3.2.0) - #135

Merged
KochiyaOcean merged 1 commit into
masterfrom
fix/rank-ignore-unknown-enemy-hp
Aug 9, 2026
Merged

fix: ignore enemies with unknown HP in rank prediction (poi-lib-battle 3.2.0)#135
KochiyaOcean merged 1 commit into
masterfrom
fix/rank-ignore-unknown-enemy-hp

Conversation

@KochiyaOcean

@KochiyaOcean KochiyaOcean commented Aug 9, 2026

Copy link
Copy Markdown
Member

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's simulateBattleRank used to count every enemy: 'N/A' <= 0 is false, so such an enemy was never counted as sunk and the HP totals turned into NaN. A battle where every other enemy was destroyed could therefore never be predicted as S.

poi-lib-battle@3.2.0 fixes this at the source — _initEnemy flags a ship as hpUnknown when 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 same hpUnknown flag, keeping those ships consistent with the ones lib-battle builds.

src/utils/lib-battle-adapter.test.ts keeps 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 install

Independent of the fix. npm install 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 dependency (poi supplies it at runtime, and only Collapse is imported), so bumping the major would misalign with what poi actually ships — instead its react/react-dom peers 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/node goes from 18 to 22 (types only).

Deliberately not .npmrc with legacy-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

Copilot AI lite review requested due to automatic review settings August 9, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-finite initHP/nowHP during rank simulation, then restore fleets.
  • Update battle packet simulation flow to use simulateResult() instead of directly reading simulator.result.
  • Add unit tests covering mixed numeric/unknown HP cases and fleet immutability.
  • Update package.json (@types/node, poi-lib-battle) and add an npm overrides block 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 thread src/utils/lib-battle-adapter.ts Outdated
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 KochiyaOcean changed the title fix: ignore enemies with non-numeric HP in rank simulation fix: ignore enemies with unknown HP in rank prediction (poi-lib-battle 3.2.0) Aug 9, 2026
@KochiyaOcean
KochiyaOcean force-pushed the fix/rank-ignore-unknown-enemy-hp branch from 1d802c8 to 8fd8db1 Compare August 9, 2026 15:46
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
KochiyaOcean force-pushed the fix/rank-ignore-unknown-enemy-hp branch from 8fd8db1 to 63fd403 Compare August 9, 2026 15:49
@KochiyaOcean
KochiyaOcean merged commit 291f299 into master Aug 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants