Commit 1e52e580 authored by Justin White's avatar Justin White

no message

parent 414c0b6b
package forge.screens.home.gengrid;
import java.util.ArrayList;
/**
* Created by AquamentosGames on 07/06/2018.
*/
public class GridBoORound implements Runnable{
private static GridBoORound ourInstance;
public static GridBoORound getInstance() {
return ourInstance;
}
public static int maxGames = 3;
public static int roundRuns = 0;
GridTribe[] tribes = new GridTribe[2];
public GridBoOMatch[] matches = new GridBoOMatch[25];
private long roundStart;
public boolean finished = false;
int completedCount = 0;
int killcount;
static boolean firstWatch = true;
int isWatching = -1;
public double k_value;
private boolean myView = true;
public GridBoORound(GridTribe t1, GridTribe t2, double k, boolean view) {
if (t1.getRunCount() < 10 || t2.getRunCount() < 10)
k *= 2;
ourInstance = this;
k_value = k;
tribes[0] = t1;
tribes[1] = t2;
myView = view;
}
public static boolean skipNumber(int n, int tier){
if (tier >= 2)
return false;
if (tier == 0)
return (n % 5 >= 3 || n > 14);
return (n % 5 == 4 || n > 19);
}
public GridBoOMatch createMatch(GridDeck t1, GridDeck t2){
if (t1.getBoOLosses()>=t1.tribe.lossCap() && t2.getBoOLosses()>=t2.tribe.lossCap())
return null;
GridBoOMatch match = new GridBoOMatch(t1, t2, k_value);
matches[match.matchID()] = match;
return match;
}
public boolean pending (int max) {
GridBoOMatch currentMatch;
GridBoOMatch restartMatch;
ArrayList<GridBoOMatch> pendList = new ArrayList<>();
ArrayList<GridBoOMatch> runList = new ArrayList<>();
if (isWatching >= 0) {
// check if the game we are watching is over
currentMatch = matches[isWatching];
if (currentMatch == null || !currentMatch.started || currentMatch.completed)
isWatching = -1;
}
for (int x = 0; x < matches.length; x++) {
currentMatch = matches[x];
if (currentMatch == null)
continue;
if (currentMatch.started && !currentMatch.completed)
runList.add(currentMatch);
else if (!currentMatch.started)
pendList.add(currentMatch);
}
pendList.sort(GridBoOMatch.matchViewComparator);
runList.sort(GridBoOMatch.matchViewComparator);
// if (runList.size() == 1 && runList.get(0).getGameDuration() / 1000 > 100)
// runList.get(0).forceKillGame(); // we are only waiting on one game that's stalled
restartMatch = null;
//isWatching = false;
for (GridBoOMatch match : runList) {
if (match.matchError) {
System.out.println("Match Error Detected!");
restartMatch = match;
break;
}
}
if (restartMatch != null) {
cloneMatch(restartMatch);
}
update();
if (pendList.size() == 0 && runList.size() <= 0)
return true;
GridBoOMatch match;
boolean watchDelay = firstWatch && (System.currentTimeMillis() - roundStart) < 10000;
boolean trywatch = false;
//GridUtilities.Log("watchDelay: "+watchDelay+"\t"+(System.currentTimeMillis()-roundStart));
while (runList.size() < max && pendList.size() > 0) {
trywatch = false;
//GridUtilities.Log(" "+myView+" "+!watchDelay+" "+isWatching);
if (myView && !watchDelay && isWatching < 0) {
match = pendList.get(0);
trywatch = true;
//GridUtilities.Log(" TryWatch: "+trywatch);
} else
match = pendList.get(pendList.size()-1);
if (match.startMatch(trywatch)) {
if (trywatch) {
isWatching = match.matchID();
if (firstWatch) {
firstWatch = false;
match.gameStart += 60000; //first match takes a bit to load
}
else
GridTourney.sleep(1000);
}
}
if (match.started){
pendList.remove(match);
runList.add(match);
}
}
GridTourney.sleep(1000);
//System.out.println("Matches: "+matches.size());
return false;
}
private void completeMatch(GridMatch match) {
//tribes[0].teamPoints += match.matchPoints[0];
//tribes[1].teamPoints += match.matchPoints[1];
}
public void update(){
int counter = 0;
StringBuilder sb = new StringBuilder();
// checking if all completed
int incomplete = 0;
for (GridBoOMatch m : matches) {
if (m != null)
m.update();
if ( m == null || m.completed )
counter++;
else if (m.started && !m.completed) {
incomplete++;
sb.append(m.toString() + "\n");
}
}
if (counter != completedCount){
System.out.println("Completed: "+counter+"/"+matches.length);
System.out.println(sb.toString());
completedCount = counter;
}
if (completedCount >= matches.length) finished = true;
}
private void deadTier(GridTribe gt){
for (int i =0; i<25; i++){
if (gt.decks[i] != null && gt.decks[i].getBoOLosses()<gt.lossCap()){
if (skipNumber(i,gt.tier())){
while (gt.decks[i].getBoOLosses()<gt.lossCap())
gt.decks[i].addBoOResult(false);
}
}
}
}
public GridDeck[] sortDecks(GridDeck g1, GridDeck g2){
GridDeck[] a = new GridDeck[]{g1, g2};
GridDeck[] b = new GridDeck[]{g2, g1};
if (g1.getBoOLosses()>=g1.tribe.lossCap())
return b;
if (g2.getBoOLosses()>=g2.tribe.lossCap())
return a;
if (g2.getBoOWins() > g1.getBoOWins())
return b;
if (g1.getBoOWins() > g2.getBoOWins())
return a;
if (g2.surviveCount() > g1.surviveCount())
return b;
if (g1.surviveCount() > g2.surviveCount())
return a;
if (g2.getElo() > g1.getElo())
return b;
if (g1.getElo() > g2.getElo())
return a;
return a;
}
public void run() {
roundRuns++;
roundStart = System.currentTimeMillis();
tribes[0].loadAllDecks();
tribes[1].loadAllDecks();
deadTier(tribes[0]);
deadTier(tribes[1]);
GridUtilities.Log(tribes[0].getViewName() +" ["+tribes[0].getElo()+"] vs "+tribes[1].getViewName()+" ["+tribes[1].getElo()+"]");
GridBoOMatch match;
GridDeck[] a1 = new GridDeck[2];
GridDeck[] a2 = new GridDeck[2];
GridDeck buff;
int minTeir = Math.min(tribes[0].tier(), tribes[1].tier());
for (int x=0; x<13; x++) {
if (x == 12)
match = createMatch(tribes[0].decks[x], tribes[1].decks[x]);
else {
a1 = sortDecks(tribes[0].decks[x],tribes[0].decks[24-x]);
a2 = sortDecks(tribes[1].decks[x],tribes[1].decks[24-x]);
// if the weaker decks are both kicked out...
if (a1[1].getBoOLosses()>=3 && a2[1].getBoOLosses()>=3){
// we only pair the first ones
match = createMatch(a1[0], a2[0]);
} else {
// pair better with weaker
match = createMatch(a1[0], a2[1]);
match = createMatch(a1[1], a2[0]);
}
}
}
while (!finished) {
pending(maxGames);
try {
Thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
}
long sctm = System.currentTimeMillis();
GridBoOMatch gm;
finished = true;
for (int m = 0; m < matches.length; m++) {
gm = matches[m];
if ( gm == null || gm.completed ) continue;
finished = false;
if ( gm.started ) {
if ( gm.recectCheck > 0 && sctm - gm.recectCheck > 10000 ) {
System.out.println("Something's wrong (run)!");
gm.wrongCount++;
if (gm.wrongCount >= 2) {
gm.awardGameDraw();
gm.wrongCount = 0;
} else {
cloneMatch(gm);
}
}
}
}
}
}
public void cloneMatch(GridBoOMatch rm){
if (rm == null)
return;
if (rm.clones < 3) {
matches[rm.matchID()] = new GridBoOMatch(rm);
} else {
rm.forceKillMatch();
}
killcount++;
if (killcount >= 7){
GridTourney.activeTourney.tokenAndQuit("Too many games aborted!",-42);
}
}
}
......@@ -292,6 +292,34 @@ public class GridDeck {
int i = Integer.parseInt(s);
return i;
}
public int getBoOWins(){
String s = deckProperties.getProperty("BoOWins","0");
int i = Integer.parseInt(s);
return i;
}
public int getBoOLosses(){
String s = deckProperties.getProperty("BoOLosses","0");
int i = Integer.parseInt(s);
return i;
}
public int getBoOBreakers(){
String s = deckProperties.getProperty("BoOBreakers","0");
int i = Integer.parseInt(s);
return i;
}
public void addBoOResult(boolean win){
if (getBoOLosses() < 3){
if (win)
deckProperties.setProperty("BoOWins",(getBoOWins()+1)+"");
else
deckProperties.setProperty("BoOLosses",(getBoOLosses()+1)+"");
} else {
if (win)
deckProperties.setProperty("BoOBreakers",(getBoOBreakers()+1)+"");
}
setSave();
}
public double getGamePerc(){
if (getGames() == 0) return 0;
return (double) getGamePoints()/(double) (getGames()*3);
......@@ -321,11 +349,15 @@ public class GridDeck {
setSave();
}
public void resetStandings(){
deckProperties.setProperty("MatchesPlayed","0");
deckProperties.setProperty("GamePoints","0");
deckProperties.setProperty("GamesPlayed","0");
deckProperties.setProperty("MatchPoints","0");;
public void resetStandings() {
deckProperties.setProperty("MatchesPlayed", "0");
deckProperties.setProperty("GamePoints", "0");
deckProperties.setProperty("GamesPlayed", "0");
deckProperties.setProperty("MatchPoints", "0");
deckProperties.setProperty("BoOWins", "0");
deckProperties.setProperty("BoOLosses", "0");
deckProperties.setProperty("BoOBreakers", "0");
setSave();
}
......@@ -660,6 +692,7 @@ public class GridDeck {
}
public void createSeed(){
//System.out.println("Creating Seed: "+tribe.getViewName());
if (!tribe.archetype.seeds.containsKey(tribe.colour) ||
tribe.archetype.seeds.get(tribe.colour).size() == 0){
for (RenColour rc : tribe.archetype.seeds.keySet()){
......@@ -997,6 +1030,25 @@ public class GridDeck {
return 0;
}
};
public static Comparator<GridDeck> breedBoOComparitor = new Comparator<GridDeck>() {
@Override
public int compare(GridDeck o1, GridDeck o2) {
if ( o1.getBoOWins() < o2.getBoOWins() ) return 1;
if ( o1.getBoOWins() > o2.getBoOWins() ) return -1;
if ( o1.getBoOLosses() < o2.getBoOLosses() ) return 1;
if ( o1.getBoOLosses() > o2.getBoOLosses() ) return -1;
if ( o1.getBoOBreakers() < o2.getBoOBreakers() ) return 1;
if ( o1.getBoOBreakers() > o2.getBoOBreakers() ) return -1;
if ( o1.getElo() < o2.getElo() ) return 1;
if ( o1.getElo() > o2.getElo() ) return -1;
return 0;
}
};
public static Comparator<GridDeck> adjustedEloComparitor = new Comparator<GridDeck>() {
@Override
public int compare(GridDeck o1, GridDeck o2) {
......@@ -1337,7 +1389,7 @@ public class GridDeck {
}
public String standingsDisplay(){
return id+" ["+getGeneration()+" +"+surviveCount()+"]: "+getMatchPoints()+"/"+getGamePoints()+" "+getElo();
return id+" ["+getGeneration()+" +"+surviveCount()+"]: "+getBoOWins()+"-"+getBoOLosses()+" "+getElo();
}
private void mutate() {
......
......@@ -298,8 +298,8 @@ public enum GridFormat {
ArrayList<GridTribe> workArray;
GridTribe test;
for (GridTribe gt : GridTribe.tribeList){
if (gt.getRunCount() < 10)
continue;
//if (gt.getRunCount() < 10)
// continue;
if (gt.colour.getIdent().length >= 3 || gt.colour.equals(RenColour.Colourless))
continue;
if (gt.set.format != this || gt.getElo() < 1000 + Math.min(50,gt.getRunCount()))
......@@ -325,8 +325,8 @@ public enum GridFormat {
}
RenColour c;
for (GridTribe gt : GridTribe.tribeList) {
if (gt.getRunCount() < 10)
continue;
//if (gt.getRunCount() < 10)
// continue;
if (gt.colour.getIdent().length < 3 && gt.colour != RenColour.Colourless)
continue;
if (gt.set.format != this || gt.getElo() < 1000 + Math.min(50,gt.getRunCount()))
......@@ -358,7 +358,7 @@ public enum GridFormat {
for (RenColour rc : bests.keySet()){
workArray = bests.get(rc);
workArray.sort(GridTribe.ratingComparator);
while (workArray.size() > 3 && workArray.get(workArray.size()-1).getElo()<1090)
while (workArray.size() > 3 && workArray.get(workArray.size()-1).getElo()<Math.max(best-100,1050))
workArray.remove(workArray.size() - 1);
algt.addAll(bests.get(rc));
}
......
......@@ -723,6 +723,15 @@ public class GridMatch extends HostedMatch {
@Override
public int compare(GridMatch o1, GridMatch o2) {
if (o1.players[0].getMatchPerc() < o2.players[0].getMatchPerc())
return 1;
if (o1.players[0].getMatchPerc() > o2.players[0].getMatchPerc())
return -1;
if (o1.players[0].surviveCount() < o2.players[0].surviveCount())
return 1;
if (o1.players[0].surviveCount() > o2.players[0].surviveCount())
return -1;
double c1 = o1.players[0].getAdjustedElo() + o1.players[1].getAdjustedElo();
double c2 = o2.players[0].getAdjustedElo() + o2.players[1].getAdjustedElo();
......
......@@ -779,7 +779,7 @@ public class GridSet {
themes = new String[]{"Artifact","Historic","Saproling","Legend","Instant","Sorcery","Enchantment",
"Hexproof","Haste","Flash","First Strike","Vigilance","Trample","Fight","Menace","Extra Turn",
"Search","Draw","Exile","LifeGain","Graveyard","Prowess","Skulk","Deathtouch","Discard","Sacrifice",
"Deathtouch","Wall","Copy","Land","Devil","Bat","Return","Enters","Defender","Sea","Undead","Elfball","Aether","Lifelink","Blocker",
"Deathtouch","Wall","Copy","Land","Devil","Bat","Return","Enters","Defender","Sea","Undead","Fiendish","Elfball","Aether","Lifelink","Blocker",
"Colourless","Reanimator","Drain","Prevent","Dies","Battlefield","Freebies","Indestructible", "Abilities"};
String seed = themes[rand.nextInt(themes.length)];
checkThemeColours(seed);
......
......@@ -38,6 +38,8 @@ public class GridTourney implements Runnable {
seededOnly = forceArch == null && rand.nextInt(100)<15;
}
public static boolean overTime = false;
public static void sleep(long millis){
try{
Thread.sleep(millis);
......@@ -497,6 +499,45 @@ public class GridTourney implements Runnable {
main.miniBreaker();
foe.miniBreaker();
startBoORound(main, foe);
}
public void startBoORound(GridTribe main, GridTribe foe){
GridBoORound rr = new GridBoORound(main, foe, doBestTribe ? 16 : 8, viewGames);
Thread t = new Thread(rr);
sleep(1000);
t.start();
while (t.isAlive()) {
sleep(1000);
}
main.setNoRe(foe);
foe.setNoRe(main);
SaveAll();
main.checkBreed();
foe.checkBreed();
main.compareTribe(foe);
foe.compareTribe(main);
gameCount ++;
if (gameCount < 12 && !overTime) {
if (forceArch == null && ((doBestDeck && foe.getElo() < main.getElo()) ||
(gameCount <= 2 && main.bredOne && !foe.bredOne))) {
forceHigh = false;
SaveAll();
start = System.currentTimeMillis();
getFoe(foe);
} else if (!main.bredOne) {
SaveAll();
start = System.currentTimeMillis();
getFoe(main);
}
}
}
public void startRound(GridTribe main, GridTribe foe){
GridRound rr = new GridRound(main, foe, doBestTribe ? 16 : 8, viewGames);
Thread t = new Thread(rr);
sleep(1000);
......
......@@ -679,23 +679,37 @@ public class GridTribe {
}
public void checkBreed(){
if (tribeProperties.getProperty("NoRe","").split("_").length < 3 + id)
return;
GridUtilities.Log("Do Breed for: "+getViewName());
public int winCap(){
return getElo() >= 1050 ? 7 : 5;
}
public int lossCap(){
return getElo() >= 1050 ? 3 : 2;
}
for (int x = 0; x<25; x++) {
breedChecks[x] = false;
if (GridRound.skipNumber(x,tier()))
breedChecks[x] = true;
public int maxBoOWins(){
loadAllDecks();
int ret = 0;
for (GridDeck gd : decks){
if (gd.getBoOWins()>ret)
ret = gd.getBoOWins();
}
return ret;
}
public int minBoOLosses(){
loadAllDecks();
int ret = 3;
for (GridDeck gd : decks){
if (gd.getBoOLosses()<ret)
ret = gd.getBoOLosses();
}
return ret;
}
public boolean doneBoOGauntlet(){
return (maxBoOWins() >= winCap() || minBoOLosses() >= lossCap());
}
boolean done = false;
private void updateCardPool(){
ArrayList<GridDeck> potentials = new ArrayList<>();
for (int x = 0; x < 25; x++)
potentials.add(getDeck(x));
......@@ -713,6 +727,119 @@ public class GridTribe {
pool.addCounts(potentials);
}
}
public void checkBoOBreed(){
GridUtilities.Log("Check Breed for: "+getViewName()+" Wins: "+maxBoOWins()+" Losses: "+minBoOLosses());
if (!doneBoOGauntlet())
return;
GridUtilities.Log("Do Breed for: "+getViewName()+" Wins: "+maxBoOWins()+" Losses: "+minBoOLosses());
//System.exit(1337);
for (int x = 0; x<25; x++) {
breedChecks[x] = false;
//if (GridRound.skipNumber(x,tier()))
// breedChecks[x] = true;
}
boolean done = false;
updateCardPool();
ArrayList<GridDeck> potentials = new ArrayList<>();
while (!done){
potentials.clear();
for (int x = 0; x < 25; x++){
if (!breedChecks[x])
potentials.add(getDeck(x));
}
if (potentials.size()==0){
done = true;
break;
}
potentials.sort(GridDeck.breedBoOComparitor);
GridDeck fat = potentials.get(0);
ArrayList<GridDeck> neigh = getNeighbours(fat.id);
if (neigh.size() > 0 && (fat.getBoOWins() + fat.getBoOBreakers() >0 )) {
neigh.sort(GridDeck.breedBoOComparitor);
GridDeck mot = null;
boolean doit = false;
for (int x = 0; x<neigh.size(); x++){
if (mot == null)
mot = neigh.get(0);
if (x == neigh.size()-1)
doit = true;
else {
doit = ShivaUtility.rand.nextInt(100) > 20;
if (!fat.determineColour().contains(mot.determineColour()))
doit = !doit; // invert the chance.
}
if (doit){
mot = neigh.get(x);
break;
}
}
GridUtilities.Log(fat.standingsDisplay()+" -> "+mot.standingsDisplay());
mot.setSurviveCount(0);
fat.setSurviveCount(fat.surviveCount()+1);
mot.breedOver(fat);
mot.saveSettings();
fat.saveSettings();
breedChecks[fat.id] = true;
breedChecks[mot.id] = true;
} else if (fat.getBoOBreakers() + fat.getBoOWins() == 0) {
GridUtilities.Log("Not enough wins to be father: "+fat.standingsDisplay());
fat.setSurviveCount(0);
fat.randomOver();
fat.saveSettings();
breedChecks[fat.id] = true;
} else {
GridUtilities.Log("Alone: "+fat.standingsDisplay());
fat.setSurviveCount(0);
fat.randomOver();
fat.saveSettings();
breedChecks[fat.id] = true;
}
}
finishRun();
}
public void checkBreed(){
checkBoOBreed();
if (true) // skip the rest;
return;
if (tribeProperties.getProperty("NoRe","").split("_").length < 3 + id)
return;
GridUtilities.Log("Do Breed for: "+getViewName());
for (int x = 0; x<</