mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
- Added a new quest preference "Do Not Play AI Matches" which allows the player to decide the outcome of AI vs. AI matches randomly instead of playing them out and thus simulating them. This is disabled by default, set to "1" to enable.
- Currently determines the outcome of all AI vs. AI matches in a 50-50 fashion. Might be upgraded later to bias the outcome towards a stronger deck judging by the total card draft rating value.
This commit is contained in:
@@ -16,12 +16,15 @@ import forge.match.HostedMatch;
|
||||
import forge.model.FModel;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.quest.data.QuestPreferences;
|
||||
import forge.tournament.system.TournamentBracket;
|
||||
import forge.tournament.system.TournamentPairing;
|
||||
import forge.tournament.system.TournamentPlayer;
|
||||
import forge.util.MyRandom;
|
||||
import forge.util.storage.IStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class QuestDraftUtils {
|
||||
@@ -146,6 +149,11 @@ public class QuestDraftUtils {
|
||||
latestSet--;
|
||||
}
|
||||
|
||||
if (latestSet == currentStandings.length - 1) {
|
||||
// No more matches left
|
||||
return;
|
||||
}
|
||||
|
||||
//Fill in any missing spots in previous brackets
|
||||
boolean foundMatchups = false;
|
||||
for (int i = 0; i <= latestSet && i <= 14; i += 2) {
|
||||
@@ -262,6 +270,15 @@ public class QuestDraftUtils {
|
||||
gui.enableOverlay();
|
||||
|
||||
final DraftMatchup nextMatch = matchups.remove(0);
|
||||
|
||||
if (FModel.getQuestPreferences().getPrefInt(QuestPreferences.QPref.RANDOMLY_DECIDE_AI_VS_AI) == 1) {
|
||||
// the user asked to decide the AI vs AI match randomly, so just call the UI update and leave the rest to injection code
|
||||
if (injectRandomMatchOutcome(false)) {
|
||||
update(gui);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
matchInProgress = true;
|
||||
|
||||
if (nextMatch.hasHumanPlayer()) {
|
||||
@@ -394,4 +411,28 @@ public class QuestDraftUtils {
|
||||
return humanPlayer != null;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean injectRandomMatchOutcome(boolean simHumanMatches) {
|
||||
QuestEventDraft qd = FModel.getQuest().getAchievements().getCurrentDraft();
|
||||
|
||||
int pos = Arrays.asList(qd.getStandings()).indexOf(QuestEventDraft.UNDETERMINED);
|
||||
int offset = (pos - 8) * 2;
|
||||
|
||||
String sid1 = qd.getStandings()[offset];
|
||||
String sid2 = qd.getStandings()[offset + 1];
|
||||
|
||||
if (sid1.equals(QuestEventDraft.HUMAN) || sid2.equals(QuestEventDraft.HUMAN)) {
|
||||
if (!simHumanMatches) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: bias the outcome towards a deck with higher total card draft rating value instead of going 50-50
|
||||
boolean randomWinner = MyRandom.getRandom().nextBoolean();
|
||||
qd.getStandings()[pos] = randomWinner ? sid1 : sid2;
|
||||
|
||||
FModel.getQuest().save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import forge.properties.ForgePreferences.FPref;
|
||||
import forge.quest.QuestDraftUtils.Mode;
|
||||
import forge.quest.QuestEventDraft.QuestDraftFormat;
|
||||
import forge.quest.data.QuestAchievements;
|
||||
import forge.quest.data.QuestPreferences;
|
||||
import forge.tournament.system.TournamentBracket;
|
||||
import forge.tournament.system.TournamentPairing;
|
||||
import forge.tournament.system.TournamentPlayer;
|
||||
@@ -459,5 +460,11 @@ public class QuestTournamentController {
|
||||
|
||||
gui = GuiBase.getInterface().getNewGuiGame();
|
||||
QuestDraftUtils.startNextMatch(gui);
|
||||
|
||||
if (FModel.getQuestPreferences().getPrefInt(QuestPreferences.QPref.RANDOMLY_DECIDE_AI_VS_AI) == 1) {
|
||||
// need to force a view update after a random match outcome was injected into standings
|
||||
view.populate();
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,9 @@ public class QuestPreferences extends PreferencesStore<QuestPreferences.QPref> i
|
||||
PLAYSET_ANY_NUMBER_SIZE("500"),
|
||||
PLAYSET_BASIC_LAND_SIZE("50"),
|
||||
|
||||
ITEM_LEVEL_RESTRICTION("1");
|
||||
ITEM_LEVEL_RESTRICTION("1"),
|
||||
|
||||
RANDOMLY_DECIDE_AI_VS_AI("0");
|
||||
|
||||
private final String strDefaultVal;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user