public void Prepare(IMonster monster) { CellAreaInfo areaInfo = monster.AreaInfo as CellAreaInfo; CellArea area = areaInfo.Area as CellArea; int x = areaInfo.X; int y = areaInfo.Y; int startBit = 0; startBit = SetContentType(startBit, area.GetCellAt(x, y - 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x - 1, y - 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x + 1, y - 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x - 1, y).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x + 1, y).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x - 1, y + 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x + 1, y + 1).ContentType); startBit = SetContentType(startBit, area.GetCellAt(x, y + 1).ContentType); }
public IMonster AddNewMonster(Genome genome) { int x, y; Cell cell = null; do { x = Common.Random.Next(Width); y = Common.Random.Next(Height); cell = cells[x, y]; }while (cell.ContentType == ContentType.Monster || cell.ContentType == ContentType.Wall); if (cell.ContentType == ContentType.Food) { UsedEnergy -= FOOD_ENERGY; } UsedEnergy += MONSTER_INIT_ENERGY; IAreaInfo areaInfo = new CellAreaInfo { Area = this, X = x, Y = y }; IMonster monster = new SimpleMonster.Monster(genome, areaInfo); monster.Energy = MONSTER_INIT_ENERGY; monster.Sensors.Add(viewSensor); monster.Sensors.Add(collisionSensor); monster.Actions.Add(new MoveAction()); Monsters.Add(monster); cell.Content = monster; cell.ContentType = ContentType.Monster; return(monster); }
public Cell GetCellAt(CellAreaInfo areaInfo) { return(GetCellAt(areaInfo.X, areaInfo.Y)); }
public void Do(IMonster monster) { CellAreaInfo areaInfo = monster.AreaInfo as CellAreaInfo; CellArea area = areaInfo.Area as CellArea; int x = areaInfo.X; int y = areaInfo.Y; int moveNr = (this[0] ? 1 : 0) + (this[1] ? 2 : 0); switch (moveNr) { case 0: y--; break; case 1: y++; break; case 2: x--; break; case 3: x++; break; } Collision = false; Cell targetCell = area.GetCellAt(x, y); switch (targetCell.ContentType) { case ContentType.Empty: areaInfo.MoveTo(x, y); break; case ContentType.Wall: Collision = true; break; case ContentType.Food: monster.Energy += CellArea.FOOD_ENERGY; targetCell.ContentType = ContentType.Empty; break; case ContentType.Monster: Collision = true; if (monster.Energy < CellArea.MONSTER_ACTIVE_SEX_ENERGY) { break; } IMonster targetMonster = (IMonster)targetCell.Content; if (targetMonster.Energy < CellArea.MONSTER_PASSIVE_SEX_ENERGY) { break; } Genome genome = sex.MakeChild(monster.Brain.Genome, targetMonster.Brain.Genome); if (genome != null) { monster.Energy -= CellArea.MONSTER_INIT_ENERGY * 0.5; targetMonster.Energy -= CellArea.MONSTER_INIT_ENERGY * 0.5; area.UsedEnergy -= CellArea.MONSTER_INIT_ENERGY; SimpleMonster.Monster m = area.AddNewMonster(genome) as SimpleMonster.Monster; m.Parents = (monster as SimpleMonster.Monster).Parents + "S"; } //else //{ // // Get energy from target monster // targetMonster.Energy -= CellArea.FOOD_ENERGY; // monster.Energy += CellArea.FOOD_ENERGY; //} break; } }