[avida-cvs] avida CVS commits: /current/source/cpu hardware_cpu.cc hardware_cpu.hh /current/source/main avida.cc callback_util.cc callback_util.hh organism.hh pop_interface.cc pop_interface.hh population.cc population.hh

goingssh avida-cvs at alife.org
Wed Oct 15 03:57:59 PDT 2003


goingssh		Tue Oct 14 19:57:59 2003 EDT

  Modified files:              
    /avida/current/source/cpu	hardware_cpu.cc hardware_cpu.hh 
    /avida/current/source/main	avida.cc callback_util.cc 
                              	callback_util.hh organism.hh 
                              	pop_interface.cc pop_interface.hh 
                              	population.cc population.hh 
  Log:
  commiting kaziing code to my branch
  
-------------- next part --------------
Index: avida/current/source/cpu/hardware_cpu.cc
diff -u avida/current/source/cpu/hardware_cpu.cc:1.58 avida/current/source/cpu/hardware_cpu.cc:1.59
--- avida/current/source/cpu/hardware_cpu.cc:1.58	Mon Oct 13 10:34:25 2003
+++ avida/current/source/cpu/hardware_cpu.cc	Tue Oct 14 19:57:58 2003
@@ -18,9 +18,11 @@
 #include "../main/genome_util.hh"
 #include "../main/organism.hh"
 #include "../main/phenotype.hh"
+#include "../main/genotype.hh"
 
 #include "test_cpu.hh"
 #include <limits.h>
+#include <fstream>
 
 
 using namespace std;
@@ -341,8 +343,6 @@
     cInstEntryCPU("square",    &cHardwareCPU::Inst_Square),
     cInstEntryCPU("sqrt",      &cHardwareCPU::Inst_Sqrt),
     cInstEntryCPU("not",       &cHardwareCPU::Inst_Not),
-    cInstEntryCPU("log",       &cHardwareCPU::Inst_Log),
-    cInstEntryCPU("log10",     &cHardwareCPU::Inst_Log10),
     cInstEntryCPU("minus-17",  &cHardwareCPU::Inst_Minus17),
     
     cInstEntryCPU("add",       &cHardwareCPU::Inst_Add, true,
@@ -493,6 +493,9 @@
     cInstEntryCPU("repro-Y",    &cHardwareCPU::Inst_Repro),
     cInstEntryCPU("repro-Z",    &cHardwareCPU::Inst_Repro),
 
+	// Jeff and Sherri
+	cInstEntryCPU("kazi",		&cHardwareCPU::Inst_Kazi),
+
     // Placebo instructions
     // nop-x (included with nops)
     cInstEntryCPU("skip",      &cHardwareCPU::Inst_Skip)
@@ -2724,6 +2727,23 @@
   return true;
 }
 
+
+bool cHardwareCPU::Inst_Kazi()
+{
+	const int reg_used = FindModifiedRegister(REG_AX);
+	int percentProb = Register(reg_used) % 100;
+	int random = abs(rand()) % 100;
+	if (random >= percentProb)
+	{
+		return true;
+	}
+	else
+	{
+		organism->Kaboom();
+		return true;
+	}
+}
+
 // The inject instruction can be used instead of a divide command, paired
 // with an allocate.  Note that for an inject to work, one needs to have a
 // broad range for sizes allowed to be allocated.
@@ -3127,7 +3147,7 @@
 
 bool cHardwareCPU::Inst_HeadDivideAsexWait()  
 { 
-  organism->GetPhenotype().SetDivideSex(true);
+  organism->GetPhenotype().SetDivideSex(false);
   organism->GetPhenotype().SetCrossNum(0);
   return Inst_HeadDivide(); 
 }
@@ -3211,10 +3231,7 @@
   
   // Do mutations.
   cInstruction read_inst = read_head.GetInst();
