mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
AI: refactor PassAbility usage, added additional runtime checks
This commit is contained in:
parent
d57a3c100d
commit
06138ab3d3
6 changed files with 31 additions and 16 deletions
|
|
@ -24,10 +24,7 @@ import mage.game.permanent.Permanent;
|
||||||
import mage.game.stack.StackAbility;
|
import mage.game.stack.StackAbility;
|
||||||
import mage.game.stack.StackObject;
|
import mage.game.stack.StackObject;
|
||||||
import mage.player.ai.ma.optimizers.TreeOptimizer;
|
import mage.player.ai.ma.optimizers.TreeOptimizer;
|
||||||
import mage.player.ai.ma.optimizers.impl.DiscardCardOptimizer;
|
import mage.player.ai.ma.optimizers.impl.*;
|
||||||
import mage.player.ai.ma.optimizers.impl.EquipOptimizer;
|
|
||||||
import mage.player.ai.ma.optimizers.impl.LevelUpOptimizer;
|
|
||||||
import mage.player.ai.ma.optimizers.impl.OutcomeOptimizer;
|
|
||||||
import mage.player.ai.util.CombatInfo;
|
import mage.player.ai.util.CombatInfo;
|
||||||
import mage.player.ai.util.CombatUtil;
|
import mage.player.ai.util.CombatUtil;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
@ -72,6 +69,7 @@ public class ComputerPlayer6 extends ComputerPlayer /*implements Player*/ {
|
||||||
protected static final String BLANKS = "...............................................";
|
protected static final String BLANKS = "...............................................";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
optimizers.add(new WrongCodeUsageOptimizer());
|
||||||
optimizers.add(new LevelUpOptimizer());
|
optimizers.add(new LevelUpOptimizer());
|
||||||
optimizers.add(new EquipOptimizer());
|
optimizers.add(new EquipOptimizer());
|
||||||
optimizers.add(new DiscardCardOptimizer());
|
optimizers.add(new DiscardCardOptimizer());
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
public class SimulatedPlayer2 extends ComputerPlayer {
|
public class SimulatedPlayer2 extends ComputerPlayer {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(SimulatedPlayer2.class);
|
private static final Logger logger = Logger.getLogger(SimulatedPlayer2.class);
|
||||||
private static final PassAbility pass = new PassAbility();
|
|
||||||
|
|
||||||
private final boolean isSimulatedPlayer;
|
private final boolean isSimulatedPlayer;
|
||||||
private final List<String> suggested;
|
private final List<String> suggested;
|
||||||
|
|
@ -45,7 +44,6 @@ public class SimulatedPlayer2 extends ComputerPlayer {
|
||||||
public SimulatedPlayer2(Player originalPlayer, boolean isSimulatedPlayer, List<String> suggested) {
|
public SimulatedPlayer2(Player originalPlayer, boolean isSimulatedPlayer, List<String> suggested) {
|
||||||
super(originalPlayer.getId());
|
super(originalPlayer.getId());
|
||||||
this.originalPlayer = originalPlayer.copy();
|
this.originalPlayer = originalPlayer.copy();
|
||||||
pass.setControllerId(playerId);
|
|
||||||
this.isSimulatedPlayer = isSimulatedPlayer;
|
this.isSimulatedPlayer = isSimulatedPlayer;
|
||||||
this.suggested = suggested;
|
this.suggested = suggested;
|
||||||
this.userData = UserData.getDefaultUserDataView();
|
this.userData = UserData.getDefaultUserDataView();
|
||||||
|
|
@ -76,7 +74,7 @@ public class SimulatedPlayer2 extends ComputerPlayer {
|
||||||
Collections.reverse(list);
|
Collections.reverse(list);
|
||||||
|
|
||||||
if (!forced) {
|
if (!forced) {
|
||||||
list.add(pass);
|
list.add(new PassAbility());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package mage.player.ai.ma.optimizers.impl;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
|
import mage.abilities.common.PassAbility;
|
||||||
|
import mage.game.Game;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AI: runtime checks for possible errors or use case, must be added first in optimizers list
|
||||||
|
*
|
||||||
|
* @author JayDi85
|
||||||
|
*/
|
||||||
|
public class WrongCodeUsageOptimizer extends BaseTreeOptimizer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void filter(Game game, List<Ability> actions, List<Ability> actionsToRemove) {
|
||||||
|
// runtime check: pass ability must be all the time
|
||||||
|
if (actions.stream().filter(a -> a instanceof PassAbility).count() != 1) {
|
||||||
|
throw new IllegalArgumentException("Wrong code usage. AI's actions list must contains only 1 instance of PassAbility");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,9 +20,7 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
public class MCTSPlayer extends ComputerPlayer {
|
public class MCTSPlayer extends ComputerPlayer {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(MCTSPlayer.class);
|
private static final Logger logger = Logger.getLogger(MCTSPlayer.class);
|
||||||
|
|
||||||
protected PassAbility pass = new PassAbility();
|
|
||||||
|
|
||||||
private NextAction nextAction;
|
private NextAction nextAction;
|
||||||
|
|
||||||
|
|
@ -32,12 +30,10 @@ public class MCTSPlayer extends ComputerPlayer {
|
||||||
|
|
||||||
public MCTSPlayer(UUID id) {
|
public MCTSPlayer(UUID id) {
|
||||||
super(id);
|
super(id);
|
||||||
this.pass.setControllerId(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MCTSPlayer(final MCTSPlayer player) {
|
public MCTSPlayer(final MCTSPlayer player) {
|
||||||
super(player);
|
super(player);
|
||||||
this.pass = player.pass.copy();
|
|
||||||
this.nextAction = player.nextAction;
|
this.nextAction = player.nextAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,7 +44,7 @@ public class MCTSPlayer extends ComputerPlayer {
|
||||||
|
|
||||||
protected List<ActivatedAbility> getPlayableAbilities(Game game) {
|
protected List<ActivatedAbility> getPlayableAbilities(Game game) {
|
||||||
List<ActivatedAbility> playables = getPlayable(game, true);
|
List<ActivatedAbility> playables = getPlayable(game, true);
|
||||||
playables.add(pass);
|
playables.add(new PassAbility());
|
||||||
return playables;
|
return playables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import mage.game.Game;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AI only: fake ability for game simulations
|
* AI: fake ability to pass priority in game simulations
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
package mage.abilities.effects.common;
|
package mage.abilities.effects.common;
|
||||||
|
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
|
|
@ -9,6 +7,8 @@ import mage.game.Game;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* AI: fake effect to pass priority in game simulations
|
||||||
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class PassEffect extends OneShotEffect {
|
public class PassEffect extends OneShotEffect {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue