reverted to using hash for hand, as starting hand is always the same size and this causes the hashes to collide, use the same code to generate valid choices for AI and human for Play choice

master
melvin 2011-06-28 09:25:42 +08:00
parent f86583f317
commit ee34640b06
2 changed files with 17 additions and 21 deletions

View File

@ -106,7 +106,7 @@ public class MagicPlayer implements MagicTarget {
extraTurns,
attackers,
blockers,
hand.size(),
hand.getCardsId(),
library.size(),
graveyard.getCardsId(),
exile.getCardsId(),

View File

@ -54,33 +54,29 @@ public class MagicPlayChoice extends MagicChoice {
// Pass is first choice when scores are equal.
options.add(MagicPlayChoiceResult.PASS);
// add rest of the options
addValidChoices(game, player, true, options);
return options;
}
private void addValidChoices(
final MagicGame game,
final MagicPlayer player,
final boolean useHints,
final Collection<Object> validChoices) {
final MagicActivationMap activationMap=player.getActivationMap();
for (final MagicActivation activation : activationMap.getActivations()) {
final Set<MagicSource> sources=activationMap.get(activation);
for (final MagicSource activationSource : sources) {
if (activation.canPlay(game,player,activationSource,true)) {
options.add(new MagicPlayChoiceResult(activationSource,activation));
if (activation.canPlay(game,player,activationSource,useHints)) {
validChoices.add(activationSource);
if (activation.getActivationHints().isIndependent()) {
break;
}
}
}
}
return options;
}
private Set<Object> getValidChoices(final MagicGame game,final MagicPlayer player) {
final Set<Object> validChoices=new HashSet<Object>();
final MagicActivationMap activationMap=player.getActivationMap();
for (final MagicActivation activation : activationMap.getActivations()) {
final Set<MagicSource> sources=activationMap.get(activation);
for (final MagicSource activationSource : sources) {
if (activation.canPlay(game,player,activationSource,false)) {
validChoices.add(activationSource);
}
}
}
return validChoices;
}
@Override
@ -119,8 +115,8 @@ public class MagicPlayChoice extends MagicChoice {
}
final Set<Object> validChoices;
validChoices=getValidChoices(game,player);
final Set<Object> validChoices = new HashSet<Object>();
addValidChoices(game, player, false, validChoices);
if (validChoices.isEmpty() && game.canSkipSingleChoice()) {
boolean skip = true;