-  const bool mut_ok = (cConfig::GetSpecialMutLine() == -1)
-    || (cConfig::GetSpecialMutLine() == read_head.GetPosition());
-
-  if (mut_ok && organism->TestCopyMut()) {
+  if (organism->TestCopyMut()) {
     read_inst = GetRandomInst();
     cpu_stats.mut_stats.copy_mut_count++; 
     write_head.FlagMutated() = true;
Index: avida/current/source/cpu/hardware_cpu.hh
diff -u avida/current/source/cpu/hardware_cpu.hh:1.35 avida/current/source/cpu/hardware_cpu.hh:1.36
--- avida/current/source/cpu/hardware_cpu.hh:1.35	Wed Oct  1 12:03:46 2003
+++ avida/current/source/cpu/hardware_cpu.hh	Tue Oct 14 19:57:58 2003
@@ -8,6 +8,7 @@
 #ifndef HARDWARE_CPU_HH
 #define HARDWARE_CPU_HH
 
+#include <vector>
 #include "hardware_base.hh"
 
 #include "../defs.hh"
@@ -20,6 +21,7 @@
 #include "cpu_defs.hh"
 #include "label.hh"
 #include "head.hh"
+using namespace std;
 
 class cInstSet;
 class cInstLibBase;
@@ -367,6 +369,7 @@
   bool Inst_InjectRand();
   bool Inst_InjectThread();
   bool Inst_Repro();
+  bool Inst_Kazi();
 
   // I/O and Sensory
   bool Inst_TaskGet();
Index: avida/current/source/main/avida.cc
diff -u avida/current/source/main/avida.cc:1.45 avida/current/source/main/avida.cc:1.46
--- avida/current/source/main/avida.cc:1.45	Thu Aug  7 20:24:19 2003
+++ avida/current/source/main/avida.cc	Tue Oct 14 19:57:58 2003
@@ -192,13 +192,14 @@
   default_interface.SetFun_GetResources(&cCallbackUtil::CB_GetResources);
   default_interface.SetFun_UpdateResources(&cCallbackUtil::CB_UpdateResources);
   default_interface.SetFun_KillCell(&cCallbackUtil::CB_KillCell);
+  default_interface.SetFun_KillSurroundCell(&cCallbackUtil::CB_KillSurroundCell);
   default_interface.SetFun_SendMessage(&cCallbackUtil::CB_SendMessage);
   default_interface.SetFun_InjectParasite(&cCallbackUtil::CB_InjectParasite);
 
   population = new cPopulation(default_interface, environment);
   cout << " ...done" << endl;
 
-  // Setup Event List
+  //Setup Event List
   cout<<"Initializing Event Factory Manager..."<<flush;
   event_manager = new cEventFactoryManager;
   cStats & stats = population->GetStats();
Index: avida/current/source/main/callback_util.cc
diff -u avida/current/source/main/callback_util.cc:1.23 avida/current/source/main/callback_util.cc:1.24
--- avida/current/source/main/callback_util.cc:1.23	Thu Aug  7 20:24:19 2003
+++ avida/current/source/main/callback_util.cc	Tue Oct 14 19:57:58 2003
@@ -186,6 +186,13 @@
   pop->KillOrganism(death_cell);
 }
 
+void cCallbackUtil::CB_KillSurroundCell(cPopulation * pop, int commie_id)
+{
+	assert (pop != NULL);
+	cPopulationCell & death_cell = pop->GetCell(commie_id);
+	pop->Kaboom(death_cell);
+}
+
 bool cCallbackUtil::CB_SendMessage(cPopulation * pop, int cell_id, cOrgMessage & mess)
 {
   mess.SetSenderID(cell_id);
Index: avida/current/source/main/callback_util.hh
diff -u avida/current/source/main/callback_util.hh:1.13 avida/current/source/main/callback_util.hh:1.14
--- avida/current/source/main/callback_util.hh:1.13	Thu Aug  7 20:24:19 2003
+++ avida/current/source/main/callback_util.hh	Tue Oct 14 19:57:58 2003
@@ -40,6 +40,7 @@
   static void CB_UpdateResources(cPopulation  * pop, int cell_id,
 				 const tArray<double> & res_change);
   static void CB_KillCell(cPopulation * pop, int death_id);
+  static void CB_KillSurroundCell(cPopulation * pop, int commie_id);
   static bool CB_SendMessage(cPopulation * pop, int cell_id, cOrgMessage & mess);
   static bool CB_InjectParasite(cPopulation * pop, int cell_id, cOrganism * parent,
 				const cGenome & injected_code);
Index: avida/current/source/main/organism.hh
diff -u avida/current/source/main/organism.hh:1.25 avida/current/source/main/organism.hh:1.26
--- avida/current/source/main/organism.hh:1.25	Thu Aug  7 21:01:58 2003
+++ avida/current/source/main/organism.hh	Tue Oct 14 19:57:58 2003
@@ -10,6 +10,7 @@
 
 #include <fstream>
 #include <deque>
+#include <vector>
 
 #include "../tools/merit.hh"
 #include "../tools/tBuffer.hh"
@@ -26,6 +27,7 @@
 
 #include "../cpu/cpu_memory.hh"
 #include "../cpu/cpu_stats.hh"
+using namespace std;
 
 class cEnvironment;
 class cGenotype;
@@ -92,9 +94,10 @@
   int GetInput() { return pop_interface.GetInput(); }
   int GetInputAt(int & input_pointer) { return pop_interface.GetInputAt(input_pointer); }
   void Die() { pop_interface.Die(); }
+  void Kaboom() {pop_interface.Kaboom();}
   int GetCellID() { return pop_interface.GetCellID(); }
   int GetDebugInfo() { return pop_interface.Debug(); }
-
+  
   // Input & Output Testing
   void DoInput(const int value, tBuffer<int> & in_buf, tBuffer<int> & out_buf);
   void DoOutput(const int value, tBuffer<int> & in_buf, tBuffer<int> &out_buf);
Index: avida/current/source/main/pop_interface.cc
diff -u avida/current/source/main/pop_interface.cc:1.14 avida/current/source/main/pop_interface.cc:1.15
--- avida/current/source/main/pop_interface.cc:1.14	Thu Aug  7 20:24:19 2003
+++ avida/current/source/main/pop_interface.cc	Tue Oct 14 19:57:58 2003
@@ -32,6 +32,7 @@
   , fun_get_resources(NULL)
   , fun_update_resources(NULL)
   , fun_kill_cell(NULL)
+  , fun_kill_surround_cell(NULL)
     , fun_send_message(NULL)
     , fun_inject_parasite(NULL)
 {
@@ -59,6 +60,7 @@
   fun_get_resources    = in_interface.fun_get_resources;
   fun_update_resources = in_interface.fun_update_resources;
   fun_kill_cell        = in_interface.fun_kill_cell;
+  fun_kill_surround_cell = in_interface.fun_kill_surround_cell;
   fun_send_message     = in_interface.fun_send_message;
   fun_inject_parasite  = in_interface.fun_inject_parasite;
 }
@@ -169,6 +171,12 @@
   (*fun_kill_cell)(population, cell_id);
 }
 
+void cPopulationInterface::Kaboom()
+{
+	if (fun_kill_surround_cell == NULL) return;
+	(*fun_kill_surround_cell)(population, cell_id);
+}
+
 bool cPopulationInterface::SendMessage(cOrgMessage & mess)
 {
   if (fun_send_message == NULL) return false;
@@ -181,3 +189,4 @@
   if (fun_inject_parasite == NULL) return false;
   return (*fun_inject_parasite)(population, cell_id, parent, injected_code);
 }
+
Index: avida/current/source/main/pop_interface.hh
diff -u avida/current/source/main/pop_interface.hh:1.12 avida/current/source/main/pop_interface.hh:1.13
--- avida/current/source/main/pop_interface.hh:1.12	Thu Aug  7 20:24:19 2003
+++ avida/current/source/main/pop_interface.hh	Tue Oct 14 19:57:58 2003
@@ -39,10 +39,12 @@
 typedef void (*tFunUpdateResources)
   (cPopulation * pop, int cell_id, const tArray<double> & res_change);
 typedef void (*tFunKillCell)(cPopulation * pop, int death_id);
+typedef void (*tFunKillSurroundCell)(cPopulation * pop, int commie_id);
 typedef bool (*tFunSendMessage)(cPopulation * pop, int cell_id, cOrgMessage & mess);
 typedef bool (*tFunInjectParasite)
   (cPopulation * pop, int cell_id, cOrganism * parent, const cGenome & injected_code);
 
+
 class cPopulationInterface {
 private:
   cPopulation * population;
@@ -63,7 +65,8 @@
   tFunDebug            fun_debug;
   tFunGetResources     fun_get_resources;
   tFunUpdateResources  fun_update_resources;
-  tFunKillCell         fun_kill_cell;
+  tFunKillCell		   fun_kill_cell;
+  tFunKillSurroundCell fun_kill_surround_cell;
   tFunSendMessage      fun_send_message;
   tFunInjectParasite   fun_inject_parasite;
 public:
@@ -93,6 +96,7 @@
   void SetFun_UpdateResources(tFunUpdateResources fun)
     { fun_update_resources = fun; }
   void SetFun_KillCell(tFunKillCell fun) { fun_kill_cell = fun; }
+  void SetFun_KillSurroundCell(tFunKillSurroundCell fun) {fun_kill_surround_cell = fun; }
   void SetFun_SendMessage(tFunSendMessage fun) { fun_send_message = fun; }
   void SetFun_InjectParasite(tFunInjectParasite fun) { fun_inject_parasite = fun; }
   void CopyCallbacks(cPopulationInterface & in_interface);
@@ -114,6 +118,7 @@
   const tArray<double> & GetResources();
   void UpdateResources(const tArray<double> & res_change);
   void Die();
+  void Kaboom();
   bool SendMessage(cOrgMessage & mess);
   bool InjectParasite(cOrganism * parent, const cGenome & injected_code);
 };
Index: avida/current/source/main/population.cc
diff -u avida/current/source/main/population.cc:1.118 avida/current/source/main/population.cc:1.119
--- avida/current/source/main/population.cc:1.118	Sun Oct 12 13:07:51 2003
+++ avida/current/source/main/population.cc	Tue Oct 14 19:57:58 2003
@@ -96,49 +96,59 @@
   cell_array.Resize(num_cells);
   resource_count.ResizeSpatialGrids(world_x, world_y);
   
+  bool bottom_flag, top_flag, right_flag, left_flag;
   for (int cell_id = 0; cell_id < num_cells; cell_id++) {
     int x = cell_id % world_x;
     int y = cell_id / world_x;
     cell_array[cell_id].Setup(cell_id, default_mut_rates);
 
 
-    bool has_bottom = true;
-    bool has_top = true;
-    bool has_right = true;
-    bool has_left = true;
-
-    if (geometry == GEOMETRY_GRID) {
-      if (y == 0) has_bottom = false;
-      if (y == world_y-1) has_top = false;
-      if (x == 0) has_left = false;
-      if (x == world_x-1) has_right = false;
+    if ((y == 0) && (geometry == GEOMETRY_GRID)) {
+      bottom_flag = false;
+    } else {
+      bottom_flag = true;
+    }
+    if ((y == world_y-1) && (geometry == GEOMETRY_GRID)) {
+      top_flag = false;
+    } else {
+      top_flag = true;
+    }
+    if ((x == 0) && (geometry == GEOMETRY_GRID)) {
+      left_flag = false;
+    } else {
+      left_flag = true;
+    }
+    if ((x == world_x-1) && (geometry == GEOMETRY_GRID)) {
+      right_flag = false;
+    } else {
+      right_flag = true;
     }
 
     // Setup the connection list for each cell. (Clockwise from -1 to 1)
 
     tList<cPopulationCell> & conn_list=cell_array[cell_id].ConnectionList();
-    if (has_bottom && has_left) {
+    if (bottom_flag && left_flag) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, -1, -1)]));
     }
