mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
tests: added tests for auto-lands suggestion in deck editor and tourney (related to #13127)
This commit is contained in:
parent
40e2cf7cda
commit
2955535927
4 changed files with 180 additions and 21 deletions
|
|
@ -6,12 +6,12 @@ import java.util.Set;
|
|||
|
||||
public final class DeckBuildUtils {
|
||||
|
||||
/**
|
||||
* Returns the number of basic lands suggested to complete a deck
|
||||
* as an array of five ints: plains, islands, swamps, mountains, forests
|
||||
* Total number of lands always sufficient to reach deckSize
|
||||
*/
|
||||
public static int[] landCountSuggestion(int deckSize, Set<Card> deckList) {
|
||||
/*
|
||||
Returns the number of basic lands suggested to complete a deck
|
||||
as an array of five ints: plains, islands, swamps, mountains, forests
|
||||
Total number of lands always sufficient to reach deckSize
|
||||
*/
|
||||
int plains = 0, islands = 0, swamps = 0, mountains = 0, forests = 0;
|
||||
int landsNeeded = deckSize - deckList.size();
|
||||
if (landsNeeded > 0) {
|
||||
|
|
@ -51,9 +51,4 @@ public final class DeckBuildUtils {
|
|||
}
|
||||
return new int[] {plains, islands, swamps, mountains, forests};
|
||||
}
|
||||
|
||||
// Hide constructor - not to be instantiated
|
||||
private DeckBuildUtils() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,12 @@ public final class TournamentUtil {
|
|||
/**
|
||||
* Tries to calculate the most appropriate sets to add basic lands for cards of a deck
|
||||
*
|
||||
* @param setCodesDeck
|
||||
* @return setCode for lands
|
||||
* @param setCodesDeck all sets in current deck
|
||||
*/
|
||||
|
||||
public static Set<String> getLandSetCodeForDeckSets(Collection<String> setCodesDeck) {
|
||||
|
||||
Set<String> landSetCodes = new HashSet<>();
|
||||
// decide from which sets basic lands are taken from
|
||||
|
||||
// from deck's sets
|
||||
for (String setCode : setCodesDeck) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
if (expansionInfo.hasBasicLands() && !CardRepository.haveSnowLands(setCode)) {
|
||||
|
|
@ -30,7 +28,7 @@ public final class TournamentUtil {
|
|||
}
|
||||
}
|
||||
|
||||
// if sets have no basic land, take land from block
|
||||
// from deck's blocks
|
||||
if (landSetCodes.isEmpty()) {
|
||||
for (String setCode : setCodesDeck) {
|
||||
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
|
||||
|
|
@ -42,10 +40,9 @@ public final class TournamentUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
// if still no set with lands found, take one by random
|
||||
|
||||
// from random
|
||||
if (landSetCodes.isEmpty()) {
|
||||
// if sets have no basic lands and also it has no parent or parent has no lands get last set with lands
|
||||
// select a set with basic lands by random
|
||||
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate()
|
||||
.stream()
|
||||
.filter(exp -> !CardRepository.haveSnowLands(exp.getCode()))
|
||||
|
|
@ -56,7 +53,7 @@ public final class TournamentUtil {
|
|||
}
|
||||
|
||||
if (landSetCodes.isEmpty()) {
|
||||
throw new IllegalArgumentException("No set with basic land was found");
|
||||
throw new IllegalArgumentException("No set with basic land was found (possible memory problems, need server restart)");
|
||||
}
|
||||
return landSetCodes;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue