diff --git a/shared/src/main/scala-2.12/io/equiv/eqfiddle/game/EnergyGame.scala b/shared/src/main/scala-2.12/io/equiv/eqfiddle/game/EnergyGame.scala index 18ae7dd..ea15099 100644 --- a/shared/src/main/scala-2.12/io/equiv/eqfiddle/game/EnergyGame.scala +++ b/shared/src/main/scala-2.12/io/equiv/eqfiddle/game/EnergyGame.scala @@ -24,10 +24,20 @@ trait EnergyGame extends SimpleGame with GameLazyDecision[EnergyGame.Energy] { } yield attackerVictoryPrices(s).map(w.unapplyEnergyUpdate(_)) val productMoves = possibleMoves.reduceLeft( - (b, a) => b.flatMap(i => a.map(j => i lub j))) + (b, a) => filterMinimal(b.flatMap(i => a.map(j => i lub j)))) productMoves.toSet } } + + private def filterMinimal(energies: List[Energy]) = { + // if energy list becomes big, prune dominated energies on-the-fly at defender positions + // to prevent exponential blowup of options. + if (energies.size > 2) { + energies.filterNot(e1 => energies.exists(e2 => e2 < e1)) + } else { + energies + } + } } object EnergyGame {