-    if (has_bottom) {
+    if (bottom_flag) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y,  0, -1)]));
     }
-    if (has_bottom && has_right) {
+    if (bottom_flag && right_flag) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, +1, -1)]));
     }
-    if (has_right) {
+    if (right_flag) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, +1,  0)]));
     }
-    if (has_top && has_right) {
+    if (top_flag && right_flag) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, +1, +1)]));
     }
-    if (has_top) {
+    if (top_flag) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y,  0, +1)]));
     }
-    if (has_top && has_left) {
+    if (top_flag && left_flag) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, -1, +1)]));
     }
-    if (has_left) {
+    if (left_flag) {
       conn_list.Push(&(cell_array[Neighbor(cell_id,world_x,world_y, -1,  0)]));
     }
 
@@ -529,6 +539,57 @@
 
   // Update the genebank (note: genotype adjustment may be defered)
   genebank->AdjustGenotype(*genotype);
+}
+
+void cPopulation::Kaboom(cPopulationCell & in_cell)
+{
+
+	cOrganism * organism = in_cell.GetOrganism();
+    cGenotype * genotype = organism->GetGenotype();
+	cGenome genome = genotype->GetGenome();
+	int id = genotype->GetID();
+	
+	int radius = 2;
+	int distance = 0;
+	int count = 0;
+
+	for (int i=-1*radius; i<=radius; i++)
+	{
+		for (int j=-1*radius; j<=radius; j++)
+		{
+			cPopulationCell & death_cell = cell_array[Neighbor(in_cell.GetID(), world_x, world_y, i, j)];
+			//do we actually have something to kill?
+			if (death_cell.IsOccupied() == false) continue;
+				
+			cOrganism * org_temp = death_cell.GetOrganism();
+			cGenotype * gene_temp = org_temp->GetGenotype();
+		
+			if (distance == 0)
+			{
+				int temp_id = gene_temp->GetID();
+				if (temp_id != id)
+				{
+					KillOrganism(death_cell);
+					count++;
+				}
+			}
+			else
+			{
+				cGenome genome_temp = gene_temp->GetGenome();
+				int diff=0;
+				for (int i=0; i<genome_temp.GetSize(); i++)
+					if (genome_temp.AsString()[i] != genome.AsString()[i])
+						diff++;
+				if (diff > distance)
+				{
+					KillOrganism(death_cell);
+					count++;
+				}
+			}
+		}
+	}
+	KillOrganism(in_cell);
+	//my prediction = 92% and, 28 get equals
 }
 
 /**
Index: avida/current/source/main/population.hh
diff -u avida/current/source/main/population.hh:1.59 avida/current/source/main/population.hh:1.60
--- avida/current/source/main/population.hh:1.59	Wed Sep 24 15:58:37 2003
+++ avida/current/source/main/population.hh	Tue Oct 14 19:57:58 2003
@@ -111,6 +111,7 @@
 
   // Deactivate an organism in the population (required for deactivations)
   void KillOrganism(cPopulationCell & in_cell);
+  void Kaboom(cPopulationCell & in_cell);
 
   // Process a single organism one instruction...
   int ScheduleOrganism();          // Determine next organism to be processed.


More information about the Avida-cvs mailing list