Difference between revisions of "Team:Carnegie Mellon/game"

Line 167: Line 167:
 
if(this.object==undefined){ return;}
 
if(this.object==undefined){ return;}
 
 
if(this.isComputer & this.children.length==0 & this.parent == -1){
+
if(this.isComputer){
spawnAIComputer();
+
if(this.children.length==0){
 +
if(this.parent == -1){
 +
spawnAIComputer();
 +
}
 +
}
 
}
 
}
 
 
Line 213: Line 217:
 
var substrates = Substrate.GetSubstrates();
 
var substrates = Substrate.GetSubstrates();
 
for(var i=0;i<substrates.length;i++){
 
for(var i=0;i<substrates.length;i++){
if(substrates[i].object!=undefined & this.isTouching(substrates[i])){
+
if(substrates[i].object!=undefined){
this.luminescence += SUBSTRATEVALUE;
+
if(this.isTouching(substrates[i])){
if(this.luminescence > MAXLUMINANCE){
+
this.luminescence += SUBSTRATEVALUE;
this.luminescence = MAXLUMINANCE;
+
if(this.luminescence > MAXLUMINANCE){
 +
this.luminescence = MAXLUMINANCE;
 +
}
 +
substrates[i].destroy();
 
}
 
}
substrates[i].destroy();
 
 
}
 
}
 
}
 
}
Line 229: Line 235:
 
var foods = Food.GetFood();
 
var foods = Food.GetFood();
 
for(var i=0;i<foods.length;i++){
 
for(var i=0;i<foods.length;i++){
if(foods[i].object!=undefined & this.isTouching(foods[i])){
+
if(foods[i].object!=undefined){
this.resize(this.radius+foods[i].radius/2);
+
if(this.isTouching(foods[i])){
foods[i].destroy();
+
this.resize(this.radius+foods[i].radius/2);
 +
foods[i].destroy();
 +
}
 
}
 
}
 
}
 
}
Line 245: Line 253:
 
