Ignore:
Timestamp:
04/29/14 18:26:49 (11 years ago)
Author:
sz
Message:

Adjusted experiment scripts to comply with the current Framsticks API (don't use static Genotype/Creature/GenePool/Population? objects and deprecated functions)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • experiments/frams/capture-the-flag/data/scripts/capture-the-flag.expdef

    r232 r233  
    5454}
    5555
    56 function onBorn()
    57 {
    58   Creature.energ0 = 100;
    59   Creature.energy = Creature.energ0;
    60 }
    61 
    62 function onDied()
     56function onBorn(cr)
     57{
     58  cr.energ0 = 100;
     59  cr.energy = cr.energ0;
     60}
     61
     62function onDied(cr)
    6363{
    6464 
     
    8787        //Create GenePool and Population for each team
    8888        GenePools.clear();
    89         GenePool.name = "Team1";
    90         GenePool.fitness = "return this.user3;";
    91         while (GenePools[0].size > 0)
    92                 GenePools[0].delete(0);
     89        var pool=GenePools[0];
     90        pool.name = "Team1";
     91        pool.fitness = "return this.user3;";
     92        while (pool.size > 0)
     93                pool.delete(0);
    9394       
    9495        Populations.clear();
    95         Population.name = "Team1";
    96        
    97         while (Population.size > 0)
    98                         Population.delete(0);
    99        
    100        
    101        
    102         Population.selfmask = 0x50001;
    103     Population.othermask = 0x60001;
     96        var pop=Populations[0];
     97        pop.name = "Team1";
     98       
     99        while (pop.size > 0)
     100                        pop.delete(0);
     101       
     102       
     103       
     104        pop.selfmask = 0x50001;
     105    pop.othermask = 0x60001;
    104106       
    105107        var i = 2;
    106108        for (i = 2; i <= ExpParams.teamsno; i++){
    107                 Populations.addGroup("Team"+i);
    108                 Population.selfmask = 0x50001;
    109         Population.othermask = 0x60001;
    110                 GenePools.addGroup("Team"+i);
    111                 GenePool.fitness = "return this.user3;";       
     109                pop=Populations.addGroup("Team"+i);
     110                pop.selfmask = 0x50001;
     111        pop.othermask = 0x60001;
     112                pool=GenePools.addGroup("Team"+i);
     113                pool.fitness = "return this.user3;";   
    112114        }
    113115       
    114116        //Create GenePool for flags and fill it
    115         GenePools.addGroup("Flags");
    116        
    117         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag0\np:",48,"Flag","Single flag object"));
    118         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag1\np:",48,"Flag","Single flag object"));
    119         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag2\np:",48,"Flag","Single flag object"));
    120         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag3\np:",48,"Flag","Single flag object"));
    121         GenePool.addGeno(Geno.newFrom("m:Vstyle=flag4\np:",48,"Flag","Single flag object"));
     117        pool=GenePools.addGroup("Flags");
     118       
     119        pool.add(Geno.newFrom("m:Vstyle=flag0\np:",48,"Flag","Single flag object"));
     120        pool.add(Geno.newFrom("m:Vstyle=flag1\np:",48,"Flag","Single flag object"));
     121        pool.add(Geno.newFrom("m:Vstyle=flag2\np:",48,"Flag","Single flag object"));
     122        pool.add(Geno.newFrom("m:Vstyle=flag3\np:",48,"Flag","Single flag object"));
     123        pool.add(Geno.newFrom("m:Vstyle=flag4\np:",48,"Flag","Single flag object"));
    122124}
    123125
     
    127129       
    128130        //Reset all global points vectors
    129         flagsX = Vector.new();
    130         flagsY = Vector.new();
    131        
    132         points = Vector.new();
    133         scored = Vector.new();
    134         taken = Vector.new();
    135         retrieved = Vector.new();
     131        flagsX = [];
     132        flagsY = [];
     133       
     134        points = [];
     135        scored = [];
     136        taken = [];
     137        retrieved = [];
    136138       
    137139        //Init global vectors
     
    201203                        Populations[team].delete(0);
    202204               
    203                 GenePools.group = ExpParams.teamsno;
    204                 GenePools.genotype = team;
     205                var cr = Populations[team].add(GenePools[ExpParams.teamsno][team]);
     206                placeFlag(cr);
     207                cr.signals.add("Flag");
     208                cr.signals[0].flavor = team;
     209                cr.signals[0].power=1000;
     210                cr.user1 = 0;
     211                cr.user2 = 0;
     212                cr.user3 = 0;
    205213               
    206                 Populations[team].createFromGenotype();
    207                 placeFlag(Populations[team][0]);
    208                 Creature.signals.add("Flag");
    209                 Creature.signals[0].flavor = team;
    210                 Creature.signals[0].power=1000;
    211                 Creature.user1 = 0;
    212                 Creature.user2 = 0;
    213                 Creature.user3 = 0;
    214                
    215                 GenePools.group = team;
    216 
    217214                var crX, crY;
    218215               
    219216                for (player = 0; player < ExpParams.memberssno; player++){
    220                         GenePools.genotype = player % GenePool.size;
    221                         Populations[team].createFromGenotype();
     217                        var pool=GenePools[team];
     218                        cr = Populations[team].add(pool[player % pool.size]);
    222219                        crX = Math.random(30) - 15;
    223220                        if (crX >=0 && crX < 5)
     
    230227                        else if (crY > -5 && crY < 0)
    231228                                crY = -5;
    232                         Creature.moveAbs(flagsX[team] + crX, flagsY[team] + crY, 0);
    233                         Creature.user1 = 0;
    234                         Creature.user2 = 0;
    235                         Creature.user3 = 0;
     229                        cr.moveAbs(flagsX[team] + crX, flagsY[team] + crY, 0);
     230                        cr.user1 = 0;
     231                        cr.user2 = 0;
     232                        cr.user3 = 0;
    236233                }
    237234        }
     
    245242                        GenePools[team].delete(0);
    246243                if (team != 1)
    247                         GenePools[team].addGeno(Geno.newFrom("lllfffX[0:2.420, 2:-2, 1:-1][-1:1, 0:1, 0:-1][-1:1](RRlllfffMMMX[|-1:-10]lllFFFMMMX[|-2:-1], fffIXlllfffMMMsX[|6:10, 3:-10](RRlllfffMMMIX[|-4:-10]lllFFFMMMIX[|-5:-1][*], , RRlllfffMMMIX[|-7:10]lllFFFMMMIX[|-8:-1][*]), RRlllfffMMMX[|-10:10]lllFFFMMMX[|-11:-1.784])", 49, "Player", "Player"));
     244                        GenePools[team].add(Geno.newFrom("lllfffX[0:2.420, 2:-2, 1:-1][-1:1, 0:1, 0:-1][-1:1](RRlllfffMMMX[|-1:-10]lllFFFMMMX[|-2:-1], fffIXlllfffMMMsX[|6:10, 3:-10](RRlllfffMMMIX[|-4:-10]lllFFFMMMIX[|-5:-1][*], , RRlllfffMMMIX[|-7:10]lllFFFMMMIX[|-8:-1][*]), RRlllfffMMMX[|-10:10]lllFFFMMMX[|-11:-1.784])", 49, "Player", "Player"));
    248245                else if (team == 1)
    249                         GenePools[team].addGeno(Geno.newFrom("lllfffX[0:2.420, 2:-2, 1:-1][-1:1, 0:1, 0:-1][-1:1](RRlllfffMMMX[|-1:-10]lllFFFMMMX[|-2:-1], fffIXlllfffMMMsX[|1:1][Thr2,lo:-0.75,hi:0.75,t:0.75,3:-10,6:10](RRlllfffMMMIX[|-4:-10]lllFFFMMMIX[|-5:-1][FlagDef,opp:0,my:1], , RRlllfffMMMIX[|-7:10]lllFFFMMMIX[|-8:-1][FlagDef,opp:0,my:1]), RRlllfffMMMX[|-10:10]lllFFFMMMX[|-11:-1.784])", 49, "Inteligent Player", "Inteligent Player"));
     246                        GenePools[team].add(Geno.newFrom("lllfffX[0:2.420, 2:-2, 1:-1][-1:1, 0:1, 0:-1][-1:1](RRlllfffMMMX[|-1:-10]lllFFFMMMX[|-2:-1], fffIXlllfffMMMsX[|1:1][Thr2,lo:-0.75,hi:0.75,t:0.75,3:-10,6:10](RRlllfffMMMIX[|-4:-10]lllFFFMMMIX[|-5:-1][FlagDef,opp:0,my:1], , RRlllfffMMMIX[|-7:10]lllFFFMMMIX[|-8:-1][FlagDef,opp:0,my:1]), RRlllfffMMMX[|-10:10]lllFFFMMMX[|-11:-1.784])", 49, "Inteligent Player", "Inteligent Player"));
    250247        }
    251248}
     
    257254        //Update flags position if taken and cooldown if recently retrieved
    258255        for (team = 0; team < Populations.size; team++){
    259                 Populations.group = team;
    260                 Populations.creature = 0;
    261                 if (Creature.user3 > 0)
    262                         Creature.user3 -= 1;
     256                var pop=Populations[team];
     257
     258                if (pop[0].user3 > 0)
     259                        pop[0].user3 -= 1;
    263260               
    264                 for (player = 1; player < Population.size; player++){
    265                         Populations.creature = player;
    266                         if (Creature.user1 == 1){
    267                                 Creature.user2.moveAbs(Creature.pos_x, Creature.pos_y, Creature.size_z + 1);
     261                for (player = 1; player < pop.size; player++){
     262                        var cr=pop[player];
     263                        if (cr.user1 == 1){
     264                                cr.user2.moveAbs(cr.pos_x, cr.pos_y, cr.size_z + 1);
    268265                        }
    269266                }
     
    286283
    287284function placeFlag(flag){
    288         flag.moveAbs(flagsX[flag.group.index], flagsY[flag.group.index], 0);
     285        flag.moveAbs(flagsX[flag.population.index], flagsY[flag.population.index], 0);
    289286}
    290287
     
    295292       
    296293        //Take flag by changing its flavour and setting flag in player and player in flag fields
    297         flag.signals[0].flavor = flag.group.index + 100;
     294        flag.signals[0].flavor = flag.population.index + 100;
    298295        flag.user1 = 1;
    299296        flag.user2 = creature;
     
    307304       
    308305        //Update team points and events
    309         points.set(creature.group.index, points[creature.group.index] + ExpParams.pointsCapture);
    310         taken.set(creature.group.index, taken[creature.group.index] + 1);
     306        points[creature.population.index] = points[creature.population.index] + ExpParams.pointsCapture;
     307        taken[creature.population.index] = taken[creature.population.index] + 1;
    311308
    312309}
     
    314311function retrieveFlag(flag, creature){
    315312        //Retrieve flag by changing its flavour and deleting it from player and player from flag
    316         flag.signals[0].flavor = flag.group.index;
     313        flag.signals[0].flavor = flag.population.index;
    317314        flag.user1 = 0;
    318315       
     
    333330       
    334331        //Update team scores
    335         points.set(creature.group.index, points[creature.group.index] + ExpParams.pointsRetrieve);
    336         retrieved.set(creature.group.index, retrieved[creature.group.index] + 1);
     332        points[creature.population.index] = points[creature.population.index] + ExpParams.pointsRetrieve;
     333        retrieved[creature.population.index] = retrieved[creature.population.index] + 1;
    337334}
    338335
    339336function scoreFlag(flag, creature){
    340337        //Put the flag back on its spot and delete references between player and flag
    341         creature.user2.signals[0].flavor = creature.user2.group.index;
     338        creature.user2.signals[0].flavor = creature.user2.population.index;
    342339        creature.user2.user1 = 0;
    343340        creature.user2.user2 = 0;
     
    354351       
    355352        //Update team points
    356         points.set(creature.group.index, points[creature.group.index] + ExpParams.pointsScoring);
    357         scored.set(creature.group.index, scored[creature.group.index] + 1);
     353        points[creature.population.index] = points[creature.population.index] + ExpParams.pointsScoring;
     354        scored[creature.population.index] = scored[creature.population.index] + 1;
    358355}
    359356
     
    385382        if (colFlag == 1){
    386383                //Collision with my flag which is taken
    387                 if (flag.group.index == creature.group.index && flag.user1 == 1){
     384                if (flag.population.index == creature.population.index && flag.user1 == 1){
    388385                        retrieveFlag(flag, creature);
    389386                } //Collision with my flag which is not taken while carrying another team's flag
    390                 else if (flag.group.index == creature.group.index && flag.user1 == 0 && creature.user1 == 1 && flag.user3 != 1){
     387                else if (flag.population.index == creature.population.index && flag.user1 == 0 && creature.user1 == 1 && flag.user3 != 1){
    391388                        scoreFlag(flag, creature);
    392389                } //Collision with another team's flag which is not taken while not carrying any flag
    393                 else if (flag.group.index != creature.group.index && flag.user1 == 0 && creature.user1 == 0 && flag.user3 != 1){
     390                else if (flag.population.index != creature.population.index && flag.user1 == 0 && creature.user1 == 0 && flag.user3 != 1){
    394391                        takeFlag(flag, creature);
    395392                }
     
    398395        else {
    399396                //Players of different teams
    400                 if (c1.group.index != c2.group.index){
     397                if (c1.population.index != c2.population.index){
    401398                        //If player 1 has a flag ...
    402399                        if (c1.user1 == 1){
    403400                                // ... and the flag is of my team ...
    404                                 if (c2.group.index == c1.user2.group.index){
     401                                if (c2.population.index == c1.user2.population.index){
    405402                                        //... retrieve it
    406403                                        retrieveFlag(c1.user2, c2);
     
    410407                        if (c2.user1 == 1){
    411408                                // ... and the flag is of my team ...
    412                                  if (c1.group.index == c2.user2.group.index){
     409                                 if (c1.population.index == c2.user2.population.index){
    413410                                        //... retrieve it
    414411                                        retrieveFlag(c2.user2, c1);
Note: See TracChangeset for help on using the changeset viewer.