Elements the Game Forum - Free Online Fantasy Card Game

Opponents, Strategy and Decks => Random, Normal and Elder => Topic started by: antiaverage on September 19, 2015, 11:44:05 am

Title: Level 0 and Level 1 Decks
Post by: antiaverage on September 19, 2015, 11:44:05 am
People were asking about how the decks are randomly generated for Level 0 and Level 1 opponents. I will post the code from the game here, and maybe at some point I'll write up a simple explanation of how it works.

Level 0:
// When you select Level 0
if (level == 0) {
    lost = lost + 1;
}

// Generating the Level 0 deck
if (level == 0) {
    firstpillar = 0;
    firstcreature = 0;
    firstskill = 0;
    firstattack = 0;
    pvpuser = "level 0";
    _root.guide.gotoAndPlay("firstcard");
    decke = "";
    for (i = 0; i < 35; i++) {
        ran = Math.floor(Math.random() * deckan);
        temp = decka.slice(4 * ran, 4 * (ran + 1));
        decke = decke + temp;
        for (j = 0; j < 3; j++) {
            if (temp.slice(0, 1) == "0") {
                temp = temp.slice(1, 4);
            }
        }
        tempelement = Math.floor(Number(temp) / 100);
        if (Math.random() > 0.200000 && tempelement > 0) {
            temp = tempelement * 100;
            if (temp < 1000) {
                temp = "0" + temp;
            }
            i = i + 1;
            decke = decke + temp;
        }
    }
    decke = decke + "0002";
    decken = i + 1;
}
if (level == 0) {
    hpemax = 50;
}

// Winning against Level 0
if (level == 0) {
    addele(1);
    fhc = fhc + 1;
    gained = 1;
    addwon(1);
    addsco(1);
    lost = lost - 1;
    quest1 = 1;
}
if (hp >= hpmax && level != "pvp" && level != -4) {
    addele(gained);
    fhc = fhc + gained;
    gained = gained * 2;
    addsco(5 * level);
    gratz.gotoAndPlay(2);
}
if (kong == 1 && score < 1000000) {
    kongregate.stats.submit("won", won);
    kongregate.stats.submit("score", score);
    kongregate.stats.submit("lost", lost);
}

Level 1:
// When you select Level 1
if (level == 1) {
    lost = lost + 1;
    addsco(-2);
}

// Generating the Level 1 deck
if (level == 1) {
    pvpuser = "level 1";
    decke = "";
    for (i = 0; i < 49; i++) {
        ran = Math.floor(Math.random() * deckan);
        temp = decka.slice(4 * ran, 4 * (ran + 1));
        decke = decke + temp;
        for (j = 0; j < 3; j++) {
            if (temp.slice(0, 1) == "0") {
                temp = temp.slice(1, 4);
            }
        }
        tempelement = Math.floor(Number(temp) / 100);
        if (Math.random() > 0.500000 && tempelement > 0) {
            temp = tempelement * 100;
            if (temp < 1000) {
                temp = "0" + temp;
            }
            i = i + 1;
            decke = decke + temp;
        }
    }
    decke = decke + "0002";
    decken = i + 1;
}

// Winning against Level 1
if (level == 1) {
    gained = 1 + Math.floor(hp / 25);
    addele(2 + gained);
    fhc = fhc + 2 + gained;
    addwon(1);
    addsco(2 + gained);
    adjcha(1);
    lost = lost - 1;
    quest4 = 1;
    if (kong == 1) {
        kongregate.stats.submit("lvl1", 1);
    }
}
if (hp >= hpmax && level != "pvp" && level != -4) {
    addele(gained);
    fhc = fhc + gained;
    gained = gained * 2;
    addsco(5 * level);
    gratz.gotoAndPlay(2);
}
if (kong == 1 && score < 1000000) {
    kongregate.stats.submit("won", won);
    kongregate.stats.submit("score", score);
    kongregate.stats.submit("lost", lost);
}
blarg: