GameCopier throws "Couldn't map" after Initiative or Monarch changes players

オープン 初心者向け
#13,092 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java
領域
backend

調査の方向性

Player.mapEffectCard()から始め、キャッシュされたInitiativeおよびMonarchの効果カードが、記録されたゾーンにどのように対応付けられるかを調べてください。InitiativeとMonarchの変更に関する添付の再現テストを使い、実行してGameCopier.makeCopy()が成功し、コピーが現在の保持者と有効な効果カードをちょうど1枚維持することを確認してください。

索引モデルが issue の本文から書いたものです。

説明

Describe the bug

GameCopier.makeCopy() throws a RuntimeException after the Initiative or Monarch status moves from one player to another.

The previous holder's cached effect card remains in Player.initiativeEffect or Player.monarchEffect, even though it has been removed from the Command zone.

Player.mapEffectCard() checks whether effect.getZone() is non-null but does not verify that the card is still present in that zone. Consequently, it attempts to map an effect card that was not copied.

This affects AI simulations using GameCopier, including Flat Monte Carlo rollouts.

Steps to reproduce

Using a minimal Java test with two players:

  1. Initialize a game and move to MAIN1.
  2. Call game.getAction().takeInitiative(playerA, "CLB").
  3. Call game.getAction().takeInitiative(playerB, "CLB").
  4. Call new GameCopier(game).withStack(false).makeCopy().

The copy throws a RuntimeException: Couldn't map The Initiative.

The same problem occurs when Monarch moves between players using becomeMonarch().

Expected behavior

The game copy should succeed, preserve the current Initiative or Monarch holder and contain exactly one active corresponding effect card.

An effect removed from its zone should not be passed to the object mapper.

Root cause

Zone.remove() removes the card from the zone's collection without clearing its cached zone reference. The cached effect object can be reused when a player regains the status.

However, GameCopier traverses the actual zone contents, so the removed effect card is absent from its object map.

The insufficient check is in Player.mapEffectCard().

Proposed minimal fix

Before calling the mapper, verify that the effect is still present in its recorded zone:

return effect == null || effect.getZone() == null || !effect.getZone().contains(effect)
        ? null : mapper.apply(effect);

This avoids changing the existing effect lifecycle, Zone.remove() or GameCopier.find().

Verification

Both failures were independently reproduced on an unchanged upstream master checkout.

  • Tests executed: 2
  • Passed: 0
  • Failed: 2
  • Skipped: 0

Both tests failed with the expected mapping exceptions.

The proposed patch passes git apply --check but was not applied during the upstream verification.

Environment

  • Repository: Card-Forge/forge
  • Branch: master
  • Commit: 3460eccd2629a05032e489bc3d70c082a57a1eee
  • Forge version: 2.0.17-SNAPSHOT
  • OS: Windows
  • Java: Temurin OpenJDK 17.0.17

Additional context

Related: #11203, which introduced copyEffectCardsToSnapshot() to address duplication of player-managed effect cards.

The attached ZIP contains the reproduction tests, execution instructions, upstream test results and the proposed minimal patch.

forge-issue-1-effect-mapping.zip

主要言語
Java
スター
2.7k
フォーク
1.1k
平均マージ
20時間 38分
マージ済み PR(30日)
323

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Card-Forge/forge のほかの issue

Card-Forge/forge の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。