Added remaining drafts to league admin screen, also refactored the boosterDraftRun starting card collection

This commit is contained in:
marcin.sciesinski
2018-05-15 17:50:52 -07:00
parent 184e36919c
commit f1623422ec
5 changed files with 70 additions and 149 deletions

View File

@@ -204,6 +204,8 @@
Format:
<select name="format">
<option value="test_draft">Test Draft</option>
<option value="fotr_draft">Fellowship Draft</option>
<option value="ttt_draft">Two Towers Draft</option>
<option value="hobbit_draft">Hobbit Draft</option>
</select><br/>
Series duration in days: <input type="text" name="serieDuration"><br/>

View File

@@ -2,21 +2,21 @@ package com.gempukku.lotro.draft2.builder;
import com.gempukku.lotro.game.CardCollection;
import com.gempukku.lotro.game.DefaultCardCollection;
import com.google.common.collect.Iterators;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.*;
public class StartingPoolBuilder {
public CardCollectionProducer buildCardCollectionProducer(JSONObject startingPool) {
String cardCollectionProducerType = (String) startingPool.get("type");
if (cardCollectionProducerType.equals("randomCardPool")) {
return buildRandomCardPool((JSONObject) startingPool.get("data"));
} else if (cardCollectionProducerType.equals("boosterDraftRun")) {
return buildBoosterDraftRun((JSONObject) startingPool.get("data"));
}
throw new RuntimeException("Unknown cardCollectionProducer type: "+cardCollectionProducerType);
throw new RuntimeException("Unknown cardCollectionProducer type: " + cardCollectionProducerType);
}
private CardCollectionProducer buildRandomCardPool(JSONObject randomCardPool) {
@@ -43,4 +43,57 @@ public class StartingPoolBuilder {
}
};
}
private CardCollectionProducer buildBoosterDraftRun(JSONObject boosterDraftRun) {
final int runLengthInput = ((Number) boosterDraftRun.get("runLength")).intValue();
final JSONArray coreCards = (JSONArray) boosterDraftRun.get("coreCards");
final JSONArray freePeoplesRuns = (JSONArray) boosterDraftRun.get("freePeoplesRuns");
final JSONArray shadowRuns = (JSONArray) boosterDraftRun.get("shadowRuns");
return new CardCollectionProducer() {
@Override
public CardCollection getCardCollection(long seed) {
Random rnd = new Random(seed);
List<String> freePeoplesRun = ((List<List<String>>) freePeoplesRuns).get(rnd.nextInt(freePeoplesRuns.size()));
List<String> shadowRun = ((List<List<String>>) shadowRuns).get(rnd.nextInt(shadowRuns.size()));
int freePeopleLength = freePeoplesRun.size();
int shadowLength = shadowRun.size();
int runLength;
if (freePeopleLength > 0 && shadowLength > 0) {
runLength = Math.min(runLengthInput, Math.min(freePeopleLength, shadowLength));
} else if (freePeopleLength > 0) {
runLength = Math.min(runLengthInput, freePeopleLength);
} else {
runLength = Math.min(runLengthInput, shadowLength);
}
int freePeopleStart = rnd.nextInt(freePeopleLength);
int shadowStart = rnd.nextInt(shadowLength);
Iterator<String> freePeopleIterator = getCyclingIterator(freePeoplesRun, freePeopleStart, runLength);
Iterator<String> shadowIterator = getCyclingIterator(shadowRun, shadowStart, runLength);
final DefaultCardCollection draftCollection = new DefaultCardCollection();
for (String coreCard : (List<String>) coreCards) {
draftCollection.addItem(coreCard, 1);
}
while (freePeopleIterator.hasNext()) {
draftCollection.addItem(freePeopleIterator.next(), 1);
}
while (shadowIterator.hasNext()) {
draftCollection.addItem(shadowIterator.next(), 1);
}
return draftCollection;
}
};
}
private static Iterator<String> getCyclingIterator(List<String> list, int start, int length) {
Iterator<String> cycleListIterator = Iterators.cycle(list);
Iterators.skip(cycleListIterator, start);
return Iterators.limit(cycleListIterator, length);
}
}

