use of de.kimminich.kata.tcg.Card in project kata-tcg by bkimminich.
the class AiStrategy method collectMaxDamageCardCombo.
private void collectMaxDamageCardCombo(List<Card> selectedCards, int availableMana, List<Card> availableCards) {
for (Card card : availableCards) {
List<Card> remainingCards = new ArrayList<>(availableCards);
if (selectedCards.stream().mapToInt(Card::getValue).sum() + card.getValue() <= availableMana) {
selectedCards.add(card);
remainingCards.remove(card);
collectMaxDamageCardCombo(selectedCards, availableMana - card.getValue(), remainingCards);
}
}
}
use of de.kimminich.kata.tcg.Card in project kata-tcg by bkimminich.
the class ConsoleInputStrategy method nextMove.
@Override
public Move nextMove(int availableMana, int currentHealth, List<Card> availableCards) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
Integer card = -1;
Action action = Action.DAMAGE;
while (card < 0 || card > 8 || card > availableMana || !availableCards.contains(new Card(card))) {
try {
String input = br.readLine();
if (input.endsWith("h")) {
action = Action.HEALING;
input = input.replace("h", "");
}
card = Integer.decode(input);
} catch (NumberFormatException e) {
logger.warning("Invalid input: " + e.getMessage());
}
}
return new Move(Optional.of(new Card(card)), action);
} catch (IOException e) {
logger.severe("Could not read console input: " + e.getMessage());
e.printStackTrace();
}
return new Move(Optional.empty(), null);
}
Aggregations