From b498fa5ee14e358ce322c643d572d3817e08e272 Mon Sep 17 00:00:00 2001 From: Sol Date: Mon, 1 Aug 2016 14:45:32 +0000 Subject: [PATCH] - Adding some foundation for Cogwork Librarian - It seems like Booster Drafts weren't changing directions for the middle packs? --- .../controllers/CEditorDraftingProcess.java | 32 ++----- .../CEditorQuestDraftingProcess.java | 13 ++- .../src/test/java/forge/BoosterDraftTest.java | 5 ++ .../src/forge/deck/FDeckEditor.java | 2 + .../main/java/forge/limited/BoosterDraft.java | 89 +++++++++++-------- .../java/forge/limited/IBoosterDraft.java | 1 + .../main/java/forge/limited/WinstonDraft.java | 5 ++ 7 files changed, 85 insertions(+), 62 deletions(-) diff --git a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CEditorDraftingProcess.java b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CEditorDraftingProcess.java index 99ced3037df..5ea1e8bb440 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CEditorDraftingProcess.java +++ b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CEditorDraftingProcess.java @@ -102,8 +102,15 @@ public class CEditorDraftingProcess extends ACEditorBase { // get next booster pack this.boosterDraft.setChoice(card); - if (this.boosterDraft.hasNextChoice()) { - this.showChoices(this.boosterDraft.nextChoice()); + boolean nextChoice = this.boosterDraft.hasNextChoice(); + ItemPool pool = null; + if (nextChoice) { + pool = this.boosterDraft.nextChoice(); + nextChoice = pool != null && !pool.isEmpty(); + } + + if (nextChoice) { + this.showChoices(pool); } else { this.saveDraft(); @@ -155,27 +162,6 @@ public class CEditorDraftingProcess extends ACEditorBase { // add sideboard to deck deck.getOrCreate(DeckSection.Sideboard).addAll(this.getDeckManager().getPool()); - //no need to add basic lands now that Add Basic Lands button exists - /*final String landSet = IBoosterDraft.LAND_SET_CODE[0].getCode(); - final boolean isZendikarSet = landSet.equals("ZEN"); // we want to generate one kind of Zendikar lands at a time only - final boolean zendikarSetMode = MyRandom.getRandom().nextBoolean(); - - final int landsCount = 10; - - for(String landName : MagicColor.Constant.BASIC_LANDS) { - int numArt = FModel.getMagicDb().getCommonCards().getArtCount(landName, landSet); - int minArtIndex = isZendikarSet ? (zendikarSetMode ? 1 : 5) : 1; - int maxArtIndex = isZendikarSet ? minArtIndex + 3 : numArt; - - if (FModel.getPreferences().getPrefBoolean(FPref.UI_RANDOM_ART_IN_POOLS)) { - for (int i = minArtIndex; i <= maxArtIndex; i++) { - deck.get(DeckSection.Sideboard).add(landName, landSet, i, numArt > 1 ? landsCount : 30); - } - } else { - deck.get(DeckSection.Sideboard).add(landName, landSet, 30); - } - }*/ - return deck; } // getPlayersDeck() diff --git a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CEditorQuestDraftingProcess.java b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CEditorQuestDraftingProcess.java index 7eca9744ad8..66e995d4594 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CEditorQuestDraftingProcess.java +++ b/forge-gui-desktop/src/main/java/forge/screens/deckeditor/controllers/CEditorQuestDraftingProcess.java @@ -110,11 +110,18 @@ public class CEditorQuestDraftingProcess extends ACEditorBase pool = null; + if (nextChoice) { + pool = this.boosterDraft.nextChoice(); + nextChoice = !pool.isEmpty(); + } + + if (nextChoice) { + this.showChoices(pool); } else { - saveDraft(); + this.saveDraft(); } } diff --git a/forge-gui-desktop/src/test/java/forge/BoosterDraftTest.java b/forge-gui-desktop/src/test/java/forge/BoosterDraftTest.java index 79344975380..47ea68649e5 100644 --- a/forge-gui-desktop/src/test/java/forge/BoosterDraftTest.java +++ b/forge-gui-desktop/src/test/java/forge/BoosterDraftTest.java @@ -74,6 +74,11 @@ public class BoosterDraftTest implements IBoosterDraft { return this.n > 0; } + @Override + public boolean isRoundOver() { + return hasNextChoice(); + } + /** *

* getChosenCards. diff --git a/forge-gui-mobile/src/forge/deck/FDeckEditor.java b/forge-gui-mobile/src/forge/deck/FDeckEditor.java index 488dd6559f9..c26e0f9641c 100644 --- a/forge-gui-mobile/src/forge/deck/FDeckEditor.java +++ b/forge-gui-mobile/src/forge/deck/FDeckEditor.java @@ -1361,6 +1361,8 @@ public class FDeckEditor extends TabPageScreen { BoosterDraft draft = parentScreen.getDraft(); draft.setChoice(card); + // TODO Implement handling of extra boosters + if (draft.hasNextChoice()) { refresh(); } diff --git a/forge-gui/src/main/java/forge/limited/BoosterDraft.java b/forge-gui/src/main/java/forge/limited/BoosterDraft.java index 4f8211907c7..e80a6d612a9 100644 --- a/forge-gui/src/main/java/forge/limited/BoosterDraft.java +++ b/forge-gui/src/main/java/forge/limited/BoosterDraft.java @@ -50,6 +50,8 @@ public class BoosterDraft implements IBoosterDraft { protected int nextBoosterGroup = 0; private int currentBoosterSize = 0; private int currentBoosterPick = 0; + private int[] draftingBooster; + private List> pack; // size 8 /** The draft picks. */ @@ -171,14 +173,6 @@ public class BoosterDraft implements IBoosterDraft { protected BoosterDraft() { this.draftFormat = LimitedPoolType.Full; } - /** - *

- * Constructor for BoosterDraft_1. - *

- * - * @param draftType - * a {@link java.lang.String} object. - */ protected BoosterDraft(final LimitedPoolType draftType) { this.draftAI.setBd(this); this.draftFormat = draftType; @@ -237,13 +231,26 @@ public class BoosterDraft implements IBoosterDraft { */ @Override public CardPool nextChoice() { - if (this.pack.get(this.getCurrentBoosterIndex()).isEmpty()) { + if (this.isRoundOver()) { + // If all packs are depleted crack 8 new packs this.pack = this.get8BoosterPack(); + if (this.pack == null) { + return null; + } } this.computerChoose(); + final CardPool result = new CardPool(); result.addAllFlat(this.pack.get(this.getCurrentBoosterIndex())); + + if (result.isEmpty()) { + // Can't set a card, since none are available. Just pass "empty" packs. + this.passPacks(); + // Recur until we find a cardpool or finish + return nextChoice(); + } + return result; } @@ -267,55 +274,64 @@ public class BoosterDraft implements IBoosterDraft { this.nextBoosterGroup++; this.currentBoosterSize = list.get(0).size(); this.currentBoosterPick = 0; + draftingBooster = new int[]{0, 1, 2, 3, 4, 5, 6, 7}; return list; } - // size 7, all the computers decks + public void addSingleBoosterPack(int player, boolean random) { + // TODO Cogwork Librarian + } - /** - *

- * getDecks. - *

- * - * @return an array of {@link forge.deck.Deck} objects. - */ + // size 7, all the computers decks @Override public Deck[] getDecks() { return this.draftAI.getDecks(); } + public void passPacks() { + // Alternate direction of pack passing + int adjust = this.nextBoosterGroup % 2 == 1 ? 1 : -1; + for(int i = 0; i < N_PLAYERS; i++) { + draftingBooster[i] = (draftingBooster[i] + adjust + pack.size()) % pack.size(); + } + } + protected void computerChoose() { - final int iHumansBooster = this.getCurrentBoosterIndex(); - int iPlayer = 0; - for (int i = 1; i < this.pack.size(); i++) { - final List booster = this.pack.get((iHumansBooster + i) % this.pack.size()); - final PaperCard aiPick = this.draftAI.choose(booster, iPlayer++); - booster.remove(aiPick); + // Loop through players 1-7 to draft their current pack + for (int i = 1; i < N_PLAYERS; i++) { + final List booster = this.pack.get(this.draftingBooster[i]); + + // Empty boosters can happen in a Conspiracy draft + if (!booster.isEmpty()) { + booster.remove(this.draftAI.choose(booster, i-1)); + } } } // computerChoose() /** * - * Get the current booster index. + * Get the current booster index for the Human * @return int */ public int getCurrentBoosterIndex() { - return this.currentBoosterPick % BoosterDraft.N_PLAYERS; + return this.draftingBooster[0]; } - /** - *

- * hasNextChoice. - *

- * - * @return a boolean. - */ + @Override + public boolean isRoundOver() { + for(List singlePack : this.pack) { + if (!singlePack.isEmpty()) { + return false; + } + } + + return true; + } + + @Override public boolean hasNextChoice() { - final boolean isLastGroup = this.nextBoosterGroup >= this.product.size(); - final boolean isBoosterDepleted = this.currentBoosterPick >= this.currentBoosterSize; - final boolean noMoreCards = isLastGroup && isBoosterDepleted; - return !noMoreCards; + return this.nextBoosterGroup < this.product.size() || !this.isRoundOver(); } /** {@inheritDoc} */ @@ -355,6 +371,7 @@ public class BoosterDraft implements IBoosterDraft { thisBooster.remove(c); this.currentBoosterPick++; + this.passPacks(); } // setChoice() @Override diff --git a/forge-gui/src/main/java/forge/limited/IBoosterDraft.java b/forge-gui/src/main/java/forge/limited/IBoosterDraft.java index 6b252fdf3e0..103d2afa965 100644 --- a/forge-gui/src/main/java/forge/limited/IBoosterDraft.java +++ b/forge-gui/src/main/java/forge/limited/IBoosterDraft.java @@ -58,6 +58,7 @@ public interface IBoosterDraft { * @return a boolean. */ boolean hasNextChoice(); + boolean isRoundOver(); /** *

diff --git a/forge-gui/src/main/java/forge/limited/WinstonDraft.java b/forge-gui/src/main/java/forge/limited/WinstonDraft.java index 78663f1d89f..cf336ad6bfd 100644 --- a/forge-gui/src/main/java/forge/limited/WinstonDraft.java +++ b/forge-gui/src/main/java/forge/limited/WinstonDraft.java @@ -126,6 +126,11 @@ public class WinstonDraft extends BoosterDraft { return getNextChoice(0) >= 0; } + @Override + public boolean isRoundOver() { + return hasNextChoice(); + } + public boolean isLastPileAndEmptyDeck(final int pile) { return this.deck.size() == 0 && getNextChoice(pile+1) >= 0; }