View File

@@ -1,143 +0,0 @@
package com.gempukku.lotro.draft2.builder;
import com.gempukku.lotro.game.CardCollection;
import com.gempukku.lotro.game.DefaultCardCollection;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
public class StartingPoolBuilder {
public CardCollectionProducer buildCardCollectionProducer(JSONObject startingPool) {
String cardCollectionProducerType = (String) startingPool.get("type");
if (cardCollectionProducerType.equals("randomCardPool")) {
return buildRandomCardPool((JSONObject) startingPool.get("data"));
} else if (cardCollectionProducerType.equals("boosterDraftRun")) {
return buildBoosterDraftRun((JSONObject) startingPool.get("data"));
}
throw new RuntimeException("Unknown cardCollectionProducer type: "+cardCollectionProducerType);
}
private CardCollectionProducer buildRandomCardPool(JSONObject randomCardPool) {
JSONArray cardPools = (JSONArray) randomCardPool.get("randomResult");
final List<CardCollection> cardCollections = new ArrayList<CardCollection>();
Iterator<JSONArray> iterator = cardPools.iterator();
while (iterator.hasNext()) {
JSONArray cards = iterator.next();
DefaultCardCollection cardCollection = new DefaultCardCollection();
Iterator<String> cardIterator = cards.iterator();
while (cardIterator.hasNext()) {
cardCollection.addItem(cardIterator.next(), 1);
}
cardCollections.add(cardCollection);
}
return new CardCollectionProducer() {
@Override
public CardCollection getCardCollection(long seed) {
Random rnd = new Random(seed);
return cardCollections.get(rnd.nextInt(cardCollections.size()));
}
};
}
private CardCollectionProducer buildBoosterDraftRun(JSONObject boosterDraftRun) {
final int runLengthInput = ((Number) boosterDraftRun.get("runLength")).intValue();
final JSONArray coreCards = (JSONArray) boosterDraftRun.get("coreCards");
JSONArray freePeoplesRuns = (JSONArray) boosterDraftRun.get("freePeoplesRuns");
JSONArray shadowRuns = (JSONArray) boosterDraftRun.get("shadowRuns");
final List<List<String>> freePeoplesRunList = new ArrayList<List<String>>();
Iterator<JSONArray> freePeoplesIterator = freePeoplesRuns.iterator();
while (freePeoplesIterator.hasNext()) {
JSONArray cards = freePeoplesIterator.next();
List<String> orderedCards = new ArrayList<String>();
Iterator<String> cardIterator = cards.iterator();
while (cardIterator.hasNext()) {
orderedCards.add(cardIterator.next());
}
freePeoplesRunList.add(orderedCards);
}
final List<List<String>> shadowRunList = new ArrayList<List<String>>();
Iterator<JSONArray> shadowIterator = shadowRuns.iterator();
while (shadowIterator.hasNext()) {
JSONArray cards = shadowIterator.next();
List<String> orderedCards = new ArrayList<String>();
Iterator<String> cardIterator = cards.iterator();
while (cardIterator.hasNext()) {
orderedCards.add(cardIterator.next());
}
shadowRunList.add(orderedCards);
}
return new CardCollectionProducer() {
@Override
public CardCollection getCardCollection(long seed) {
Random rnd = new Random(seed);
List<String> freePeoplesRun = freePeoplesRunList.get(rnd.nextInt(freePeoplesRunList.size()));
List<String> shadowRun = shadowRunList.get(rnd.nextInt(shadowRunList.size()));
int runLength = 0;
if (freePeoplesRun.size() > 0 && shadowRun.size() > 0) {
runLength = Math.min(runLengthInput, Math.min(freePeoplesRun.size(), shadowRun.size()));
} else if (freePeoplesRun.size() > 0) {
runLength = Math.min(runLengthInput, freePeoplesRun.size());
} else {
runLength = Math.min(runLengthInput, shadowRun.size());
}
String[] draftRun = new String[runLength];
if (freePeoplesRun.size() > 0) {
int runSeed = rnd.nextInt() % freePeoplesRun.size();
if (runSeed + runLength > freePeoplesRun.size()) {
int runFromStart = runSeed + runLength - freePeoplesRun.size();
int runAtEnd = runLength - runFromStart;
for (int i = 0; i < runAtEnd; i++) {
draftRun[i] = freePeoplesRun.get(runSeed+i);
}
for (int i = 0; i < runFromStart; i++) {
draftRun[runAtEnd + i] = freePeoplesRun.get(i);
}
} else {
for (int i = 0; i < runLength; i++) {
draftRun[i] = freePeoplesRun.get(runSeed+i);
}
}
}
if (shadowRun.size() > 0) {
int runSeed = rnd.nextInt() % shadowRun.size();
if (runSeed + runLength > shadowRun.size()) {
int runFromStart = runSeed + runLength - shadowRun.size();
int runAtEnd = runLength - runFromStart;
for (int i = 0; i < runAtEnd; i++) {
draftRun[i] = shadowRun.get(runSeed+i);
}
for (int i = 0; i < runFromStart; i++) {
draftRun[runAtEnd + i] = shadowRun.get(i);
}
} else {
for (int i = 0; i < runLength; i++) {
draftRun[i] = shadowRun.get(runSeed+i);
}
}
}
final DefaultCardCollection draftCollection = new DefaultCardCollection();
Iterator<String> iterator = coreCards.iterator();
while (iterator.hasNext()) {
draftCollection.addItem(iterator.next(), 1);
}
for (int i = 0; i < draftRun.length; i++) {
draftCollection.addItem(draftRun[i], 1);
}
return draftCollection;
}
};
}
}

