mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
Added the possibility to force AI to play cards in cheat mode.
This commit is contained in:
parent
3c8e5d4ea2
commit
6933c5a9f3
4 changed files with 63 additions and 13 deletions
|
@ -56,10 +56,8 @@ import mage.players.Player;
|
|||
import mage.target.Target;
|
||||
import mage.target.TargetCard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
|
@ -81,11 +79,15 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
protected int currentScore;
|
||||
protected SimulationNode2 root;
|
||||
|
||||
private static final String FILE_WITH_INSTRUCTIONS = "config/ai.please.cast.this.txt";
|
||||
private List<String> suggested = new ArrayList<String>();
|
||||
|
||||
public ComputerPlayer6(String name, RangeOfInfluence range, int skill) {
|
||||
super(name, range);
|
||||
maxDepth = skill * 2;
|
||||
maxThink = skill * 3;
|
||||
maxNodes = Config2.maxNodes;
|
||||
getSuggestedActions();
|
||||
}
|
||||
|
||||
public ComputerPlayer6(final ComputerPlayer6 player) {
|
||||
|
@ -773,7 +775,7 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
|
||||
for (Player copyPlayer: sim.getState().getPlayers().values()) {
|
||||
Player origPlayer = game.getState().getPlayers().get(copyPlayer.getId());
|
||||
SimulatedPlayer2 newPlayer = new SimulatedPlayer2(copyPlayer.getId(), copyPlayer.getId().equals(playerId));
|
||||
SimulatedPlayer2 newPlayer = new SimulatedPlayer2(copyPlayer.getId(), copyPlayer.getId().equals(playerId), suggested);
|
||||
newPlayer.restore(origPlayer);
|
||||
sim.getState().getPlayers().put(copyPlayer.getId(), newPlayer);
|
||||
}
|
||||
|
@ -795,4 +797,26 @@ public class ComputerPlayer6 extends ComputerPlayer<ComputerPlayer6> implements
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void getSuggestedActions() {
|
||||
try {
|
||||
File file = new File(FILE_WITH_INSTRUCTIONS);
|
||||
if (file.exists()) {
|
||||
Scanner scanner = new Scanner(file);
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if (line.startsWith("cast:") || line.startsWith("play:")) {
|
||||
suggested.add(line.substring(5, line.length()));
|
||||
}
|
||||
}
|
||||
System.out.println("suggested::");
|
||||
for (int i = 0; i < suggested.size(); i++) {
|
||||
System.out.println(" " + suggested.get(i));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// swallow
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,12 +28,8 @@
|
|||
|
||||
package mage.player.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbility;
|
||||
|
@ -43,6 +39,7 @@ import mage.abilities.costs.mana.ManaCost;
|
|||
import mage.abilities.costs.mana.ManaCosts;
|
||||
import mage.abilities.costs.mana.VariableManaCost;
|
||||
import mage.abilities.mana.ManaOptions;
|
||||
import mage.cards.Card;
|
||||
import mage.choices.Choice;
|
||||
import mage.filter.FilterAbility;
|
||||
import mage.game.Game;
|
||||
|
@ -50,6 +47,7 @@ import mage.game.combat.Combat;
|
|||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.StackAbility;
|
||||
import mage.sets.innistrad.UnholyFiend;
|
||||
import mage.target.Target;
|
||||
import mage.util.Logging;
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -66,10 +64,13 @@ public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
|
|||
private transient ConcurrentLinkedQueue<Ability> allActions;
|
||||
private static PassAbility pass = new PassAbility();
|
||||
|
||||
public SimulatedPlayer2(UUID id, boolean isSimulatedPlayer) {
|
||||
private List<String> suggested;
|
||||
|
||||
public SimulatedPlayer2(UUID id, boolean isSimulatedPlayer, List<String> suggested) {
|
||||
super(id);
|
||||
pass.setControllerId(playerId);
|
||||
this.isSimulatedPlayer = isSimulatedPlayer;
|
||||
this.suggested = suggested;
|
||||
}
|
||||
|
||||
public SimulatedPlayer2(final SimulatedPlayer2 player) {
|
||||
|
@ -101,6 +102,7 @@ public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
|
|||
ManaOptions available = getManaAvailable(game);
|
||||
available.addMana(manaPool.getMana());
|
||||
List<Ability> playables = game.getPlayer(playerId).getPlayable(game, filter, available, isSimulatedPlayer);
|
||||
playables = filterAbilities(game, playables, suggested);
|
||||
for (Ability ability: playables) {
|
||||
List<Ability> options = game.getPlayer(playerId).getPlayableOptions(ability, game);
|
||||
if (options.size() == 0) {
|
||||
|
@ -141,6 +143,29 @@ public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
|
|||
// }
|
||||
// }
|
||||
|
||||
protected List<Ability> filterAbilities(Game game, List<Ability> playables, List<String> suggested) {
|
||||
if (playables.isEmpty()) {
|
||||
return playables;
|
||||
}
|
||||
if (suggested == null || suggested.isEmpty()) {
|
||||
return playables;
|
||||
}
|
||||
List<Ability> filtered = new ArrayList<Ability>();
|
||||
for (Ability ability : playables) {
|
||||
Card card = game.getCard(ability.getSourceId());
|
||||
for (String s : suggested) {
|
||||
if (s.equals(card.getName())) {
|
||||
System.out.println("matched: " + s);
|
||||
filtered.add(ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!filtered.isEmpty()) {
|
||||
return filtered;
|
||||
}
|
||||
return playables;
|
||||
}
|
||||
|
||||
//add a generic mana cost for each amount possible
|
||||
protected void simulateVariableCosts(Ability ability, Game game) {
|
||||
int numAvailable = getAvailableManaProducers(game).size();
|
||||
|
@ -276,5 +301,4 @@ public class SimulatedPlayer2 extends ComputerPlayer<SimulatedPlayer2> {
|
|||
public void priority(Game game) {
|
||||
//should never get here
|
||||
}
|
||||
|
||||
}
|
||||
|
|
2
Mage.Server/config/ai.please.cast.this.txt.example
Normal file
2
Mage.Server/config/ai.please.cast.this.txt.example
Normal file
|
@ -0,0 +1,2 @@
|
|||
play:Swamp
|
||||
cast:Duress
|
Binary file not shown.
Loading…
Reference in a new issue