Skip to content

Commit

Permalink
suggested improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Northmoc committed Dec 7, 2024
1 parent 0de3bb9 commit a5e2dff
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
10 changes: 2 additions & 8 deletions forge-ai/src/main/java/forge/ai/PlayerControllerAi.java
Original file line number Diff line number Diff line change
Expand Up @@ -737,14 +737,8 @@ public String chooseSector(Card assignee, String ai, List<String> sectors) {
}

@Override
public List<String> chooseLetter(int n, String ai, List<String> letters) {
List<String> chosen = Lists.newArrayList();
for (int i = 0; i <=n; i++) {
String choice = Aggregates.random(letters);
letters.remove(choice);
chosen.add(choice);
}
return chosen;
public List<String> chooseLetter(int n, SpellAbility sa, List<String> letters) {
return Aggregates.random(letters, n);
}

@Override
Expand Down
1 change: 1 addition & 0 deletions forge-ai/src/main/java/forge/ai/simulation/GameCopier.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ private void addCard(Game newGame, ZoneType zone, Card c, Player aiPlayer) {
if (c.hasNamedCard()) {
newCard.setNamedCards(Lists.newArrayList(c.getNamedCards()));
}
if (c.hasChosenLetter()) newCard.setChosenLetters(Lists.newArrayList(c.getChosenLetters()));
newCard.setSVars(c.getSVars());
newCard.copyChangedSVarsFrom(c);
}
Expand Down
5 changes: 3 additions & 2 deletions forge-game/src/main/java/forge/game/ForgeScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import forge.util.Expressions;
import org.apache.commons.lang3.StringUtils;

import java.text.Normalizer;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -95,7 +96,7 @@ public static boolean cardStateHasProperty(CardState cardState, String property,
} else if (property.startsWith("ChosenLetter")) {
final List<String> letters = source.getChosenLetters();
if (letters == null) return false; // some things check before letters have been chosen
String name = cardState.getName();
String name = Normalizer.normalize(cardState.getName().toUpperCase(), Normalizer.Form.NFD);
if (name.startsWith("A-")) name = name.substring(2); // remove Alchemy tag
if (property.contains("FirstWord")) name = name.split(" ")[0];
boolean found = false;
Expand All @@ -108,7 +109,7 @@ public static boolean cardStateHasProperty(CardState cardState, String property,
}
} else if (property.endsWith("Contains")) {
for (String l : letters) {
if (name.contains(l) || name.contains(l.toLowerCase())) {
if (name.contains(l)) {
found = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ public class ChooseLetterEffect extends SpellAbilityEffect {
@Override
public void resolve(SpellAbility sa) {
final Card card = sa.getHostCard();
List<String> letters = Lists.newArrayList("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
List<String> letters = Lists.newArrayList("A", "B", "C", "D", "E", "É", "F", "G", "H", "I", "J", "K", "L", "M", "N",

This comment has been minimized.

Copy link
@Hanmac

Hanmac Dec 7, 2024

Contributor

Shouldn't E be normalized to E?

"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
List<String> consonants = Lists.newArrayList("B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q",
"R", "S", "T", "V", "W", "X", "Y", "Z");
List<String> choices = sa.hasParam("Consonant") ? consonants : letters;
if (sa.hasParam("Exclude")) choices.removeAll(Arrays.asList(sa.getParam("Exclude").split(",")));
int num = AbilityUtils.calculateAmount(card, sa.getParamOrDefault("Num", "1"), sa);
final List<String> chosen = card.getController().getController().chooseLetter(num,
sa.getParamOrDefault("AILogic", ""), choices);
final List<String> chosen = card.getController().getController().chooseLetter(num, sa, choices);
card.setChosenLetters(chosen);
}
}
4 changes: 4 additions & 0 deletions forge-game/src/main/java/forge/game/card/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,10 @@ public final void clearChosenNumber() {
view.clearChosenNumber();
}

public boolean hasChosenLetter() {
return chosenLetters != null && !chosenLetters.isEmpty();
}

public final List<String> getChosenLetters() {
return chosenLetters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ public Card getLKICopy(Map<Integer, Card> cachedMap) {
newCopy.setChosenType2(copyFrom.getChosenType2());
newCopy.setNamedCards(Lists.newArrayList(copyFrom.getNamedCards()));
newCopy.setChosenColors(Lists.newArrayList(copyFrom.getChosenColors()));
newCopy.setChosenLetters(Lists.newArrayList(copyFrom.getChosenLetters()));
if (copyFrom.hasChosenNumber()) {
newCopy.setChosenNumber(copyFrom.getChosenNumber());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public final void reveal(List<CardView> cards, ZoneType zone, PlayerView owner,
public abstract PlayerZone chooseStartingHand(List<PlayerZone> zones);
public abstract Mana chooseManaFromPool(List<Mana> manaChoices);

public abstract List<String> chooseLetter(int n, String ai, List<String> letters);
public abstract List<String> chooseLetter(int n, SpellAbility sa, List<String> letters);

public abstract String chooseSomeType(String kindOfType, SpellAbility sa, Collection<String> validTypes, List<String> invalidTypes, boolean isOptional);
public final String chooseSomeType(String kindOfType, SpellAbility sa, Collection<String> validTypes, List<String> invalidTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public String chooseSomeType(String kindOfType, SpellAbility sa, Collection<Stri
}

@Override
public List<String> chooseLetter(int n, String ai, List<String> letters) {
public List<String> chooseLetter(int n, SpellAbility sa, List<String> letters) {
List<String> chosen = Lists.newArrayList();
for (int i = 0; i <=n; i++) {
String choice = chooseItem(letters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ private void sortCreatureTypes(List<String> types) {
}

@Override
public List<String> chooseLetter(int n, String ai, List<String> letters) {
public List<String> chooseLetter(int n, SpellAbility sa, List<String> letters) {
List<String> chosen = Lists.newArrayList();
for (int i = 0; i < n; i++) {
String choice = getGui().one(Localizer.getInstance().getMessage("lblChooseLetter"), letters);
Expand Down

0 comments on commit a5e2dff

Please sign in to comment.