View File

@@ -46,8 +46,12 @@ public class LotroFormatLibrary {
Boolean winOnControlling5Sites = (Boolean) formatDef.get("winOnControlling5Sites");
if (winOnControlling5Sites == null)
winOnControlling5Sites = false;
Boolean limited = (Boolean) formatDef.get("limited");
if (limited == null)
limited = false;
final DefaultLotroFormat format = new DefaultLotroFormat(adventure, library, name, surveyUrl, block, true, 60, 4, true,
int maximumSameName = limited ? 20 : 4;
final DefaultLotroFormat format = new DefaultLotroFormat(adventure, library, name, surveyUrl, block, true, 60, maximumSameName, true,
cancelRingBearerSkirmish, hasRuleOfFour, winAtEndOfRegroup, winOnControlling5Sites);
JSONArray sets = (JSONArray) formatDef.get("set");

View File

@@ -245,6 +245,7 @@
"code":"limited_fotr",
"sites":"FELLOWSHIP",
"cancelRingBearerSkirmish":true,
"limited":true,
"set":[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
"hall":false
},
@@ -253,6 +254,7 @@
"code":"limited_ttt",
"sites":"TWO_TOWERS",
"cancelRingBearerSkirmish":true,
"limited":true,
"set":[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
"hall":false
},
@@ -261,6 +263,7 @@
"code":"limited_king",
"sites":"KING",
"cancelRingBearerSkirmish":true,
"limited":true,
"set":[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
"hall":false
},
@@ -269,6 +272,7 @@
"code":"limited_shadows",
"sites":"SHADOWS",
"cancelRingBearerSkirmish":false,
"limited":true,
"set":[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
"hall":false
},
@@ -345,6 +349,7 @@
"code":"limited_hobbit",
"sites":"HOBBIT",
"cancelRingBearerSkirmish":true,
"limited":true,
"set":[30, 31],
"hall":false
}