Remove load from paper card call during game state copying #9339
+504
−49
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.
Problem
The AI simulation system was experiencing significant performance bottlenecks due to GameCopier.createCardCopy() calling Card.fromPaperCard() for every card copied during simulation. This method re-parses card definitions from scratch by invoking CardFactory.getCard(), which is computationally expensive when performed repeatedly across thousands of simulated game states. Profiling identified this as the most critical bottleneck in the /forge-ai module.
Solution
Implemented a new optimized code path via CardCopyService.copyStatsToGame() that efficiently copies card statistics between game instances without re-parsing card definitions. The method creates a minimal card shell using Card.newCard() and then copies all necessary state from the source card using the existing CardState.copyFrom() infrastructure. The new path preserves all card properties including types, abilities, counters, zone information, and controller/owner relationships while avoiding the expensive parsing overhead.
Testing
Added 13 comprehensive unit tests to GameSimulationTest.java covering various card scenarios: basic creatures, creatures with counters, lands, artifacts, enchantments, planeswalkers, multi-faced cards (MDFCs, transform, adventure), and tokens. These tests verify that copied cards maintain correct properties and that the simulation produces identical results compared to the original implementation.