mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
AI: removed outdated AIMinimax project (#7075), removed some useless player classes, code and config files, improved docs;
This commit is contained in:
parent
6ac2f44cc1
commit
08b99fcbf7
40 changed files with 103 additions and 2462 deletions
|
|
@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
|
|||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ComputerPlayerMCTS extends ComputerPlayer implements Player {
|
||||
public class ComputerPlayerMCTS extends ComputerPlayer {
|
||||
|
||||
private static final int THINK_MIN_RATIO = 40;
|
||||
private static final int THINK_MAX_RATIO = 100;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.player.ai;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -15,6 +14,10 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* AI: server side bot with monte carlo logic (experimental, the latest version)
|
||||
* <p>
|
||||
* Simple implementation for random play, outdate and do not support,
|
||||
* see <a href="https://github.com/magefree/mage/issues/7075">more details here</a>
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
|
|
@ -51,22 +54,19 @@ public class MCTSPlayer extends ComputerPlayer {
|
|||
public List<Ability> getPlayableOptions(Game game) {
|
||||
List<Ability> all = new ArrayList<>();
|
||||
List<ActivatedAbility> playables = getPlayableAbilities(game);
|
||||
for (ActivatedAbility ability: playables) {
|
||||
for (ActivatedAbility ability : playables) {
|
||||
List<Ability> options = game.getPlayer(playerId).getPlayableOptions(ability, game);
|
||||
if (options.isEmpty()) {
|
||||
if (!ability.getManaCosts().getVariableCosts().isEmpty()) {
|
||||
simulateVariableCosts(ability, all, game);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
all.add(ability);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (Ability option: options) {
|
||||
} else {
|
||||
for (Ability option : options) {
|
||||
if (!ability.getManaCosts().getVariableCosts().isEmpty()) {
|
||||
simulateVariableCosts(option, all, game);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
all.add(option);
|
||||
}
|
||||
}
|
||||
|
|
@ -137,7 +137,7 @@ public class MCTSPlayer extends ComputerPlayer {
|
|||
|
||||
private List<List<UUID>> copyEngagement(List<List<UUID>> engagement) {
|
||||
List<List<UUID>> newEngagement = new ArrayList<>();
|
||||
for (List<UUID> group: engagement) {
|
||||
for (List<UUID> group : engagement) {
|
||||
newEngagement.add(new ArrayList<>(group));
|
||||
}
|
||||
return newEngagement;
|
||||
|
|
@ -154,7 +154,7 @@ public class MCTSPlayer extends ComputerPlayer {
|
|||
List<Permanent> remaining = remove(blockers, blocker);
|
||||
for (int i = 0; i < numGroups; i++) {
|
||||
if (game.getCombat().getGroups().get(i).canBlock(blocker, game)) {
|
||||
List<List<UUID>>newEngagement = copyEngagement(engagement);
|
||||
List<List<UUID>> newEngagement = copyEngagement(engagement);
|
||||
newEngagement.get(i).add(blocker.getId());
|
||||
engagements.add(newEngagement);
|
||||
// logger.debug("simulating -- found redundant block combination");
|
||||
|
|
|
|||
|
|
@ -24,11 +24,13 @@ import java.io.Serializable;
|
|||
import java.util.*;
|
||||
|
||||
/**
|
||||
* plays randomly
|
||||
* AI: helper class to simulate games with MCTS AI (each player replaced by simulated)
|
||||
* <p>
|
||||
* Plays randomly
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class SimulatedPlayerMCTS extends MCTSPlayer {
|
||||
public final class SimulatedPlayerMCTS extends MCTSPlayer {
|
||||
|
||||
private boolean isSimulatedPlayer;
|
||||
private int actionCount = 0;
|
||||
|
|
@ -98,28 +100,13 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
|
|||
ability.addManaCostsToPay(new GenericManaCost(RandomUtil.nextInt(amount)));
|
||||
}
|
||||
}
|
||||
// check if ability kills player, if not then it's ok to play
|
||||
// if (ability.isUsesStack()) {
|
||||
// Game testSim = game.copy();
|
||||
// activateAbility((ActivatedAbility) ability, testSim);
|
||||
// StackObject testAbility = testSim.getStack().pop();
|
||||
// testAbility.resolve(testSim);
|
||||
// testSim.applyEffects();
|
||||
// testSim.checkStateAndTriggered();
|
||||
// if (!testSim.getPlayer(playerId).hasLost()) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
break;
|
||||
// }
|
||||
}
|
||||
return ability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean triggerAbility(TriggeredAbility source, Game game) {
|
||||
// logger.info("trigger");
|
||||
if (source != null && source.canChooseTarget(game, playerId)) {
|
||||
Ability ability;
|
||||
List<Ability> options = getPlayableOptions(source, game);
|
||||
|
|
@ -153,7 +140,6 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
|
|||
@Override
|
||||
public void selectAttackers(Game game, UUID attackingPlayerId) {
|
||||
//useful only for two player games - will only attack first opponent
|
||||
// logger.info("select attackers");
|
||||
UUID defenderId = game.getOpponents(playerId).iterator().next();
|
||||
List<Permanent> attackersList = super.getAvailableAttackers(defenderId, game);
|
||||
//use binary digits to calculate powerset of attackers
|
||||
|
|
@ -177,7 +163,6 @@ public class SimulatedPlayerMCTS extends MCTSPlayer {
|
|||
|
||||
@Override
|
||||
public void selectBlockers(Ability source, Game game, UUID defendingPlayerId) {
|
||||
// logger.info("select blockers");
|
||||
int numGroups = game.getCombat().getGroups().size();
|
||||
if (numGroups == 0) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue