Changeset 233 for experiments/frams/capture-the-flag/data
- Timestamp:
- 04/29/14 18:26:49 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
experiments/frams/capture-the-flag/data/scripts/capture-the-flag.expdef
r232 r233 54 54 } 55 55 56 function onBorn( )57 { 58 Creature.energ0 = 100;59 Creature.energy = Creature.energ0;60 } 61 62 function onDied( )56 function onBorn(cr) 57 { 58 cr.energ0 = 100; 59 cr.energy = cr.energ0; 60 } 61 62 function onDied(cr) 63 63 { 64 64 … … 87 87 //Create GenePool and Population for each team 88 88 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); 93 94 94 95 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; 104 106 105 107 var i = 2; 106 108 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;"; 112 114 } 113 115 114 116 //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")); 122 124 } 123 125 … … 127 129 128 130 //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 = []; 136 138 137 139 //Init global vectors … … 201 203 Populations[team].delete(0); 202 204 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; 205 213 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 217 214 var crX, crY; 218 215 219 216 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]); 222 219 crX = Math.random(30) - 15; 223 220 if (crX >=0 && crX < 5) … … 230 227 else if (crY > -5 && crY < 0) 231 228 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; 236 233 } 237 234 } … … 245 242 GenePools[team].delete(0); 246 243 if (team != 1) 247 GenePools[team].add Geno(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")); 248 245 else if (team == 1) 249 GenePools[team].add Geno(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")); 250 247 } 251 248 } … … 257 254 //Update flags position if taken and cooldown if recently retrieved 258 255 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; 263 260 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); 268 265 } 269 266 } … … 286 283 287 284 function 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); 289 286 } 290 287 … … 295 292 296 293 //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; 298 295 flag.user1 = 1; 299 296 flag.user2 = creature; … … 307 304 308 305 //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; 311 308 312 309 } … … 314 311 function retrieveFlag(flag, creature){ 315 312 //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; 317 314 flag.user1 = 0; 318 315 … … 333 330 334 331 //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; 337 334 } 338 335 339 336 function scoreFlag(flag, creature){ 340 337 //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; 342 339 creature.user2.user1 = 0; 343 340 creature.user2.user2 = 0; … … 354 351 355 352 //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; 358 355 } 359 356 … … 385 382 if (colFlag == 1){ 386 383 //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){ 388 385 retrieveFlag(flag, creature); 389 386 } //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){ 391 388 scoreFlag(flag, creature); 392 389 } //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){ 394 391 takeFlag(flag, creature); 395 392 } … … 398 395 else { 399 396 //Players of different teams 400 if (c1. group.index != c2.group.index){397 if (c1.population.index != c2.population.index){ 401 398 //If player 1 has a flag ... 402 399 if (c1.user1 == 1){ 403 400 // ... 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){ 405 402 //... retrieve it 406 403 retrieveFlag(c1.user2, c2); … … 410 407 if (c2.user1 == 1){ 411 408 // ... 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){ 413 410 //... retrieve it 414 411 retrieveFlag(c2.user2, c1);
Note: See TracChangeset
for help on using the changeset viewer.