if(curCell.object!=undefined){
 
if(curCell.object!=undefined){
 
for(var j=0;j<curCell.children;j++){
 
for(var j=0;j<curCell.children;j++){
if(this.isTouching(curCell.children[j]) & this.distance(curCell.children[j])<this.radius){
+
if(this.isTouching(curCell.children[j])){
if(curCell.children[j].radius<this.radius*EATINGRATIO){
+
if(this.distance(curCell.children[j])<this.radius){
ateSomething = true;
+
if(curCell.children[j].radius<this.radius*EATINGRATIO){
this.resize(this.radius+curCell.children[j]/2);
+
ateSomething = true;
curCell.children[j].destroy();
+
this.resize(this.radius+curCell.children[j]/2);
 +
curCell.children[j].destroy();
 +
}
 
}
 
}
 
}
 
}
 
}
 
}
if(this.isTouching(curCell) & this.distance(curCell)<this.radius){
+
if(this.isTouching(curCell)){
if(curCell.radius<this.radius*EATINGRATIO){
+
if(this.distance(curCell)<this.radius){
ateSomething = true;
+
if(curCell.radius<this.radius*EATINGRATIO){
this.resize(this.radius+curCell.radius/2);
+
ateSomething = true;
curCell.destroy();
+
this.resize(this.radius+curCell.radius/2);
 +
curCell.destroy();
 +
}
 
}
 
}
 
}
 
}
Line 271: Line 283:
 
var spikes = Spike.GetSpikes();
 
var spikes = Spike.GetSpikes();
 
for(var i=0;i<spikes.length;i++){
 
for(var i=0;i<spikes.length;i++){
if(spikes[i].object!=undefined & this.radius>spikes[i].radius*1.5 & this.isTouching(spikes[i])){
+
if(spikes[i].object!=undefined){
this.split();
+
if(this.radius>spikes[i].radius*1.5){
spikes[i].destroy();
+
if(this.isTouching(spikes[i])){
break;
+
this.split();
 +
spikes[i].destroy();
 +
break;
 +
}
 +
}
 
}
 
}
 
}
 
}
Line 325: Line 341:
 
for(var j=0;j<curCell.children.length;j++){
 
for(var j=0;j<curCell.children.length;j++){
 
if(curCell.children[j] != this){
 
if(curCell.children[j] != this){
if(curCell.children[j].object!=undefined &
+
if(curCell.children[j].object!=undefined){
curCell.children[j].radius<this.radius*EATINGRATIO & this.distance(curCell.children[j])<sight){
+
if(curCell.children[j].radius<this.radius*EATINGRATIO){
prey = curCell.children[j];
+
if(this.distance(curCell.children[j])<sight){
sight = this.distance(prey);
+
prey = curCell.children[j];
 +
sight = this.distance(prey);
 +
}
 +
}
 
}
 
}
 
}
 
}
 
}
 
}
 
if(curCell != this){
 
if(curCell != this){
if(curCell.object!=undefined & curCell.radius<this.radius*EATINGRATIO & this.distance(curCell)<sight){
+
if(curCell.object!=undefined){
prey = curCell;
+
if(curCell.radius<this.radius*EATINGRATIO){
sight = this.distance(prey);
+
if(this.distance(curCell)<sight){
 +
prey = curCell;
 +
sight = this.distance(prey);
 +
}
 +
}
 
}
 
}
 
}
 
}
 
}
 
}
if(curCell.object!=undefined & curCell.size*EATINGRATIO>this.size & this.distance(curCell)<this.radius*5){ //this cell can eat me and is close
+
if(curCell.object!=undefined){
var difference = [curCell.center[0]-this.center[0],curCell.center[1]-this.center[1]];
+
if(curCell.size*EATINGRATIO>this.size){
gottaRun[0] += difference[0];
+
if(this.distance(curCell)<this.radius*5){ //this cell can eat me and is close
gottRun[0] += difference[1];
+
var difference = [curCell.center[0]-this.center[0],curCell.center[1]-this.center[1]];
 +
gottaRun[0] += difference[0];
 +
gottRun[0] += difference[1];
 +
}
 +
}
 
}
 
}
 
}
 
}
Line 361: Line 388:
 
if(sight>proximity){ //if something is in proximity do immediately (else look for better)
 
if(sight>proximity){ //if something is in proximity do immediately (else look for better)
 
var curFood = foods[i];
 
var curFood = foods[i];
if(curFood!=undefined & this.distance(curFood)<sight){
+
if(curFood!=undefined){
food = curFood;
+
if(this.distance(curFood)<sight){
sight = this.distance(curFood);
+
food = curFood;
 +
sight = this.distance(curFood);
 +
}
 
}
 
}
 
}
 
}
Line 380: Line 409:
 
if(sight>proximity){ //if something is in proximity do immediately (else look for better)
 
if(sight>proximity){ //if something is in proximity do immediately (else look for better)
 
var curSubstrate = substrates[i];
 
var curSubstrate = substrates[i];
if(curSubstrate!=undefined & this.distance(curSubstrate)<sight){
+
if(curSubstrate!=undefined){
substrate = curSubstrate;
+
if(this.distance(curSubstrate)<sight){
sight = this.distance(curSubstrate);
+
substrate = curSubstrate;
 +
sight = this.distance(curSubstrate);
 +
}
 
}
 
}
 
}
 
}
Line 703: Line 734:
 
for(var i=0;i<_computers.length;i++){
 
for(var i=0;i<_computers.length;i++){
 
var computer = _computers[i];
 
var computer = _computers[i];
if(computer!=undefined & computer.object!=undefined){
+
if(computer!=undefined){
computer.enemyMovementAI();
+
if(computer.object!=undefined){
 +
computer.enemyMovementAI();
 +
}
 
}
 
}
 
}
 
}

Revision as of 14:21, 29 June 2015

Luciferase: The Game