[Avida-SVN] r3308 - in branches/topology-manager/source: cpu main

pakanati at myxo.css.msu.edu pakanati at myxo.css.msu.edu
Wed Jun 10 10:57:13 PDT 2009


Author: pakanati
Date: 2009-06-10 13:57:13 -0400 (Wed, 10 Jun 2009)
New Revision: 3308

Added:
   branches/topology-manager/source/main/cDemeInterface.h
Modified:
   branches/topology-manager/source/cpu/cHardwareCPU.cc
   branches/topology-manager/source/main/cPopulationInterface.h
Log:
some preliminary interface stuff (probably non-working)

Modified: branches/topology-manager/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/topology-manager/source/cpu/cHardwareCPU.cc	2009-06-10 13:57:47 UTC (rev 3307)
+++ branches/topology-manager/source/cpu/cHardwareCPU.cc	2009-06-10 17:57:13 UTC (rev 3308)
@@ -76,7 +76,7 @@
     cNOPEntryCPU("nop-B", REG_BX),
     cNOPEntryCPU("nop-C", REG_CX)
   };
-  
+
   static const tInstLibEntry<tMethod> s_f_array[] = {
     /*
      Note: all entries of cNOPEntryCPU s_n_array must have corresponding
@@ -86,7 +86,7 @@
     tInstLibEntry<tMethod>("nop-A", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
     tInstLibEntry<tMethod>("nop-B", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
     tInstLibEntry<tMethod>("nop-C", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
-    
+
     tInstLibEntry<tMethod>("nop-X", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
     tInstLibEntry<tMethod>("if-equ-0", &cHardwareCPU::Inst_If0, 0, "Execute next instruction if ?BX?==0, else skip it"),
     tInstLibEntry<tMethod>("if-not-0", &cHardwareCPU::Inst_IfNot0, 0, "Execute next instruction if ?BX?!=0, else skip it"),
@@ -112,7 +112,7 @@
 		tInstLibEntry<tMethod>("if-p-0.25", &cHardwareCPU::Inst_IfP0p25, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("if-p-0.50", &cHardwareCPU::Inst_IfP0p50, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("if-p-0.75", &cHardwareCPU::Inst_IfP0p75, nInstFlag::STALL),
-				
+
 		// The below series of conditionals extend the traditional Avida single-instruction-skip
 		// to a block, or series of instructions.
 		tInstLibEntry<tMethod>("if-less.end", &cHardwareCPU::Inst_IfLessEnd, nInstFlag::STALL),
@@ -127,15 +127,15 @@
     tInstLibEntry<tMethod>("return", &cHardwareCPU::Inst_Return),
 
     tInstLibEntry<tMethod>("throw", &cHardwareCPU::Inst_Throw),
-    tInstLibEntry<tMethod>("throwif=0", &cHardwareCPU::Inst_ThrowIf0),    
+    tInstLibEntry<tMethod>("throwif=0", &cHardwareCPU::Inst_ThrowIf0),
     tInstLibEntry<tMethod>("throwif!=0", &cHardwareCPU::Inst_ThrowIfNot0),
     tInstLibEntry<tMethod>("catch", &cHardwareCPU::Inst_Catch),
-    
+
     tInstLibEntry<tMethod>("goto", &cHardwareCPU::Inst_Goto),
-    tInstLibEntry<tMethod>("goto-if=0", &cHardwareCPU::Inst_GotoIf0),    
+    tInstLibEntry<tMethod>("goto-if=0", &cHardwareCPU::Inst_GotoIf0),
     tInstLibEntry<tMethod>("goto-if!=0", &cHardwareCPU::Inst_GotoIfNot0),
     tInstLibEntry<tMethod>("label", &cHardwareCPU::Inst_Label),
-    
+
     tInstLibEntry<tMethod>("pop", &cHardwareCPU::Inst_Pop, nInstFlag::DEFAULT, "Remove top number from stack and place into ?BX?"),
     tInstLibEntry<tMethod>("push", &cHardwareCPU::Inst_Push, nInstFlag::DEFAULT, "Copy number from ?BX? and place it into the stack"),
     tInstLibEntry<tMethod>("swap-stk", &cHardwareCPU::Inst_SwitchStack, nInstFlag::DEFAULT, "Toggle which stack is currently being used"),
@@ -153,14 +153,14 @@
     tInstLibEntry<tMethod>("set_C=B", &cHardwareCPU::Inst_CopyRegCB),
     tInstLibEntry<tMethod>("reset", &cHardwareCPU::Inst_Reset),
 	//tInstLibEntry<tMethod>("load-val", &cHardwareCPU::Inst_LoadVal),
-    
+
     tInstLibEntry<tMethod>("pop-A", &cHardwareCPU::Inst_PopA),
     tInstLibEntry<tMethod>("pop-B", &cHardwareCPU::Inst_PopB),
     tInstLibEntry<tMethod>("pop-C", &cHardwareCPU::Inst_PopC),
     tInstLibEntry<tMethod>("push-A", &cHardwareCPU::Inst_PushA),
     tInstLibEntry<tMethod>("push-B", &cHardwareCPU::Inst_PushB),
     tInstLibEntry<tMethod>("push-C", &cHardwareCPU::Inst_PushC),
-    
+
     tInstLibEntry<tMethod>("shift-r", &cHardwareCPU::Inst_ShiftR, nInstFlag::DEFAULT, "Shift bits in ?BX? right by one (divide by two)"),
     tInstLibEntry<tMethod>("shift-l", &cHardwareCPU::Inst_ShiftL, nInstFlag::DEFAULT, "Shift bits in ?BX? left by one (multiply by two)"),
     tInstLibEntry<tMethod>("bit-1", &cHardwareCPU::Inst_Bit1),
@@ -177,7 +177,7 @@
     tInstLibEntry<tMethod>("square", &cHardwareCPU::Inst_Square),
     tInstLibEntry<tMethod>("sqrt", &cHardwareCPU::Inst_Sqrt),
     tInstLibEntry<tMethod>("not", &cHardwareCPU::Inst_Not),
-    
+
     tInstLibEntry<tMethod>("add", &cHardwareCPU::Inst_Add, nInstFlag::DEFAULT, "Add BX to CX and place the result in ?BX?"),
     tInstLibEntry<tMethod>("sub", &cHardwareCPU::Inst_Sub, nInstFlag::DEFAULT, "Subtract CX from BX and place the result in ?BX?"),
     tInstLibEntry<tMethod>("mult", &cHardwareCPU::Inst_Mult, 0, "Multiple BX by CX and place the result in ?BX?"),
@@ -191,13 +191,13 @@
 
 		// treatable instructions
 		tInstLibEntry<tMethod>("nand-treatable", &cHardwareCPU::Inst_NandTreatable, nInstFlag::DEFAULT, "Nand BX by CX and place the result in ?BX?, fails if deme is treatable"),
-		
+
     tInstLibEntry<tMethod>("copy", &cHardwareCPU::Inst_Copy),
     tInstLibEntry<tMethod>("read", &cHardwareCPU::Inst_ReadInst),
     tInstLibEntry<tMethod>("write", &cHardwareCPU::Inst_WriteInst),
     tInstLibEntry<tMethod>("stk-read", &cHardwareCPU::Inst_StackReadInst),
     tInstLibEntry<tMethod>("stk-writ", &cHardwareCPU::Inst_StackWriteInst),
-    
+
     tInstLibEntry<tMethod>("compare", &cHardwareCPU::Inst_Compare),
     tInstLibEntry<tMethod>("if-n-cpy", &cHardwareCPU::Inst_IfNCpy),
     tInstLibEntry<tMethod>("allocate", &cHardwareCPU::Inst_Allocate),
@@ -211,7 +211,7 @@
     tInstLibEntry<tMethod>("search-f", &cHardwareCPU::Inst_SearchF),
     tInstLibEntry<tMethod>("search-b", &cHardwareCPU::Inst_SearchB),
     tInstLibEntry<tMethod>("mem-size", &cHardwareCPU::Inst_MemSize),
-    
+
     tInstLibEntry<tMethod>("get", &cHardwareCPU::Inst_TaskGet, nInstFlag::STALL),
     tInstLibEntry<tMethod>("get-2", &cHardwareCPU::Inst_TaskGet2, nInstFlag::STALL),
     tInstLibEntry<tMethod>("stk-get", &cHardwareCPU::Inst_TaskStackGet, nInstFlag::STALL),
@@ -255,12 +255,12 @@
     tInstLibEntry<tMethod>("donate-energy-faced10", &cHardwareCPU::Inst_DonateEnergyFaced10, nInstFlag::STALL),
     tInstLibEntry<tMethod>("donate-energy-faced20", &cHardwareCPU::Inst_DonateEnergyFaced20, nInstFlag::STALL),
     tInstLibEntry<tMethod>("donate-energy-faced50", &cHardwareCPU::Inst_DonateEnergyFaced50, nInstFlag::STALL),
-    tInstLibEntry<tMethod>("donate-energy-faced100", &cHardwareCPU::Inst_DonateEnergyFaced100, nInstFlag::STALL),    
+    tInstLibEntry<tMethod>("donate-energy-faced100", &cHardwareCPU::Inst_DonateEnergyFaced100, nInstFlag::STALL),
     tInstLibEntry<tMethod>("rotate-to-most-needy", &cHardwareCPU::Inst_RotateToMostNeedy, nInstFlag::STALL),
     tInstLibEntry<tMethod>("request-energy", &cHardwareCPU::Inst_RequestEnergy, nInstFlag::STALL),
     tInstLibEntry<tMethod>("request-energy-on", &cHardwareCPU::Inst_RequestEnergyFlagOn, nInstFlag::STALL),
     tInstLibEntry<tMethod>("request-energy-off", &cHardwareCPU::Inst_RequestEnergyFlagOff, nInstFlag::STALL),
-    tInstLibEntry<tMethod>("increase-energy-donation", &cHardwareCPU::Inst_IncreaseEnergyDonation, nInstFlag::STALL),    
+    tInstLibEntry<tMethod>("increase-energy-donation", &cHardwareCPU::Inst_IncreaseEnergyDonation, nInstFlag::STALL),
     tInstLibEntry<tMethod>("decrease-energy-donation", &cHardwareCPU::Inst_DecreaseEnergyDonation, nInstFlag::STALL),
     tInstLibEntry<tMethod>("IObuf-add1", &cHardwareCPU::Inst_IOBufAdd1, nInstFlag::STALL),
     tInstLibEntry<tMethod>("IObuf-add0", &cHardwareCPU::Inst_IOBufAdd0, nInstFlag::STALL),
@@ -275,7 +275,7 @@
     tInstLibEntry<tMethod>("rotate-to-occupied-cell", &cHardwareCPU::Inst_RotateOccupiedCell, nInstFlag::STALL),
     tInstLibEntry<tMethod>("rotate-to-next-occupied-cell", &cHardwareCPU::Inst_RotateNextOccupiedCell, nInstFlag::STALL),
     tInstLibEntry<tMethod>("rotate-to-event-cell", &cHardwareCPU::Inst_RotateEventCell, nInstFlag::STALL),
-    
+
     tInstLibEntry<tMethod>("set-cmut", &cHardwareCPU::Inst_SetCopyMut),
     tInstLibEntry<tMethod>("mod-cmut", &cHardwareCPU::Inst_ModCopyMut),
     tInstLibEntry<tMethod>("get-cell-xy", &cHardwareCPU::Inst_GetCellPosition),
@@ -288,9 +288,9 @@
     tInstLibEntry<tMethod>("sg-rotate-l", &cHardwareCPU::Inst_SGRotateL),
     tInstLibEntry<tMethod>("sg-rotate-r", &cHardwareCPU::Inst_SGRotateR),
     tInstLibEntry<tMethod>("sg-sense", &cHardwareCPU::Inst_SGSense),
-    
 
-    
+
+
     // Movement instructions
     tInstLibEntry<tMethod>("tumble", &cHardwareCPU::Inst_Tumble, nInstFlag::STALL),
     tInstLibEntry<tMethod>("move", &cHardwareCPU::Inst_Move, nInstFlag::STALL),
@@ -298,7 +298,7 @@
     tInstLibEntry<tMethod>("if-event-in-unoccupied-neighbor-cell", &cHardwareCPU::Inst_IfNeighborEventInUnoccupiedCell),
     tInstLibEntry<tMethod>("if-event-in-faced-cell", &cHardwareCPU::Inst_IfFacingEventCell),
     tInstLibEntry<tMethod>("if-event-in-current-cell", &cHardwareCPU::Inst_IfEventInCell),
-    
+
     // Threading instructions
     tInstLibEntry<tMethod>("fork-th", &cHardwareCPU::Inst_ForkThread),
     tInstLibEntry<tMethod>("forkl", &cHardwareCPU::Inst_ForkThreadLabel),
@@ -306,7 +306,7 @@
     tInstLibEntry<tMethod>("forkl=0", &cHardwareCPU::Inst_ForkThreadLabelIf0),
     tInstLibEntry<tMethod>("kill-th", &cHardwareCPU::Inst_KillThread),
     tInstLibEntry<tMethod>("id-th", &cHardwareCPU::Inst_ThreadID),
-    
+
     // Head-based instructions
     tInstLibEntry<tMethod>("h-alloc", &cHardwareCPU::Inst_MaxAlloc, nInstFlag::DEFAULT, "Allocate maximum allowed space"),
     tInstLibEntry<tMethod>("h-alloc-mw", &cHardwareCPU::Inst_MaxAllocMoveWriteHead),
@@ -330,7 +330,7 @@
     tInstLibEntry<tMethod>("if-label-direct", &cHardwareCPU::Inst_IfLabel, nInstFlag::DEFAULT, "Execute next if we copied direct match of the attached label"),
     tInstLibEntry<tMethod>("if-label2", &cHardwareCPU::Inst_IfLabel2, 0, "If copied label compl., exec next inst; else SKIP W/NOPS"),
     tInstLibEntry<tMethod>("set-flow", &cHardwareCPU::Inst_SetFlow, nInstFlag::DEFAULT, "Set flow-head to position in ?CX?"),
-    
+
     tInstLibEntry<tMethod>("h-copy2", &cHardwareCPU::Inst_HeadCopy2),
     tInstLibEntry<tMethod>("h-copy3", &cHardwareCPU::Inst_HeadCopy3),
     tInstLibEntry<tMethod>("h-copy4", &cHardwareCPU::Inst_HeadCopy4),
@@ -340,15 +340,15 @@
     tInstLibEntry<tMethod>("h-copy8", &cHardwareCPU::Inst_HeadCopy8),
     tInstLibEntry<tMethod>("h-copy9", &cHardwareCPU::Inst_HeadCopy9),
     tInstLibEntry<tMethod>("h-copy10", &cHardwareCPU::Inst_HeadCopy10),
-    
+
     tInstLibEntry<tMethod>("divide-sex", &cHardwareCPU::Inst_HeadDivideSex, nInstFlag::STALL),
     tInstLibEntry<tMethod>("divide-asex", &cHardwareCPU::Inst_HeadDivideAsex, nInstFlag::STALL),
-    
+
     tInstLibEntry<tMethod>("div-sex", &cHardwareCPU::Inst_HeadDivideSex, nInstFlag::STALL),
     tInstLibEntry<tMethod>("div-asex", &cHardwareCPU::Inst_HeadDivideAsex, nInstFlag::STALL),
     tInstLibEntry<tMethod>("div-asex-w", &cHardwareCPU::Inst_HeadDivideAsexWait, nInstFlag::STALL),
     tInstLibEntry<tMethod>("div-sex-MS", &cHardwareCPU::Inst_HeadDivideMateSelect, nInstFlag::STALL),
-    
+
     tInstLibEntry<tMethod>("h-divide1", &cHardwareCPU::Inst_HeadDivide1, nInstFlag::STALL),
     tInstLibEntry<tMethod>("h-divide2", &cHardwareCPU::Inst_HeadDivide2, nInstFlag::STALL),
     tInstLibEntry<tMethod>("h-divide3", &cHardwareCPU::Inst_HeadDivide3, nInstFlag::STALL),
@@ -373,10 +373,11 @@
     tInstLibEntry<tMethod>("h-divide0.05", &cHardwareCPU::Inst_HeadDivide0_05, nInstFlag::STALL),
     tInstLibEntry<tMethod>("h-divide0.01", &cHardwareCPU::Inst_HeadDivide0_01, nInstFlag::STALL),
     tInstLibEntry<tMethod>("h-divide0.001", &cHardwareCPU::Inst_HeadDivide0_001, nInstFlag::STALL),
-    
+
     // High-level instructions
-		tInstLibEntry<tMethod>("repro_deme", &cHardwareCPU::Inst_ReproDeme, nInstFlag::STALL),
-    tInstLibEntry<tMethod>("repro", &cHardwareCPU::Inst_Repro, nInstFlag::STALL),
+	tInstLibEntry<tMethod>("repro_deme", &cHardwareCPU::Inst_ReproDeme, nInstFlag::STALL),
+	tInstLibEntry<tMethod>("reproduce_deme", &cHardwareCPU::Inst_ReproduceDeme, nInstFlag::DEFAULT),
+	tInstLibEntry<tMethod>("repro", &cHardwareCPU::Inst_Repro, nInstFlag::STALL),
     tInstLibEntry<tMethod>("repro-sex", &cHardwareCPU::Inst_ReproSex, nInstFlag::STALL),
     tInstLibEntry<tMethod>("repro-A", &cHardwareCPU::Inst_Repro, nInstFlag::STALL),
     tInstLibEntry<tMethod>("repro-B", &cHardwareCPU::Inst_Repro, nInstFlag::STALL),
@@ -406,17 +407,17 @@
     tInstLibEntry<tMethod>("repro-Z", &cHardwareCPU::Inst_Repro, nInstFlag::STALL),
 
     tInstLibEntry<tMethod>("put-repro", &cHardwareCPU::Inst_TaskPutRepro, nInstFlag::STALL),
-    tInstLibEntry<tMethod>("metabolize", &cHardwareCPU::Inst_TaskPutResetInputsRepro, nInstFlag::STALL),        
+    tInstLibEntry<tMethod>("metabolize", &cHardwareCPU::Inst_TaskPutResetInputsRepro, nInstFlag::STALL),
 
     tInstLibEntry<tMethod>("sterilize", &cHardwareCPU::Inst_Sterilize),
-    
+
     tInstLibEntry<tMethod>("spawn-deme", &cHardwareCPU::Inst_SpawnDeme, nInstFlag::STALL),
-    
+
     // Suicide
     tInstLibEntry<tMethod>("kazi",	&cHardwareCPU::Inst_Kazi, nInstFlag::STALL),
     tInstLibEntry<tMethod>("kazi5", &cHardwareCPU::Inst_Kazi5, nInstFlag::STALL),
     tInstLibEntry<tMethod>("die", &cHardwareCPU::Inst_Die, nInstFlag::STALL),
-    tInstLibEntry<tMethod>("suicide", &cHardwareCPU::Inst_Suicide, nInstFlag::STALL),		
+    tInstLibEntry<tMethod>("suicide", &cHardwareCPU::Inst_Suicide, nInstFlag::STALL),
     tInstLibEntry<tMethod>("relinquishEnergyToFutureDeme", &cHardwareCPU::Inst_RelinquishEnergyToFutureDeme, nInstFlag::STALL),
     tInstLibEntry<tMethod>("relinquishEnergyToNeighborOrganisms", &cHardwareCPU::Inst_RelinquishEnergyToNeighborOrganisms, nInstFlag::STALL),
     tInstLibEntry<tMethod>("relinquishEnergyToOrganismsInDeme", &cHardwareCPU::Inst_RelinquishEnergyToOrganismsInDeme, nInstFlag::STALL),
@@ -430,10 +431,10 @@
   	tInstLibEntry<tMethod>("if-energy-not-high", &cHardwareCPU::Inst_IfEnergyNotHigh, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("if-faced-energy-high", &cHardwareCPU::Inst_IfFacedEnergyHigh, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("if-faced-energy-not-high", &cHardwareCPU::Inst_IfFacedEnergyNotHigh, nInstFlag::STALL),
-  	tInstLibEntry<tMethod>("if-energy-med", &cHardwareCPU::Inst_IfEnergyMed, nInstFlag::STALL),	 
-  	tInstLibEntry<tMethod>("if-faced-energy-med", &cHardwareCPU::Inst_IfFacedEnergyMed, nInstFlag::STALL),	
-  	tInstLibEntry<tMethod>("if-faced-energy-less", &cHardwareCPU::Inst_IfFacedEnergyLess, nInstFlag::STALL),	
-  	tInstLibEntry<tMethod>("if-faced-energy-more", &cHardwareCPU::Inst_IfFacedEnergyMore, nInstFlag::STALL),	    
+  	tInstLibEntry<tMethod>("if-energy-med", &cHardwareCPU::Inst_IfEnergyMed, nInstFlag::STALL),
+  	tInstLibEntry<tMethod>("if-faced-energy-med", &cHardwareCPU::Inst_IfFacedEnergyMed, nInstFlag::STALL),
+  	tInstLibEntry<tMethod>("if-faced-energy-less", &cHardwareCPU::Inst_IfFacedEnergyLess, nInstFlag::STALL),
+  	tInstLibEntry<tMethod>("if-faced-energy-more", &cHardwareCPU::Inst_IfFacedEnergyMore, nInstFlag::STALL),
 	  tInstLibEntry<tMethod>("if-energy-in-buffer", &cHardwareCPU::Inst_IfEnergyInBuffer, nInstFlag::STALL),
 	  tInstLibEntry<tMethod>("if-energy-not-in-buffer", &cHardwareCPU::Inst_IfEnergyNotInBuffer, nInstFlag::STALL),
     tInstLibEntry<tMethod>("get-energy-level", &cHardwareCPU::Inst_GetEnergyLevel, nInstFlag::STALL),
@@ -443,7 +444,7 @@
     tInstLibEntry<tMethod>("get-energy-request-status", &cHardwareCPU::Inst_GetEnergyRequestStatus, nInstFlag::STALL),
     tInstLibEntry<tMethod>("get-faced-energy-request-status", &cHardwareCPU::Inst_GetFacedEnergyRequestStatus, nInstFlag::STALL),
 
-	  
+
     // Sleep and time
     tInstLibEntry<tMethod>("sleep", &cHardwareCPU::Inst_Sleep, nInstFlag::STALL),
     tInstLibEntry<tMethod>("sleep1", &cHardwareCPU::Inst_Sleep, nInstFlag::STALL),
@@ -451,7 +452,7 @@
     tInstLibEntry<tMethod>("sleep3", &cHardwareCPU::Inst_Sleep, nInstFlag::STALL),
     tInstLibEntry<tMethod>("sleep4", &cHardwareCPU::Inst_Sleep, nInstFlag::STALL),
     tInstLibEntry<tMethod>("time", &cHardwareCPU::Inst_GetUpdate, nInstFlag::STALL),
-    
+
     // Promoter Model
     tInstLibEntry<tMethod>("promoter", &cHardwareCPU::Inst_Promoter),
     tInstLibEntry<tMethod>("terminate", &cHardwareCPU::Inst_Terminate),
@@ -483,7 +484,7 @@
 		tInstLibEntry<tMethod>("bcast2", &cHardwareCPU::Inst_Broadcast2, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("bcast4", &cHardwareCPU::Inst_Broadcast4, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("bcast8", &cHardwareCPU::Inst_Broadcast8, nInstFlag::STALL),
-		
+
     // Alarms
     tInstLibEntry<tMethod>("send-alarm-msg-local", &cHardwareCPU::Inst_Alarm_MSG_local, nInstFlag::STALL),
     tInstLibEntry<tMethod>("send-alarm-msg-multihop", &cHardwareCPU::Inst_Alarm_MSG_multihop, nInstFlag::STALL),
@@ -520,19 +521,19 @@
     tInstLibEntry<tMethod>("if-pheromone", &cHardwareCPU::Inst_IfPheromone),
     tInstLibEntry<tMethod>("if-not-pheromone", &cHardwareCPU::Inst_IfNotPheromone),
     tInstLibEntry<tMethod>("drop-pheromone", &cHardwareCPU::Inst_DropPheromone, nInstFlag::STALL),
-    
+
     // Opinion instructions.
     // These are STALLs because opinions are only relevant with respect to time.
     tInstLibEntry<tMethod>("set-opinion", &cHardwareCPU::Inst_SetOpinion, nInstFlag::STALL),
     tInstLibEntry<tMethod>("get-opinion", &cHardwareCPU::Inst_GetOpinion, nInstFlag::STALL),
-		
+
 		// Data collection
 		tInstLibEntry<tMethod>("if-cell-data-changed", &cHardwareCPU::Inst_IfCellDataChanged, nInstFlag::STALL),
     tInstLibEntry<tMethod>("collect-cell-data", &cHardwareCPU::Inst_CollectCellData, nInstFlag::STALL),
     tInstLibEntry<tMethod>("kill-cell-event", &cHardwareCPU::Inst_KillCellEvent, nInstFlag::STALL),
     tInstLibEntry<tMethod>("kill-faced-cell-event", &cHardwareCPU::Inst_KillFacedCellEvent, nInstFlag::STALL),
     tInstLibEntry<tMethod>("collect-cell-data-and-kill-event", &cHardwareCPU::Inst_CollectCellDataAndKillEvent, nInstFlag::STALL),
-		
+
 		// Synchronization
     tInstLibEntry<tMethod>("flash", &cHardwareCPU::Inst_Flash, nInstFlag::STALL),
     tInstLibEntry<tMethod>("if-recvd-flash", &cHardwareCPU::Inst_IfRecvdFlash, nInstFlag::STALL),
@@ -540,20 +541,20 @@
     tInstLibEntry<tMethod>("flash-info-b", &cHardwareCPU::Inst_FlashInfoB, nInstFlag::STALL),
     tInstLibEntry<tMethod>("reset-flash-info", &cHardwareCPU::Inst_ResetFlashInfo, nInstFlag::STALL),
     tInstLibEntry<tMethod>("hard-reset", &cHardwareCPU::Inst_HardReset, nInstFlag::STALL),
-    tInstLibEntry<tMethod>("get-cycles", &cHardwareCPU::Inst_GetCycles, nInstFlag::STALL),		
+    tInstLibEntry<tMethod>("get-cycles", &cHardwareCPU::Inst_GetCycles, nInstFlag::STALL),
 
 		// Neighborhood-sensing instructions
 		tInstLibEntry<tMethod>("get-neighborhood", &cHardwareCPU::Inst_GetNeighborhood, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("if-neighborhood-changed", &cHardwareCPU::Inst_IfNeighborhoodChanged, nInstFlag::STALL),
-		
-		
+
+
 		// Reputation instructions
-		
+
   	tInstLibEntry<tMethod>("donate-frm", &cHardwareCPU::Inst_DonateFacingRawMaterials, nInstFlag::STALL),
   	tInstLibEntry<tMethod>("donate-spec", &cHardwareCPU::Inst_DonateFacingRawMaterialsOtherSpecies, nInstFlag::STALL),
-  	tInstLibEntry<tMethod>("donate-if-donor", &cHardwareCPU::Inst_DonateIfDonor, nInstFlag::STALL),		
-  	tInstLibEntry<tMethod>("donate-string", &cHardwareCPU::Inst_DonateFacingString, nInstFlag::STALL),		
-		
+  	tInstLibEntry<tMethod>("donate-if-donor", &cHardwareCPU::Inst_DonateIfDonor, nInstFlag::STALL),
+  	tInstLibEntry<tMethod>("donate-string", &cHardwareCPU::Inst_DonateFacingString, nInstFlag::STALL),
+
     tInstLibEntry<tMethod>("get-neighbors-reputation", &cHardwareCPU::Inst_GetNeighborsReputation, nInstFlag::STALL),
     tInstLibEntry<tMethod>("get-reputation", &cHardwareCPU::Inst_GetReputation, nInstFlag::STALL),
     tInstLibEntry<tMethod>("get-raw-mat-amount", &cHardwareCPU::Inst_GetAmountOfRawMaterials, nInstFlag::STALL),
@@ -566,31 +567,31 @@
 		tInstLibEntry<tMethod>("rotate-to-tag", &cHardwareCPU::Inst_RotateToDifferentTag, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("if-donor",  &cHardwareCPU::Inst_IfDonor, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("prod-string",  &cHardwareCPU::Inst_ProduceString, nInstFlag::STALL),
-		
+
 		// Group formation instructions
 		tInstLibEntry<tMethod>("join-group", &cHardwareCPU::Inst_JoinGroup, nInstFlag::STALL),
 		tInstLibEntry<tMethod>("orgs-in-group", &cHardwareCPU::Inst_NumberOrgsInGroup, nInstFlag::STALL),
-		
+
     // Must always be the last instruction in the array
     tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
   };
-  
+
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
-  
+
   static cString n_names[n_size];
   static int nop_mods[n_size];
   for (int i = 0; i < n_size && i < NUM_REGISTERS; i++) {
     n_names[i] = s_n_array[i].name;
     nop_mods[i] = s_n_array[i].nop_mod;
   }
-  
+
   const int f_size = sizeof(s_f_array)/sizeof(tInstLibEntry<tMethod>);
   static tMethod functions[f_size];
   for (int i = 0; i < f_size; i++) functions[i] = s_f_array[i].GetFunction();
 
 	const int def = 0;
   const int null_inst = f_size - 1;
-  
+
   return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, def, null_inst);
 }
 
@@ -599,18 +600,18 @@
 , m_last_cell_data(false, 0)
 {
   m_functions = s_inst_slib->GetFunctions();
-  
+
   m_spec_die = false;
   m_epigenetic_state = false;
-  
+
   m_thread_slicing_parallel = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1);
   m_no_cpu_cycle_time = m_world->GetConfig().NO_CPU_CYCLE_TIME.Get();
-  
+
   m_promoters_enabled = m_world->GetConfig().PROMOTERS_ENABLED.Get();
   m_constitutive_regulation = m_world->GetConfig().CONSTITUTIVE_REGULATION.Get();
-  
+
   m_slip_read_head = !m_world->GetConfig().SLIP_COPY_MODE.Get();
-  
+
   m_memory = in_organism->GetGenome();  // Initialize memory...
   Reset(ctx);                            // Setup the rest of the hardware...
 }
@@ -619,15 +620,15 @@
 void cHardwareCPU::internalReset()
 {
   m_global_stack.Clear();
-  
+
   // We want to reset to have a single thread.
   m_threads.Resize(1);
-  
+
   // Reset that single thread.
   m_threads[0].Reset(this, 0);
   m_thread_id_chart = 1; // Mark only the first thread as taken...
   m_cur_thread = 0;
-  
+
   // But then reset thread to have any epigenetic information we have saved
   if (m_epigenetic_state) {
     for (int i=0; i<NUM_REGISTERS; i++) {
@@ -635,11 +636,11 @@
     }
     m_threads[0].stack = m_epigenetic_saved_stack;
   }
-  
+
   m_mal_active = false;
   m_executedmatchstrings = false;
-  
 
+
   // Promoter model
   if (m_world->GetConfig().PROMOTERS_ENABLED.Get())
   {
@@ -672,16 +673,16 @@
 void cHardwareCPU::cLocalThread::Reset(cHardwareBase* in_hardware, int in_id)
 {
   m_id = in_id;
-  
+
   for (int i = 0; i < NUM_REGISTERS; i++) reg[i] = 0;
   for (int i = 0; i < NUM_HEADS; i++) heads[i].Reset(in_hardware);
-  
+
   stack.Clear();
   cur_stack = 0;
   cur_head = nHardware::HEAD_IP;
   read_label.Clear();
   next_label.Clear();
-  
+
   // Promoter model
   m_promoter_inst_executed = 0;
 }
@@ -694,10 +695,10 @@
   assert(!speculative || (speculative && !m_thread_slicing_parallel));
 
   int last_IP_pos = IP().GetPosition();
-  
+
   // Mark this organism as running...
   m_organism->SetRunning(true);
-  
+
   if (!speculative && m_spec_die) {
     m_organism->Die();
     m_organism->SetRunning(false);
@@ -705,41 +706,41 @@
   }
 
   cPhenotype& phenotype = m_organism->GetPhenotype();
-  
+
   // First instruction - check whether we should be starting at a promoter, when enabled.
   if (phenotype.GetCPUCyclesUsed() == 0 && m_promoters_enabled) Inst_Terminate(ctx);
-  
+
   // Count the cpu cycles used
   phenotype.IncCPUCyclesUsed();
   if (!m_world->GetConfig().NO_CPU_CYCLE_TIME.Get()) phenotype.IncTimeUsed();
 
   const int num_threads = m_threads.GetSize();
-  
+
   // If we have threads turned on and we executed each thread in a single
   // timestep, adjust the number of instructions executed accordingly.
   const int num_inst_exec = m_thread_slicing_parallel ? num_threads : 1;
-  
+
   for (int i = 0; i < num_inst_exec; i++) {
     // Setup the hardware for the next instruction to be executed.
     int last_thread = m_cur_thread++;
     if (m_cur_thread >= num_threads) m_cur_thread = 0;
-    
+
     m_advance_ip = true;
     cHeadCPU& ip = m_threads[m_cur_thread].heads[nHardware::HEAD_IP];
     ip.Adjust();
-    
+
 #if BREAKPOINTS
     if (ip.FlagBreakpoint()) {
       m_organism->DoBreakpoint();
     }
 #endif
-    
+
     // Print the status of this CPU at each step...
     if (m_tracer != NULL) m_tracer->TraceHardware(*this);
-    
+
     // Find the instruction to be executed
     const cInstruction& cur_inst = ip.GetInst();
-    
+
     if (speculative && (m_spec_die || m_inst_set->ShouldStall(cur_inst))) {
       // Speculative instruction reject, flush and return
       m_cur_thread = last_thread;
@@ -748,17 +749,17 @@
       m_organism->SetRunning(false);
       return false;
     }
-    
+
     // Test if costs have been paid and it is okay to execute this now...
     bool exec = true;
     if (m_has_any_costs) exec = SingleProcess_PayCosts(ctx, cur_inst);
 
     // Constitutive regulation applied here
-    if (m_constitutive_regulation) Inst_SenseRegulate(ctx); 
+    if (m_constitutive_regulation) Inst_SenseRegulate(ctx);
 
     // If there are no active promoters and a certain mode is set, then don't execute any further instructions
     if (m_promoters_enabled && m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 2 && m_promoter_index == -1) exec = false;
-  
+
     // Now execute the instruction...
     if (exec == true) {
       // NOTE: This call based on the cur_inst must occur prior to instruction
@@ -770,35 +771,35 @@
       if (m_inst_set->GetProbFail(cur_inst) > 0.0) {
         exec = !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
       }
-      
+
       // Flag instruction as executed even if it failed (moved from SingleProcess_ExecuteInst)
       // this allows division conditions to be met even if most instruction executions failed. @JEB
-      
+
       // Mark the instruction as executed
       IP().SetFlagExecuted();
-      
+
       // Add to the promoter inst executed count before executing the inst (in case it is a terminator)
       if (m_promoters_enabled) m_threads[m_cur_thread].IncPromoterInstExecuted();
 
       if (exec == true) SingleProcess_ExecuteInst(ctx, cur_inst);
-      
+
       // Some instruction (such as jump) may turn m_advance_ip off.  Usually
       // we now want to move to the next instruction in the memory.
       if (m_advance_ip == true) ip.Advance();
-      
+
       // Pay the time cost of the instruction now
       phenotype.IncTimeUsed(time_cost);
-            
+
       // In the promoter model, we may force termination after a certain number of inst have been executed
       if (m_promoters_enabled) {
         const double processivity = m_world->GetConfig().PROMOTER_PROCESSIVITY.Get();
         if (ctx.GetRandom().P(1 - processivity)) Inst_Terminate(ctx);
-        if (m_world->GetConfig().PROMOTER_INST_MAX.Get() && (m_threads[m_cur_thread].GetPromoterInstExecuted() >= m_world->GetConfig().PROMOTER_INST_MAX.Get())) 
+        if (m_world->GetConfig().PROMOTER_INST_MAX.Get() && (m_threads[m_cur_thread].GetPromoterInstExecuted() >= m_world->GetConfig().PROMOTER_INST_MAX.Get()))
           Inst_Terminate(ctx);
       }
 
     } // if exec
-        
+
   } // Previous was executed once for each thread...
 
   // Kill creatures who have reached their max num of instructions executed
@@ -808,35 +809,35 @@
     else m_organism->Die();
   }
   if (!speculative && phenotype.GetToDelete()) m_spec_die = true;
-  
+
   // Note: if organism just died, this will NOT let it repro.
   CheckImplicitRepro(ctx, last_IP_pos > m_threads[m_cur_thread].heads[nHardware::HEAD_IP].GetPosition());
-  
+
   m_organism->SetRunning(false);
-  
+
   return !m_spec_die;
 }
 
 // This method will handle the actual execution of an instruction
 // within a single process, once that function has been finalized.
-bool cHardwareCPU::SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst) 
+bool cHardwareCPU::SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst)
 {
   // Copy Instruction locally to handle stochastic effects
   cInstruction actual_inst = cur_inst;
-  
+
 #ifdef EXECUTION_ERRORS
   // If there is an execution error, execute a random instruction.
   if (m_organism->TestExeErr()) actual_inst = m_inst_set->GetRandomInst(ctx);
 #endif /* EXECUTION_ERRORS */
-    
+
   // Get a pointer to the corresponding method...
   int inst_idx = m_inst_set->GetLibFunctionIndex(actual_inst);
-  
+
 #if INSTRUCTION_COUNT
   // instruction execution count incremented
   m_organism->GetPhenotype().IncCurInstCount(actual_inst.GetOp());
 #endif
-	
+
   // And execute it.
   const bool exec_success = (this->*(m_functions[inst_idx]))(ctx);
 
@@ -847,8 +848,8 @@
   if (exec_success == false) {
     m_organism->GetPhenotype().DecCurInstCount(actual_inst.GetOp());
   }
-#endif	
-  
+#endif
+
   return exec_success;
 }
 
@@ -858,11 +859,11 @@
   // Mark this organism as running...
   bool prev_run_state = m_organism->IsRunning();
   m_organism->SetRunning(true);
-  
+
   if (m_tracer != NULL) m_tracer->TraceHardware(*this, true);
-  
+
   SingleProcess_ExecuteInst(ctx, inst);
-  
+
   m_organism->SetRunning(prev_run_state);
 }
 
@@ -870,12 +871,12 @@
 bool cHardwareCPU::OK()
 {
   bool result = true;
-    
+
   for (int i = 0; i < m_threads.GetSize(); i++) {
     if (m_threads[i].stack.OK() == false) result = false;
     if (m_threads[i].next_label.OK() == false) result = false;
   }
-  
+
   return result;
 }
 
@@ -883,12 +884,12 @@
 {
   fp << m_organism->GetPhenotype().GetCPUCyclesUsed() << " ";
   fp << "IP:" << IP().GetPosition() << "    ";
-  
+
   for (int i = 0; i < NUM_REGISTERS; i++) {
     fp << static_cast<char>('A' + i) << "X:" << GetRegister(i) << " ";
     fp << setbase(16) << "[0x" << GetRegister(i) << "]  " << setbase(10);
   }
-  
+
   // Add some extra information if additional time costs are used for instructions,
   // leave this out if there are no differences to keep it cleaner
   if ( m_organism->GetPhenotype().GetTimeUsed() != m_organism->GetPhenotype().GetCPUCyclesUsed() )
@@ -896,30 +897,30 @@
     fp << "  EnergyUsed:" << m_organism->GetPhenotype().GetTimeUsed();
   }
   fp << endl;
-  
+
   fp << "  R-Head:" << GetHead(nHardware::HEAD_READ).GetPosition() << " "
     << "W-Head:" << GetHead(nHardware::HEAD_WRITE).GetPosition()  << " "
     << "F-Head:" << GetHead(nHardware::HEAD_FLOW).GetPosition()   << "  "
     << "RL:" << GetReadLabel().AsString() << "   "
     << endl;
-    
+
   int number_of_stacks = GetNumStacks();
   for (int stack_id = 0; stack_id < number_of_stacks; stack_id++) {
     fp << ((m_threads[m_cur_thread].cur_stack == stack_id) ? '*' : ' ') << " Stack " << stack_id << ":" << setbase(16) << setfill('0');
     for (int i = 0; i < nHardware::STACK_SIZE; i++) fp << " Ox" << setw(8) << GetStack(i, stack_id, 0);
     fp << setfill(' ') << setbase(10) << endl;
   }
-  
+
   fp << "  Mem (" << m_memory.GetSize() << "):"
 		  << "  " << m_memory.AsString()
 		  << endl;
-      
+
   if (m_ext_mem.GetSize()) {
     fp << "  Ext Mem: " << m_ext_mem[0];
     for (int i = 1; i < m_ext_mem.GetSize(); i++) fp << ", " << m_ext_mem[i];
     fp << endl;
   }
-  
+
   if (m_world->GetConfig().PROMOTERS_ENABLED.Get())
   {
     fp << "  Promoters: index=" << m_promoter_index << " offset=" << m_promoter_offset;
@@ -927,10 +928,10 @@
     for (int i=0; i<m_promoters.GetSize(); i++)
     {
       fp << setfill(' ') << setbase(10) << " " << m_promoters[i].m_pos << ":";
-      fp << "Ox" << setbase(16) << setfill('0') << setw(8) << (m_promoters[i].GetRegulatedBitCode()) << " "; 
+      fp << "Ox" << setbase(16) << setfill('0') << setw(8) << (m_promoters[i].GetRegulatedBitCode()) << " ";
     }
     fp << setfill(' ') << setbase(10) << endl;
-  }    
+  }
   fp.flush();
 }
 
@@ -950,38 +951,38 @@
 cHeadCPU cHardwareCPU::FindLabel(int direction)
 {
   cHeadCPU & inst_ptr = IP();
-  
+
   // Start up a search head at the position of the instruction pointer.
   cHeadCPU search_head(inst_ptr);
   cCodeLabel & search_label = GetLabel();
-  
+
   // Make sure the label is of size > 0.
-  
+
   if (search_label.GetSize() == 0) {
     return inst_ptr;
   }
-  
+
   // Call special functions depending on if jump is forwards or backwards.
   int found_pos = 0;
   if( direction < 0 ) {
     found_pos = FindLabel_Backward(search_label, inst_ptr.GetMemory(),
                                    inst_ptr.GetPosition() - search_label.GetSize());
   }
-  
+
   // Jump forward.
   else if (direction > 0) {
     found_pos = FindLabel_Forward(search_label, inst_ptr.GetMemory(),
                                   inst_ptr.GetPosition());
   }
-  
+
   // Jump forward from the very beginning.
   else {
     found_pos = FindLabel_Forward(search_label, inst_ptr.GetMemory(), 0);
   }
-  
+
   // Return the last line of the found label, if it was found.
   if (found_pos >= 0) search_head.Set(found_pos - 1);
-  
+
   // Return the found position (still at start point if not found).
   return search_head;
 }
@@ -995,23 +996,23 @@
                                     const cGenome & search_genome, int pos)
 {
   assert (pos < search_genome.GetSize() && pos >= 0);
-  
+
   int search_start = pos;
   int label_size = search_label.GetSize();
   bool found_label = false;
-  
+
   // Move off the template we are on.
   pos += label_size;
-  
+
   // Search until we find the complement or exit the memory.
   while (pos < search_genome.GetSize()) {
-    
+
     // If we are within a label, rewind to the beginning of it and see if
     // it has the proper sub-label that we're looking for.
-    
+
     if (m_inst_set->IsNop(search_genome[pos])) {
       // Find the start and end of the label we're in the middle of.
-      
+
       int start_pos = pos;
       int end_pos = pos + 1;
       while (start_pos > search_start &&
@@ -1023,12 +1024,12 @@
         end_pos++;
       }
       int test_size = end_pos - start_pos;
-      
+
       // See if this label has the proper sub-label within it.
       int max_offset = test_size - label_size + 1;
       int offset = start_pos;
       for (offset = start_pos; offset < start_pos + max_offset; offset++) {
-        
+
         // Test the number of matches for this offset.
         int matches;
         for (matches = 0; matches < label_size; matches++) {
@@ -1037,35 +1038,35 @@
             break;
           }
         }
-        
+
         // If we have found it, break out of this loop!
         if (matches == label_size) {
           found_label = true;
           break;
         }
       }
-      
+
       // If we've found the complement label, set the position to the end of
       // the label we found it in, and break out.
-      
+
       if (found_label == true) {
         // pos = end_pos;
         pos = label_size + offset;
         break;
       }
-      
+
       // We haven't found it; jump pos to just after the current label being
       // checked.
       pos = end_pos;
     }
-    
+
     // Jump up a block to the next possible point to find a label,
     pos += label_size;
   }
-  
+
   // If the label was not found return a -1.
   if (found_label == false) pos = -1;
-  
+
   return pos;
 }
 
@@ -1077,22 +1078,22 @@
                                      const cGenome & search_genome, int pos)
 {
   assert (pos < search_genome.GetSize());
-  
+
   int search_start = pos;
   int label_size = search_label.GetSize();
   bool found_label = false;
-  
+
   // Move off the template we are on.
   pos -= label_size;
-  
+
   // Search until we find the complement or exit the memory.
   while (pos >= 0) {
     // If we are within a label, rewind to the beginning of it and see if
     // it has the proper sub-label that we're looking for.
-    
+
     if (m_inst_set->IsNop( search_genome[pos] )) {
       // Find the start and end of the label we're in the middle of.
-      
+
       int start_pos = pos;
       int end_pos = pos + 1;
       while (start_pos > 0 && m_inst_set->IsNop(search_genome[start_pos - 1])) {
@@ -1103,11 +1104,11 @@
         end_pos++;
       }
       int test_size = end_pos - start_pos;
-      
+
       // See if this label has the proper sub-label within it.
       int max_offset = test_size - label_size + 1;
       for (int offset = start_pos; offset < start_pos + max_offset; offset++) {
-        
+
         // Test the number of matches for this offset.
         int matches;
         for (matches = 0; matches < label_size; matches++) {
@@ -1116,34 +1117,34 @@
             break;
           }
         }
-        
+
         // If we have found it, break out of this loop!
         if (matches == label_size) {
           found_label = true;
           break;
         }
       }
-      
+
       // If we've found the complement label, set the position to the end of
       // the label we found it in, and break out.
-      
+
       if (found_label == true) {
         pos = end_pos;
         break;
       }
-      
+
       // We haven't found it; jump pos to just before the current label
       // being checked.
       pos = start_pos - 1;
     }
-    
+
     // Jump up a block to the next possible point to find a label,
     pos -= label_size;
   }
-  
+
   // If the label was not found return a -1.
   if (found_label == false) pos = -1;
-  
+
   return pos;
 }
 
@@ -1151,20 +1152,20 @@
 cHeadCPU cHardwareCPU::FindLabel(const cCodeLabel & in_label, int direction)
 {
   assert (in_label.GetSize() > 0);
-  
+
   // IDEALY:
   // Keep making jumps (in the proper direction) equal to the label
   // length.  If we are inside of a label, check its size, and see if
   // any of the sub-labels match properly.
   // FOR NOW:
   // Get something which works, no matter how inefficient!!!
-  
+
   cHeadCPU temp_head(this);
-  
+
   while (temp_head.InMemory()) {
     // IDEALY: Analyze the label we are in; see if the one we are looking
     // for could be a sub-label of it.  Skip past it if not.
-    
+
     int i;
     for (i = 0; i < in_label.GetSize(); i++) {
       if (!m_inst_set->IsNop(temp_head.GetInst()) ||
@@ -1176,10 +1177,10 @@
       temp_head.AbsJump(i - 1);
       return temp_head;
     }
-    
+
     temp_head.AbsJump(direction);     // IDEALY: MAKE LARGER JUMPS
   }
-  
+
   temp_head.AbsSet(-1);
   return temp_head;
 }
@@ -1188,18 +1189,18 @@
 bool cHardwareCPU::InjectHost(const cCodeLabel & in_label, const cGenome & injection)
 {
   // Make sure the genome will be below max size after injection.
-  
+
   const int new_size = injection.GetSize() + m_memory.GetSize();
   if (new_size > MAX_CREATURE_SIZE) return false; // (inject fails)
-  
+
   const int inject_line = FindLabelFull(in_label).GetPosition();
-  
+
   // Abort if no compliment is found.
   if (inject_line == -1) return false; // (inject fails)
-  
+
   // Inject the code!
   InjectCode(injection, inject_line+1);
-  
+
   return true; // (inject succeeds!)
 }
 
@@ -1208,19 +1209,19 @@
   assert(line_num >= 0);
   assert(line_num <= m_memory.GetSize());
   assert(m_memory.GetSize() + inject_code.GetSize() < MAX_CREATURE_SIZE);
-  
+
   // Inject the new code.
   const int inject_size = inject_code.GetSize();
   m_memory.Insert(line_num, inject_code);
-  
+
   // Set instruction flags on the injected code
   for (int i = line_num; i < line_num + inject_size; i++) {
     m_memory.SetFlagInjected(i);
   }
   m_organism->GetPhenotype().IsModified() = true;
-  
-  // Adjust all of the heads to take into account the new mem size.  
-  for (int i = 0; i < NUM_HEADS; i++) {    
+
+  // Adjust all of the heads to take into account the new mem size.
+  for (int i = 0; i < NUM_HEADS; i++) {
     if (GetHead(i).GetPosition() > line_num) GetHead(i).Jump(inject_size);
   }
 }
@@ -1255,15 +1256,15 @@
 {
   int count = 0;
   cHeadCPU * inst_ptr = &( IP() );
-  
+
   GetLabel().Clear();
-  
+
   while (m_inst_set->IsNop(inst_ptr->GetNextInst()) &&
          (count < max_size)) {
     count++;
     inst_ptr->Advance();
     GetLabel().AddNop(m_inst_set->GetNopMod(inst_ptr->GetInst()));
-    
+
     // If this is the first line of the template, mark it executed.
     if (GetLabel().GetSize() <=	m_world->GetConfig().MAX_LABEL_EXE_SIZE.Get()) {
       inst_ptr->SetFlagExecuted();
@@ -1276,20 +1277,20 @@
 {
   const int num_threads = m_threads.GetSize();
   if (num_threads == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
-  
+
   // Make room for the new thread.
   m_threads.Resize(num_threads + 1);
-  
+
   // Initialize the new thread to the same values as the current one.
   m_threads[num_threads] = m_threads[m_cur_thread];
-  
+
   // Find the first free bit in m_thread_id_chart to determine the new
   // thread id.
   int new_id = 0;
   while ( (m_thread_id_chart >> new_id) & 1 == 1) new_id++;
   m_threads[num_threads].SetID(new_id);
   m_thread_id_chart |= (1 << new_id);
-  
+
   return true;
 }
 
@@ -1298,25 +1299,25 @@
 {
   // Make sure that there is always at least one thread...
   if (m_threads.GetSize() == 1) return false;
-  
+
   // Note the current thread and set the current back one.
   const int kill_thread = m_cur_thread;
   ThreadPrev();
-  
+
   // Turn off this bit in the m_thread_id_chart...
   m_thread_id_chart ^= 1 << m_threads[kill_thread].GetID();
-  
+
   // Copy the last thread into the kill position
   const int last_thread = m_threads.GetSize() - 1;
   if (last_thread != kill_thread) {
     m_threads[kill_thread] = m_threads[last_thread];
   }
-  
+
   // Kill the thread!
   m_threads.Resize(m_threads.GetSize() - 1);
-  
+
   if (m_cur_thread > kill_thread) m_cur_thread--;
-  
+
   return true;
 }
 
@@ -1327,7 +1328,7 @@
 inline int cHardwareCPU::FindModifiedRegister(int default_register)
 {
   assert(default_register < NUM_REGISTERS);  // Reg ID too high.
-  
+
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_register = m_inst_set->GetNopMod(IP().GetInst());
@@ -1339,7 +1340,7 @@
 inline int cHardwareCPU::FindModifiedNextRegister(int default_register)
 {
   assert(default_register < NUM_REGISTERS);  // Reg ID too high.
-  
+
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_register = m_inst_set->GetNopMod(IP().GetInst());
@@ -1353,7 +1354,7 @@
 inline int cHardwareCPU::FindModifiedPreviousRegister(int default_register)
 {
   assert(default_register < NUM_REGISTERS);  // Reg ID too high.
-  
+
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_register = m_inst_set->GetNopMod(IP().GetInst());
@@ -1368,7 +1369,7 @@
 inline int cHardwareCPU::FindModifiedHead(int default_head)
 {
   assert(default_head < NUM_HEADS); // Head ID too high.
-  
+
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();
     default_head = m_inst_set->GetNopMod(IP().GetInst());
@@ -1403,9 +1404,9 @@
 bool cHardwareCPU::Allocate_Default(const int new_size)
 {
   m_memory.Resize(new_size);
-  
+
   // New space already defaults to default instruction...
-  
+
   return true;
 }
 
@@ -1421,10 +1422,10 @@
           cStringUtil::Stringf("Allocate of %d too small", allocated_size));
     return false;
   }
-  
+
   const int old_size = m_memory.GetSize();
   const int new_size = old_size + allocated_size;
-  
+
   // Make sure that the new size is in range.
   if (new_size > MAX_CREATURE_SIZE  ||  new_size < MIN_CREATURE_SIZE) {
     m_organism->Fault(FAULT_LOC_ALLOC, FAULT_TYPE_ERROR,
@@ -1432,7 +1433,7 @@
                                new_size));
     return false;
   }
-  
+
   const int max_alloc_size = (int) (old_size * m_world->GetConfig().CHILD_SIZE_RANGE.Get());
   if (allocated_size > max_alloc_size) {
     m_organism->Fault(FAULT_LOC_ALLOC, FAULT_TYPE_ERROR,
@@ -1440,7 +1441,7 @@
                                allocated_size, max_alloc_size));
     return false;
   }
-  
+
   const int max_old_size =
     (int) (allocated_size * m_world->GetConfig().CHILD_SIZE_RANGE.Get());
   if (old_size > max_old_size) {
@@ -1449,7 +1450,7 @@
                                old_size, max_old_size));
     return false;
   }
-  
+
   switch (m_world->GetConfig().ALLOC_METHOD.Get()) {
     case ALLOC_METHOD_NECRO:
       // Only break if this succeeds -- otherwise just do random.
@@ -1461,7 +1462,7 @@
       Allocate_Default(new_size);
       break;
   }
-  
+
   m_mal_active = true;
 
   return true;
@@ -1474,67 +1475,67 @@
     if (m_memory.FlagCopied(i)) copied_size++;
   }
   return copied_size;
-}  
+}
 
 
 bool cHardwareCPU::Divide_Main(cAvidaContext& ctx, const int div_point,
                                const int extra_lines, double mut_multiplier)
 {
   const int child_size = m_memory.GetSize() - div_point - extra_lines;
-  
+
   // Make sure this divide will produce a viable offspring.
   const bool viable = Divide_CheckViable(ctx, div_point, child_size);
   if (viable == false) return false;
-  
+
   // Since the divide will now succeed, set up the information to be sent
   // to the new organism
   cGenome& child_genome = m_organism->OffspringGenome().GetGenome();
   child_genome = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
   m_organism->OffspringGenome().SetHardwareType(GetType());
   m_organism->OffspringGenome().SetInstSetID(GetInstSetID());
-  
+
   // Make sure it is an exact copy at this point (before divide mutations) if required
   if (m_world->GetConfig().REQUIRE_EXACT_COPY.Get() && (m_organism->GetGenome() != child_genome) ) {
     return false;
   }
-  
+
   // Cut off everything in this memory past the divide point.
   m_memory.Resize(div_point);
-  
+
   // Handle Divide Mutations...
   Divide_DoMutations(ctx, mut_multiplier);
 
   // Many tests will require us to run the offspring through a test CPU;
   // this is, for example, to see if mutations need to be reverted or if
   // lineages need to be updated.
-  Divide_TestFitnessMeasures1(ctx); 
-  
+  Divide_TestFitnessMeasures1(ctx);
+
 #if INSTRUCTION_COSTS
   // reset first time instruction costs
   for (int i = 0; i < m_inst_ft_cost.GetSize(); i++) {
     m_inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
   }
 #endif
-  
+
   m_mal_active = false;
   if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) {
     m_advance_ip = false;
   }
-  
+
   // Activate the child
   bool parent_alive = m_organism->ActivateDivide(ctx);
 
   // Do more work if the parent lives through the birth of the offspring
   if (parent_alive) {
-  
-    if ( (m_world->GetConfig().EPIGENETIC_METHOD.Get() == EPIGENETIC_METHOD_PARENT) 
+
+    if ( (m_world->GetConfig().EPIGENETIC_METHOD.Get() == EPIGENETIC_METHOD_PARENT)
     || (m_world->GetConfig().EPIGENETIC_METHOD.Get() == EPIGENETIC_METHOD_BOTH) ) {
-      InheritState(*this);  
+      InheritState(*this);
     }
 
     if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
-  
+
   return true;
 }
 
@@ -1551,22 +1552,22 @@
 
   //cStats stats = m_world->GetStats();
   const int child_size = m_memory.GetSize() - div_point - extra_lines;
-  
+
   // Make sure this divide will produce a viable offspring.
   const bool viable = Divide_CheckViable(ctx, div_point, child_size);
   if (viable == false) return false;
-  
+
   // Since the divide will now succeed, set up the information to be sent
   // to the new organism
   cGenome& child_genome = m_organism->OffspringGenome().GetGenome();
   child_genome = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
   m_organism->OffspringGenome().SetHardwareType(GetType());
   m_organism->OffspringGenome().SetInstSetID(GetInstSetID());
-  
+
   // Cut off everything in this memory past the divide point.
   m_memory.Resize(div_point);
-  
-  unsigned 
+
+  unsigned
     totalMutations = 0,
     mutations = 0;
     //RScount = 0;
@@ -1593,10 +1594,10 @@
     }
 
     fitTest = Divide_TestFitnessMeasures1(ctx);
-    
+
     if(!fitTest && mutations >= totalMutations) break;
 
-  } 
+  }
   // think about making this mutations == totalMuations - though this may be too hard...
   /*
   if(RScount > 2)
@@ -1614,24 +1615,24 @@
     m_inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
   }
 #endif
-  
+
   m_mal_active = false;
   if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) {
     m_advance_ip = false;
   }
-  
+
   // Activate the child, and do more work if the parent lives through the
   // birth.
   bool parent_alive = m_organism->ActivateDivide(ctx);
   if (parent_alive) {
     if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
-  
+
   return true;
 }
 
 /*
-  Almost the same as Divide_Main, but only allows for one mutation 
+  Almost the same as Divide_Main, but only allows for one mutation
     on divde and resamples reverted offspring.
 
   RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTIONS OCCUR ON DIVIDE!!
@@ -1644,22 +1645,22 @@
 
   //cStats stats = m_world->GetStats();
   const int child_size = m_memory.GetSize() - div_point - extra_lines;
-  
+
   // Make sure this divide will produce a viable offspring.
   const bool viable = Divide_CheckViable(ctx, div_point, child_size);
   if (viable == false) return false;
-  
+
   // Since the divide will now succeed, set up the information to be sent
   // to the new organism
   cGenome& child_genome = m_organism->OffspringGenome().GetGenome();
   child_genome = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
   m_organism->OffspringGenome().SetHardwareType(GetType());
   m_organism->OffspringGenome().SetInstSetID(GetInstSetID());
-  
+
   // Cut off everything in this memory past the divide point.
   m_memory.Resize(div_point);
-  
-  unsigned 
+
+  unsigned
     totalMutations = 0,
     mutations = 0;
   //    RScount = 0;
@@ -1689,7 +1690,7 @@
     //if(mutations > 1 ) cerr << "Too Many mutations!!!!!!!!!!!!!!!" << endl;
     if(!fitTest && mutations >= totalMutations) break;
 
-  } 
+  }
   // think about making this mutations == totalMuations - though this may be too hard...
   /*
   if(RScount > 2)
@@ -1707,24 +1708,24 @@
     m_inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
   }
 #endif
-  
+
   m_mal_active = false;
   if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) {
     m_advance_ip = false;
   }
-  
+
   // Activate the child, and do more work if the parent lives through the
   // birth.
   bool parent_alive = m_organism->ActivateDivide(ctx);
   if (parent_alive) {
     if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
-  
+
   return true;
 }
 
 /*
-  Almost the same as Divide_Main, but only allows for one mutation 
+  Almost the same as Divide_Main, but only allows for one mutation
     on divde and resamples reverted offspring.
 
   RESAMPLING ONLY WORKS CORRECTLY WHEN ALL MUTIONS OCCUR ON DIVIDE!!
@@ -1737,22 +1738,22 @@
 
   //cStats stats = m_world->GetStats();
   const int child_size = m_memory.GetSize() - div_point - extra_lines;
-  
+
   // Make sure this divide will produce a viable offspring.
   const bool viable = Divide_CheckViable(ctx, div_point, child_size);
   if (viable == false) return false;
-  
+
   // Since the divide will now succeed, set up the information to be sent
   // to the new organism
   cGenome& child_genome = m_organism->OffspringGenome().GetGenome();
   child_genome = cGenomeUtil::Crop(m_memory, div_point, div_point+child_size);
   m_organism->OffspringGenome().SetHardwareType(GetType());
   m_organism->OffspringGenome().SetInstSetID(GetInstSetID());
-  
+
   // Cut off everything in this memory past the divide point.
   m_memory.Resize(div_point);
-  
-  unsigned 
+
+  unsigned
     totalMutations = 0,
     mutations = 0;
   //    RScount = 0;
@@ -1782,7 +1783,7 @@
     //if(mutations > 1 ) cerr << "Too Many mutations!!!!!!!!!!!!!!!" << endl;
     if(!fitTest && mutations >= totalMutations) break;
 
-  } 
+  }
   // think about making this mutations == totalMuations - though this may be too hard...
   /*
   if(RScount > 2)
@@ -1800,28 +1801,28 @@
     m_inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
   }
 #endif
-  
+
   m_mal_active = false;
   if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) {
     m_advance_ip = false;
   }
-  
+
   // Activate the child, and do more work if the parent lives through the
   // birth.
   bool parent_alive = m_organism->ActivateDivide(ctx);
   if (parent_alive) {
     if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
   }
-  
+
   return true;
 }
 
 // Sets the current state of the hardware and also saves this state so
 //  that future Reset() calls will reset to that epigenetic state
 void cHardwareCPU::InheritState(cHardwareBase& in_hardware)
-{ 
+{
   m_epigenetic_state = true;
-  cHardwareCPU& in_h = (cHardwareCPU&)in_hardware; 
+  cHardwareCPU& in_h = (cHardwareCPU&)in_hardware;
   const cLocalThread& thread = in_h.GetThread(in_h.GetCurThread());
   for (int i=0; i<NUM_REGISTERS; i++) {
     m_epigenetic_saved_reg[i] = thread.reg[i];
@@ -1839,11 +1840,11 @@
 {
   const int reg_used = FindModifiedRegister(REG_BX);
   if (GetRegister(reg_used) != 0)  IP().Advance();
-  return true; 
+  return true;
 }
 
 bool cHardwareCPU::Inst_IfNot0(cAvidaContext& ctx)       // Execute next if ?bx? != 0.
-{ 
+{
   const int reg_used = FindModifiedRegister(REG_BX);
   if (GetRegister(reg_used) == 0)  IP().Advance();
   return true;
@@ -1956,13 +1957,13 @@
   //    no nop label (default): valueToCompare = 1; nop-A: valueToCompare = -1
   //                     nop-B: valueToCompare = 2; nop-C: valueToCompare =  4
   // @LMG 2/13/2009
-  
+
   int valueToCompare = 1;
-  
+
   if (m_inst_set->IsNop(IP().GetNextInst())) {
-    IP().Advance();    
+    IP().Advance();
     switch (m_inst_set->GetNopMod(IP().GetInst())) {
-        
+
       case REG_AX:
         valueToCompare = -1; break;
       case REG_BX:
@@ -1973,11 +1974,11 @@
         valueToCompare =  1; break;
     }
     IP().SetFlagExecuted();
-    
+
   }
-  
+
   if (GetRegister(REG_BX) <= valueToCompare)  IP().Advance();
-  
+
   return true;
 }
 
@@ -1987,13 +1988,13 @@
   //    no nop label (default): valueToCompare = 1; nop-A: valueToCompare = -1
   //                     nop-B: valueToCompare = 2; nop-C: valueToCompare =  4
   // @LMG 2/13/2009
-  
+
   int valueToCompare = 1;
-  
+
   if (m_inst_set->IsNop(IP().GetNextInst())) {
     IP().Advance();
     switch (m_inst_set->GetNopMod(IP().GetInst())) {
-        
+
       case REG_AX:
         valueToCompare = -1; break;
       case REG_BX:
@@ -2004,11 +2005,11 @@
         valueToCompare =  1; break;
     }
     IP().SetFlagExecuted();
-    
+
   }
-  
+
   if (GetRegister(REG_BX) != valueToCompare)  IP().Advance();
-  
+
   return true;
 }
 
@@ -2048,20 +2049,20 @@
 {
   ReadLabel();
   GetLabel().Rotate(1, NUM_NOPS);
-  
+
   // If there is no label, jump BX steps.
   if (GetLabel().GetSize() == 0) {
     GetActiveHead().Jump(GetRegister(REG_BX));
     return true;
   }
-  
+
   // Otherwise, try to jump to the complement label.
   const cHeadCPU jump_location(FindLabel(1));
   if ( jump_location.GetPosition() != -1 ) {
     GetActiveHead().Set(jump_location);
     return true;
   }
-  
+
   // If complement label was not found; record an error.
   m_organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_ERROR,
                   "jump-f: No complement label");
@@ -2073,20 +2074,20 @@
 {
   ReadLabel();
   GetLabel().Rotate(1, NUM_NOPS);
-  
+
   // If there is no label, jump BX steps.
   if (GetLabel().GetSize() == 0) {
     GetActiveHead().Jump(GetRegister(REG_BX));
     return true;
   }
-  
+
   // otherwise jump to the complement label.
   const cHeadCPU jump_location(FindLabel(-1));
   if ( jump_location.GetPosition() != -1 ) {
     GetActiveHead().Set(jump_location);
     return true;
   }
-  
+
   // If complement label was not found; record an error.
   m_organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_ERROR,
                   "jump-b: No complement label");
@@ -2098,22 +2099,22 @@
   // Put the starting location onto the stack
   const int location = IP().GetPosition();
   StackPush(location);
-  
+
   // Jump to the compliment label (or by the ammount in the bx register)
   ReadLabel();
   GetLabel().Rotate(1, NUM_NOPS);
-  
+
   if (GetLabel().GetSize() == 0) {
     IP().Jump(GetRegister(REG_BX));
     return true;
   }
-  
+
   const cHeadCPU jump_location(FindLabel(1));
   if (jump_location.GetPosition() != -1) {
     IP().Set(jump_location);
     return true;
   }
-  
+
   // If complement label was not found; record an error.
   m_organism->Fault(FAULT_LOC_JUMP, FAULT_TYPE_ERROR,
                   "call: no complement label");
@@ -2133,12 +2134,12 @@
 
   //Look for the label directly (no complement)
   ReadLabel();
-    
+
   cHeadCPU search_head(IP());
   int start_pos = search_head.GetPosition();
   search_head++;
-  
-  while (start_pos != search_head.GetPosition()) 
+
+  while (start_pos != search_head.GetPosition())
   {
     // If we find a catch instruction, compare the NOPs following it
     if (search_head.GetInst() == catch_inst)
@@ -2150,16 +2151,16 @@
       //  (1) It ends (=> use the catch!)
       //  (2) It becomes longer than the throw label (=> use the catch!)
       //  (3) We find a NOP that doesnt match the throw (=> DON'T use the catch...)
-      
+
       bool match = true;
-      int size_matched = 0;      
+      int size_matched = 0;
       while ( match && m_inst_set->IsNop(search_head.GetInst()) && (size_matched < GetLabel().GetSize()) )
       {
         if ( GetLabel()[size_matched] != m_inst_set->GetNopMod( search_head.GetInst()) ) match = false;
         search_head++;
         size_matched++;
       }
-      
+
       // We found a matching catch instruction
       if (match)
       {
@@ -2168,7 +2169,7 @@
                               // so we mark the catch as executed.
         return true;
       }
-      
+
       //If we advanced past NOPs during testing, retreat
       if ( !m_inst_set->IsNop(search_head.GetInst()) ) search_head--;
     }
@@ -2198,12 +2199,12 @@
 
   //Look for an EXACT label match after a 'label' instruction
   ReadLabel();
-  
+
   cHeadCPU search_head(IP());
   int start_pos = search_head.GetPosition();
   search_head++;
-  
-  while (start_pos != search_head.GetPosition()) 
+
+  while (start_pos != search_head.GetPosition())
   {
     if (search_head.GetInst() == label_inst)
     {
@@ -2219,8 +2220,8 @@
         size_matched++;
         search_head++;
       }
-      
-      // We found a matching 'label' instruction only if the next 
+
+      // We found a matching 'label' instruction only if the next
       // instruction (at the search head now) is also not a NOP
       if ( (size_matched == GetLabel().GetSize()) && !m_inst_set->IsNop(search_head.GetInst()) )
       {
@@ -2572,10 +2573,10 @@
 
 bool cHardwareCPU::Inst_NandTreatable(cAvidaContext& ctx)
 {
-/*	
+/*
 	if(!m_organism->GetDeme()->isTreatable() && m_world->GetRandom().P(probFail))
 		return true;
-	
+
   const int dst = FindModifiedRegister(REG_BX);
   const int op1 = REG_BX;
   const int op2 = REG_CX;
@@ -2635,7 +2636,7 @@
 
   const cHeadCPU from(this, GetRegister(op1));
   cHeadCPU to(this, GetRegister(op2) + GetRegister(op1));
-  
+
   if (m_organism->TestCopyMut(ctx)) {
     to.SetInst(m_inst_set->GetRandomInst(ctx));
     to.SetFlagMutated();  // Mark this instruction as mutated...
@@ -2645,7 +2646,7 @@
     to.ClearFlagMutated();  // UnMark
     to.ClearFlagCopyMut();  // UnMark
   }
-  
+
   to.SetFlagCopied();  // Set the copied flag.
 //  cpu_stats.mut_stats.copies_exec++;
   return true;
@@ -2657,7 +2658,7 @@
   const int src = REG_BX;
 
   const cHeadCPU from(this, GetRegister(src));
-  
+
   // Dis-allowing mutations on read, for the moment (write only...)
   // @CAO This allows perfect error-correction...
   GetRegister(dst) = from.GetInst().GetOp();
@@ -2702,7 +2703,7 @@
   const int op1 = REG_AX;
   cHeadCPU to(this, GetRegister(op1) + GetRegister(dst));
   const int value = Mod(StackPop(), m_inst_set->GetSize());
-  
+
   // Change value on a mutation...
   if (m_organism->TestCopyMut(ctx)) {
     to.SetInst(m_inst_set->GetRandomInst(ctx));
@@ -2713,7 +2714,7 @@
     to.ClearFlagMutated();     // UnMark
     to.ClearFlagCopyMut();     // UnMark
   }
-  
+
   to.SetFlagCopied();  // Set the copied flag.
   return true;
 }
@@ -2726,16 +2727,16 @@
 
   cHeadCPU from(this, GetRegister(op1));
   cHeadCPU to(this, GetRegister(op2) + GetRegister(op1));
-  
+
   // Compare is dangerous -- it can cause mutations!
   if (m_organism->TestCopyMut(ctx)) {
     to.SetInst(m_inst_set->GetRandomInst(ctx));
     to.SetFlagMutated();      // Mark this instruction as mutated...
     to.SetFlagCopyMut();      // Mark this instruction as copy mut...
   }
-  
+
   GetRegister(dst) = from.GetInst().GetOp() - to.GetInst().GetOp();
-  
+
   return true;
 }
 
@@ -2746,7 +2747,7 @@
 
   const cHeadCPU from(this, GetRegister(op1));
   const cHeadCPU to(this, GetRegister(op2) + GetRegister(op1));
-  
+
   // Allow for errors in this test...
   if (m_organism->TestCopyMut(ctx)) {
     if (from.GetInst() != to.GetInst()) IP().Advance();
@@ -2767,35 +2768,35 @@
   } else return false;
 }
 
-bool cHardwareCPU::Inst_Divide(cAvidaContext& ctx)  
-{ 
+bool cHardwareCPU::Inst_Divide(cAvidaContext& ctx)
+{
   const int src = REG_AX;
-  return Divide_Main(ctx, GetRegister(src));    
+  return Divide_Main(ctx, GetRegister(src));
 }
 
 /*
-  Divide with resampling -- Same as regular divide but on reversions will be 
+  Divide with resampling -- Same as regular divide but on reversions will be
   resampled after they are reverted.
 
   AWC 06/29/06
 
  */
 
-bool cHardwareCPU::Inst_DivideRS(cAvidaContext& ctx)  
-{ 
+bool cHardwareCPU::Inst_DivideRS(cAvidaContext& ctx)
+{
   const int src = REG_AX;
-  return Divide_MainRS(ctx, GetRegister(src));    
+  return Divide_MainRS(ctx, GetRegister(src));
 }
 
 
-bool cHardwareCPU::Inst_CDivide(cAvidaContext& ctx) 
-{ 
-  return Divide_Main(ctx, m_memory.GetSize() / 2);   
+bool cHardwareCPU::Inst_CDivide(cAvidaContext& ctx)
+{
+  return Divide_Main(ctx, m_memory.GetSize() / 2);
 }
 
-bool cHardwareCPU::Inst_CAlloc(cAvidaContext& ctx)  
-{ 
-  return Allocate_Main(ctx, m_memory.GetSize());   
+bool cHardwareCPU::Inst_CAlloc(cAvidaContext& ctx)
+{
+  return Allocate_Main(ctx, m_memory.GetSize());
 }
 
 bool cHardwareCPU::Inst_MaxAlloc(cAvidaContext& ctx)   // Allocate maximal more
@@ -2835,7 +2836,7 @@
   // This only works if 'transposon' is in the current instruction set
   static bool transposon_in_use = GetInstSet().InstInSet(cStringUtil::Stringf("transposon"));
   if (!transposon_in_use) return;
-  
+
   static cInstruction transposon_inst = GetInstSet().GetInst(cStringUtil::Stringf("transposon"));
   cGenome& child_genome = m_organism->OffspringGenome().GetGenome();
 
@@ -2844,7 +2845,7 @@
   for (int i = 0; i < m_memory.GetSize(); i++) {
     if (m_memory.FlagExecuted(i) && (m_memory[i] == transposon_inst)) tr_count++;
   }
-  
+
   for (int i = 0; i < tr_count; i++) {
     if (ctx.GetRandom().P(0.01)) {
       const unsigned int mut_line = ctx.GetRandom().GetUInt(child_genome.GetSize() + 1);
@@ -2857,24 +2858,254 @@
 // Inst_ReproDeme replicates a deme using cPopulation::ReplicateDeme.
 // It is similar to Inst_SpawnDeme, but the implementation of Inst_SpawnDeme doesn't contain many new deme-level replication features
 bool cHardwareCPU::Inst_ReproDeme(cAvidaContext& ctx) {
-	
+
 	cDeme* sourceDeme = m_organism->GetOrgInterface().GetDeme();
 	if(sourceDeme == NULL)
 		return false; // in test CPU
-	
+
 	// this function will become to depend on a predicate, but I am still thinking of how to do this (BEB)
 	sourceDeme->ReplicateDeme();
 	return true;
 }
 
-bool cHardwareCPU::Inst_Repro(cAvidaContext& ctx)
-{ 
+// Inst_ReproduceDeme replicates a deme.  This is differentiated from Inst_ReproDeme, since Inst_ReproDeme sets a flag for reproduction at the next event.
+// This instruction is intended to be an immediate deme reproduction.
+bool cHardwareCPU::Inst_ReproduceDeme(cAvidaContext& ctx) {
+
+	double meritadjustment = 1.0;
+
+
+	cDeme* sourceDeme = m_organism->GetOrgInterface().GetDeme();
+	if(sourceDeme == NULL)
+		return false; // in test CPU
+
+	int left_cell = 0;
+	int center_cell = 1;
+	int right_cell = 2;
+
+	if(m_organism != sourceDeme->GetOrganism(center_cell))
+	{
+		return false;
+	}
+
+	int total_cycles_executed = 0;
+	int alive_orgs = 0;
+	double total_deme_merit = 1;
+
+	int cycle_bonus = 0;
+
+
+	//TESTING ONLY ALLOWING REPRODEME IF DEME IS FULL
+	if((sourceDeme->GetOrganism(left_cell) == NULL) || (sourceDeme->GetOrganism(center_cell) == NULL) || (sourceDeme->GetOrganism(right_cell) == NULL))
+		return false;
+
+	if(sourceDeme->GetOrganism(left_cell) != NULL)
+	{
+		total_cycles_executed += sourceDeme->GetOrganism(left_cell)->GetPhenotype().GetCPUCyclesUsed();
+		alive_orgs++;
+		total_deme_merit += sourceDeme->GetOrganism(left_cell)->GetGenotype()->GetMerit();
+		tArray<int> orgReactions = sourceDeme->GetOrganism(left_cell)->GetPhenotype().GetCurReactionCount();
+		if(orgReactions[0] >= 1)
+		{
+			cycle_bonus += 200;
+			meritadjustment *= 20;
+		}
+		cycle_bonus += 200;
+	}
+
+	if(sourceDeme->GetOrganism(center_cell) != NULL)
+	{
+		total_cycles_executed += sourceDeme->GetOrganism(center_cell)->GetPhenotype().GetCPUCyclesUsed();
+		alive_orgs++;
+		total_deme_merit += sourceDeme->GetOrganism(center_cell)->GetGenotype()->GetMerit();
+		tArray<int> orgReactions = sourceDeme->GetOrganism(center_cell)->GetPhenotype().GetCurReactionCount();
+	}
+
+	if(sourceDeme->GetOrganism(right_cell) != NULL)
+	{
+		total_cycles_executed += sourceDeme->GetOrganism(right_cell)->GetPhenotype().GetCPUCyclesUsed();
+		alive_orgs++;
+		total_deme_merit += sourceDeme->GetOrganism(right_cell)->GetGenotype()->GetMerit();
+		tArray<int> orgReactions = sourceDeme->GetOrganism(right_cell)->GetPhenotype().GetCurReactionCount();
+		if(orgReactions[2] >= 1)
+		{
+			cycle_bonus += 200;
+			meritadjustment*=20;
+		}
+		cycle_bonus += 200;
+
+	}
+
+
+
+	if(alive_orgs == 1)
+	{
+//		meritadjustment *= 1;
+	}
+	if(alive_orgs == 2)
+	{
+//		meritadjustment *= 20;
+	}
+	if(alive_orgs == 3)
+	{
+//		meritadjustment *= 50;
+	}
+
+
+	total_deme_merit = meritadjustment;
+	int parent_size = m_memory.GetSize();
+	const int executed_size = calcExecutedSize(parent_size);
+	const int min_exe_lines = static_cast<int>(parent_size * m_world->GetConfig().MIN_EXE_LINES.Get());
+	if (executed_size < min_exe_lines)
+	{
+//	    m_organism->Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR,
+//                    cStringUtil::Stringf("Too few executed lines (%d < %d)", executed_size, min_exe_lines));
+	}
+
+
+//	if(executed_size > min_exe_lines) //  total_cycles_executed > 100)
+//	{
+/*
+		  AdjustHeads();
+
+		  const int divide_pos = GetHead(nHardware::HEAD_READ).GetPosition();
+		  int child_end =  GetHead(nHardware::HEAD_WRITE).GetPosition();
+		  if (child_end == 0) child_end = m_memory.GetSize();
+		  const int extra_lines = m_memory.GetSize() - child_end;
+
+//		  cGenome& child_genome = m_organism->OffspringGenome().GetGenome();
+//		  child_genome = cGenomeUtil::Crop(m_memory, 0, div_pos);
+
+		  if(divide_pos > 0)
+		  {
+	//		  m_memory.Resize(divide_pos);
+		  }
+		  else
+		  {
+			  return false;
+		  }
+		  // Re-adjust hea<ds.
+		  AdjustHeads();
+*/
+		m_world->GetPopulation().ReplicateDeme2(ctx, *sourceDeme, total_deme_merit);  //sourceDeme
+//	}
+//	else
+//	{
+//		return false;
+//	}
+
+
+
+	return true;
+}
+
+// Inst_ReproLimited is designed to work similarly to Inst_Repro, with the caveat that instead of copying the entire genome, it only
+// copies the region between the read and write head.
+bool cHardwareCPU::Inst_ReproLimited(cAvidaContext& ctx)
+{
   // check if repro can replace an existing organism
   if(m_world->GetConfig().REPRO_METHOD.Get() == 0 && m_organism->IsNeighborCellOccupied())
     return false;
 
+  // Setup child
+  cDeme* sourceDeme = m_organism->GetOrgInterface().GetDeme();
+  if(sourceDeme == NULL)
+	return false; // in test CPU
+
+  int left_cell = 0;
+  int center_cell = 1;
+  int right_cell = 2;
+  if(m_organism != sourceDeme->GetOrganism(center_cell))
+  {
+    return false;
+  }
+
+  cGenome& child_genome = m_organism->OffspringGenome().GetGenome();
+
+  child_genome = m_organism->GetGenome();
+
+  AdjustHeads();
+
+  const int divide_pos = GetHead(nHardware::HEAD_READ).GetPosition();
+  int child_end =  GetHead(nHardware::HEAD_WRITE).GetPosition();
+  if (child_end == 0) child_end = m_memory.GetSize();
+  const int extra_lines = m_memory.GetSize() - child_end;
+
+
+  if((child_end - divide_pos) > 0)
+  {
+    child_genome = cGenomeUtil::Crop(m_memory, divide_pos, child_end);
+  }
+  else
+  {
+	return false;
+  }
+
+  // Re-adjust hea<ds.
+  AdjustHeads();
+  doDifferentiationMutation(ctx, child_genome);
+
+
+
+
+	// Check viability
+  bool viable = Divide_CheckViable(ctx, m_organism->GetGenome().GetSize(), child_genome.GetSize(), 1);
+  if (!viable) { return false; }
+  if(child_genome.GetSize() <= 0)
+  {
+	return false;
+  }
+
+  #if INSTRUCTION_COSTS
+    // reset first time instruction costs
+    for (int i = 0; i < m_inst_ft_cost.GetSize(); i++)
+    {
+	   m_inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
+    }
+  #endif
+
+  int destcellID = m_world->GetPopulation().GetCell(m_organism->GetCellID()).GetCellFaced().GetID();
+  cGenotype* child_genotype =m_organism->GetGenotype();
+
+  if (child_genome != m_organism->GetGenome()) // if the phenotypes are different.
+  {
+    // Add this genotype with only one parent since its asexual.
+    child_genotype = m_world->GetClassificationManager().GetGenotype(child_genome, m_organism->GetGenotype(), NULL);
+  }
+
+  m_organism->GetGenotype()->SetBreedStats(*child_genotype);
+  child_genotype->IncDeferAdjust();
+
+  m_world->GetPopulation().KillOrganism(m_world->GetPopulation().GetCell(destcellID));
+
+  m_world->GetPopulation().InjectGenotype(destcellID, child_genotype);
+
+  child_genotype->DecDeferAdjust();
+  m_world->GetClassificationManager().AdjustGenotype(*child_genotype);
+
+
+	//	return m_world->GetPopulation().ActivateOffspring(ctx, child_genome, m_organism);
+	//Reset the parent
+	//if (parent_alive) {
+	//  if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
+	//}
+
+
+	  return true;
+}
+
+
+
+
+
+bool cHardwareCPU::Inst_Repro(cAvidaContext& ctx)
+{
+  // check if repro can replace an existing organism
+  if(m_world->GetConfig().REPRO_METHOD.Get() == 0 && m_organism->IsNeighborCellOccupied())
+      return false;
+
   if (m_organism->GetPhenotype().GetCurBonus() < m_world->GetConfig().REQUIRED_BONUS.Get()) return false;
-  
+
   // Setup child
   cGenome& child_genome = m_organism->OffspringGenome().GetGenome();
   child_genome = m_organism->GetGenome();
@@ -2883,7 +3114,7 @@
 
   // Do transposon movement and copying before other mutations
   Divide_DoTransposons(ctx);
-  
+
   // Perform Copy Mutations...
   if (m_organism->GetCopyMutProb() > 0) { // Skip this if no mutations....
     for (int i = 0; i < m_memory.GetSize(); i++) {
@@ -2892,29 +3123,29 @@
       }
     }
   }
-  
+
   Divide_DoMutations(ctx);
-  
+
   // Check viability
   bool viable = Divide_CheckViable(ctx, m_organism->GetGenome().GetSize(), m_organism->OffspringGenome().GetSize(), 1);
   if (!viable) { return false; }
-  
+
   // Many tests will require us to run the offspring through a test CPU;
   // this is, for example, to see if mutations need to be reverted or if
   // lineages need to be updated.
   Divide_TestFitnessMeasures(ctx);
-  
+
 #if INSTRUCTION_COSTS
   // reset first time instruction costs
   for (int i = 0; i < m_inst_ft_cost.GetSize(); i++) {
     m_inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
   }
 #endif
-  
+
   if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) m_advance_ip = false;
-  
+
   const bool parent_alive = m_organism->ActivateDivide(ctx);
-  
+
   //Reset the parent
   if (parent_alive) {
     if (m_world->GetConfig().DIVIDE_METHOD.Get() == DIVIDE_METHOD_SPLIT) Reset(ctx);
@@ -2933,12 +3164,12 @@
 {
   // Do normal IO, but don't zero register
   //Inst_TaskPut(ctx);
-  
+
   const int reg_used = FindModifiedRegister(REG_BX);
   const int value = GetRegister(reg_used);
  // GetRegister(reg_used) = 0;
   m_organism->DoOutput(ctx, value);
-  
+
   // Immediately attempt a repro
   return Inst_Repro(ctx);
 }
@@ -2947,12 +3178,12 @@
 {
   // Do normal IO
   bool return_value = Inst_TaskPutResetInputs(ctx);
-  
+
   // Immediately attempt a repro
   Inst_Repro(ctx);
 
   // return value of put since successful repro would wipe state anyway
-  return return_value; 
+  return return_value;
 }
 
 bool cHardwareCPU::Inst_SpawnDeme(cAvidaContext& ctx)
@@ -2969,7 +3200,7 @@
   return true;
 }
 
-                   
+
 bool cHardwareCPU::Inst_Sterilize(cAvidaContext& ctx)
 {
   m_organism->GetPhenotype().IsFertile() = false;
@@ -2991,7 +3222,7 @@
 }
 
 /* Similar to Kazi, this instructon probabilistically causes
- the organism to die. However, in this case it does so in 
+ the organism to die. However, in this case it does so in
  order to win points for its deme and it does not take out
  any other organims. */
 bool  cHardwareCPU::Inst_Suicide(cAvidaContext& ctx)
@@ -3034,7 +3265,7 @@
       numOcuppiedNeighbors++;
     }
     m_organism->Rotate(1);
-  }  
+  }
   assert(m_organism->GetFacing() == orginalFacing);
 
   for(int i = 0; i < m_organism->GetNeighborhoodSize(); i++) {
@@ -3074,7 +3305,7 @@
   const int start_pos = GetHead(nHardware::HEAD_READ).GetPosition();
   const int end_pos = GetHead(nHardware::HEAD_WRITE).GetPosition();
   const int inject_size = end_pos - start_pos;
-  
+
   // Make sure the creature will still be above the minimum size,
   if (inject_size <= 0) {
     m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: no code to inject");
@@ -3084,37 +3315,37 @@
     m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: new size too small");
     return false; // (inject fails)
   }
-  
+
   // Since its legal to cut out the injected piece, do so.
   cGenome inject_code(cGenomeUtil::Crop(m_memory, start_pos, end_pos));
   m_memory.Remove(start_pos, inject_size);
   AdjustHeads();
-  
+
   // If we don't have a host, stop here.
   cOrganism * host_organism = m_organism->GetNeighbor();
   if (host_organism == NULL) return false;
-  
+
   // Scan for the label to match...
   ReadLabel();
-  
+
   // If there is no label, abort.
   if (GetLabel().GetSize() == 0) {
     m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: label required");
     return false; // (inject fails)
   }
-  
+
   // Search for the label in the host...
   GetLabel().Rotate(1, NUM_NOPS);
-  
+
   const bool inject_signal = host_organism->GetHardware().InjectHost(GetLabel(), inject_code);
   if (inject_signal) {
     m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_WARNING, "inject: host too large.");
     return false; // Inject failed.
   }
-  
+
   // Set the relevent flags.
   m_organism->GetPhenotype().IsModifier() = true;
-  
+
   return inject_signal;
 }
 
@@ -3142,7 +3373,7 @@
   const int start_pos = GetHead(nHardware::HEAD_READ).GetPosition();
   const int end_pos = GetHead(nHardware::HEAD_WRITE).GetPosition();
   const int inject_size = end_pos - start_pos;
-  
+
   // Make sure the creature will still be above the minimum size,
   if (inject_size <= 0) {
     m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: no code to inject");
@@ -3152,34 +3383,34 @@
     m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: new size too small");
     return false; // (inject fails)
   }
-  
+
   // Since its legal to cut out the injected piece, do so.
   cGenome inject_code( cGenomeUtil::Crop(m_memory, start_pos, end_pos) );
   m_memory.Remove(start_pos, inject_size);
-  
+
   // If we don't have a host, stop here.
   cOrganism * host_organism = m_organism->GetNeighbor();
   if (host_organism == NULL) return false;
-  
+
   // Scan for the label to match...
   ReadLabel();
-  
+
   // If there is no label, abort.
   if (GetLabel().GetSize() == 0) {
     m_organism->Fault(FAULT_LOC_INJECT, FAULT_TYPE_ERROR, "inject: label required");
     return false; // (inject fails)
   }
-  
+
   // Search for the label in the host...
   GetLabel().Rotate(1, NUM_NOPS);
-  
+
   if (host_organism->GetHardware().InjectHost(GetLabel(), inject_code)) {
     if (ForkThread()) m_organism->GetPhenotype().IsMultiThread() = true;
   }
-  
+
   // Set the relevent flags.
   m_organism->GetPhenotype().IsModifier() = true;
-  
+
   return true;
 }
 
@@ -3203,15 +3434,15 @@
 
   const int reg_used_1 = FindModifiedRegister(REG_BX);
   const int reg_used_2 = FindNextRegister(reg_used_1);
-  
+
   const int value1 = m_organism->GetNextInput();
   GetRegister(reg_used_1) = value1;
   m_organism->DoInput(value1);
-  
+
   const int value2 = m_organism->GetNextInput();
   GetRegister(reg_used_2) = value2;
   m_organism->DoInput(value2);
-  
+
   return true;
 }
 
@@ -3226,7 +3457,7 @@
 bool cHardwareCPU::Inst_TaskStackLoad(cAvidaContext& ctx)
 {
   // @DMB - TODO: this should look at the input_size...
-  for (int i = 0; i < 3; i++) 
+  for (int i = 0; i < 3; i++)
     StackPush( m_organism->GetNextInput() );
   return true;
 }
@@ -3252,11 +3483,11 @@
 bool cHardwareCPU::Inst_TaskIO(cAvidaContext& ctx)
 {
   const int reg_used = FindModifiedRegister(REG_BX);
-  
+
   // Do the "put" component
   const int value_out = GetRegister(reg_used);
   m_organism->DoOutput(ctx, value_out);  // Check for tasks completed.
-  
+
   // Do the "get" component
   const int value_in = m_organism->GetNextInput();
   GetRegister(reg_used) = value_in;
@@ -3271,7 +3502,7 @@
   if (new_bonus < 0) new_bonus = 0;
   //keep the bonus positive or zero
   m_organism->GetPhenotype().SetCurBonus(new_bonus);
-  
+
   return Inst_TaskIO(ctx);
 }
 
@@ -3281,15 +3512,15 @@
 
   //check cur_bonus before the output
   double preOutputBonus = m_organism->GetPhenotype().GetCurBonus();
-  
+
   // Do the "put" component
   const int value_out = GetRegister(reg_used);
   m_organism->DoOutput(ctx, value_out);  // Check for tasks completed.
 
   //check cur_merit after the output
-  double postOutputBonus = m_organism->GetPhenotype().GetCurBonus(); 
-  
-  
+  double postOutputBonus = m_organism->GetPhenotype().GetCurBonus();
+
+
   //push the effect of the IO on merit (+,0,-) to the active stack
 
   if (preOutputBonus > postOutputBonus){
@@ -3307,10 +3538,10 @@
     }
 
 
-  
 
 
-  
+
+
   // Do the "get" component
   const int value_in = m_organism->GetNextInput();
   GetRegister(reg_used) = value_in;
@@ -3376,9 +3607,9 @@
 
 bool cHardwareCPU::DoSense(cAvidaContext& ctx, int conversion_method, double base)
 {
-  // Returns the amount of a resource or resources 
+  // Returns the amount of a resource or resources
   // specified by modifying NOPs into register BX
-  const tArray<double> res_count = m_organism->GetOrgInterface().GetResources() + 
+  const tArray<double> res_count = m_organism->GetOrgInterface().GetResources() +
     m_organism->GetOrgInterface().GetDemeResources(m_organism->GetOrgInterface().GetDemeID());
 
   // Arbitrarily set to BX since the conditional instructions use this directly.
@@ -3391,7 +3622,7 @@
   static int last_num_resources = 0;
   static int max_label_length = 0;
   int num_nops = GetInstSet().GetNumNops();
-  
+
   if ((last_num_resources != res_count.GetSize()))
   {
       max_label_length = (int) ceil(log((double)res_count.GetSize())/log((double)num_nops));
@@ -3403,33 +3634,33 @@
   // to uniquely specify a resource, then add together
   // a subset of resources (motivation: regulation can evolve
   // to be more specific if there is an advantage)
-   
+
   // Find the maximum number of NOPs needed to specify this number of resources
   // Note: It's a bit wasteful to recalculate this every time and organisms will
   // definitely be confused if the number of resources changes during a run
   // because their mapping to resources will be disrupted
-  
+
   // Attempt to read a label with this maximum length
   ReadLabel(max_label_length);
-  
+
   // Find the length of the label that we actually obtained (max is max_reg_needed)
   int real_label_length = GetLabel().GetSize();
-  
-  // Start and end labels to define the start and end indices of  
+
+  // Start and end labels to define the start and end indices of
   // resources that we need to add together
   cCodeLabel start_label = cCodeLabel(GetLabel());
   cCodeLabel   end_label = cCodeLabel(GetLabel());
-  
+
   for (int i = 0; i < max_label_length - real_label_length; i++)
   {
     start_label.AddNop(0);
     end_label.AddNop(num_nops-1);
   }
-  
+
   int start_index = start_label.AsInt(num_nops);
   int   end_index =   end_label.AsInt(num_nops);
 
-  // If the label refers to ONLY resources that 
+  // If the label refers to ONLY resources that
   // do not exist, then the operation fails
   if (start_index >= res_count.GetSize()) return false;
 
@@ -3453,9 +3684,9 @@
         // Do some range checking to make sure we don't overflow
         resource_result = (INT_MAX - resource_result <= add_amount) ? INT_MAX : resource_result + add_amount;
       }
-    } 
+    }
   }
-  
+
   // Take the log after adding resource amounts together! This way a zero can be assigned to INT_MIN
   if (conversion_method == 0) // Log2
   {
@@ -3469,10 +3700,10 @@
       resource_result = (int)(log(dresource_result)/log(base));
     }
   }
-    
+
   //Dump this value into an arbitrary register: BX
   GetRegister(reg_to_set) = resource_result;
-  
+
   //We have to convert this to a different index that includes all degenerate labels possible: shortest to longest
   int sensed_index = 0;
   int on = 1;
@@ -3483,15 +3714,15 @@
   }
   sensed_index+= GetLabel().AsInt(num_nops);
   m_organism->GetPhenotype().IncSenseCount(sensed_index);
-  
-  return true; 
 
+  return true;
+
   // Note that we are converting <double> resources to <int> register values
 }
 
-/* Convert modifying NOPs to the index of a resource. If there are fewer 
- * than the number of NOPs required to specify a resource, find the subset 
- * of resources.  (Motivation: can evolve to be more specific if there is 
+/* Convert modifying NOPs to the index of a resource. If there are fewer
+ * than the number of NOPs required to specify a resource, find the subset
+ * of resources.  (Motivation: can evolve to be more specific if there is
  * an advantage.)
  *
  * Mostly ripped from Jeff B.'s DoSense(); meant to be a helper function for
@@ -3500,9 +3731,9 @@
  *
  * returns true if successful, false otherwise
  *
- * start_index and end_index of resource range are "returned" via their 
- * respective arguments; any int at all may be passed to these, as it will just 
- * get overwritten.  (Obviously, if the resource is fully specified, 
+ * start_index and end_index of resource range are "returned" via their
+ * respective arguments; any int at all may be passed to these, as it will just
+ * get overwritten.  (Obviously, if the resource is fully specified,
  * start_index == end_index.)
  *
  * spec_id is the id number of the specification
@@ -3511,39 +3742,39 @@
 bool cHardwareCPU::FindModifiedResource(int& start_index, int& end_index, int& spec_id)
 {
   int num_resources = m_organism->GetOrgInterface().GetResources().GetSize();
-  
+
   //if there are no resources, translation cannot be successful; return false
   if (num_resources <= 0)
   {return false;}
-  
+
   //calculate the maximum number of NOPs necessary to completely specify a resource
   int num_nops = GetInstSet().GetNumNops();
   int max_label_length = (int)(ceil(log((double)num_resources) / log((double)num_nops)));
-  
+
   //attempt to read a label of the maximum length
   ReadLabel(max_label_length);
-  
+
   //find the length of the label that was actually read
   int real_label_length = GetLabel().GetSize();
-  
+
   // save the specification id
   spec_id = GetLabel().AsIntUnique(num_nops);
-  
+
   /* find start and end resource indices specified by the label */
-  
+
   cCodeLabel start_label = cCodeLabel(GetLabel());
   cCodeLabel   end_label = cCodeLabel(GetLabel());
-  
+
   //fill out any labels that are not maximum length
   for (int i = 0; i < max_label_length - real_label_length; i++){
     start_label.AddNop(0);
     end_label.AddNop(num_nops - 1);
   }
-  
+
   //translate into resource indices
   start_index = start_label.AsInt(num_nops);
   end_index   =   end_label.AsInt(num_nops);
-  
+
   return true;
 }
 
@@ -3553,7 +3784,7 @@
  *
  * env_remove   - specifies whether the collected resources should be removed from
  *                the environment
- * internal_add - specifies whether the collected resources should be added to 
+ * internal_add - specifies whether the collected resources should be added to
  *                the organism's internal resources.
  */
 bool cHardwareCPU::DoCollect(cAvidaContext& ctx, bool env_remove, bool internal_add)
@@ -3562,7 +3793,7 @@
 
   bool finite_resources_exist = FindModifiedResource(start_bin, end_bin, spec_id);
   if(!finite_resources_exist) {return true;}
-  
+
   // Add this specification
   m_organism->IncCollectSpecCount(spec_id);
 
@@ -3604,12 +3835,12 @@
   if(bin_used >= 0)
   {
     res_change[bin_used] = -1 * (res_count[bin_used] * m_world->GetConfig().ABSORB_RESOURCE_FRACTION.Get());
-    
+
     if(internal_add && (max < 0 || (total + -1 * res_change[bin_used]) <= max))
     {m_organism->AddToRBin(bin_used, -1 * res_change[bin_used]);}
     else
     {res_change[bin_used] = 0.0;}
-    
+
     if(!env_remove)
     {res_change[bin_used] = 0.0;}
   }
@@ -3622,16 +3853,16 @@
       if(internal_add && (max < 0 || (total + -1 * res_change[i]) <= max))
       {m_organism->AddToRBin(i, -1 * res_change[i]);}
       else
-      {res_change[i] = 0.0;}   
-      
+      {res_change[i] = 0.0;}
+
       if(!env_remove)
       {res_change[i] = 0.0;}
     }
   }
-  
+
   // Update resource counts to reflect res_change
   m_organism->GetOrgInterface().UpdateResources(res_change);
-  
+
   return true;
 }
 
@@ -3659,14 +3890,14 @@
   return DoCollect(ctx, true, false);
 }
 
-/*! Sense the level of resources in this organism's cell, and if all of the 
+/*! Sense the level of resources in this organism's cell, and if all of the
 resources present are above the min level for that resource, execute the following
 intruction.  Otherwise, skip the following instruction.
 */
 bool cHardwareCPU::Inst_IfResources(cAvidaContext& ctx)
 {
   // These are the current levels of resources at this cell:
-  const tArray<double> resources = m_organism->GetOrgInterface().GetResources() + 
+  const tArray<double> resources = m_organism->GetOrgInterface().GetResources() +
     m_organism->GetOrgInterface().GetDemeResources(m_organism->GetOrgInterface().GetDemeID());
 
   // Now we loop through the different reactions, checking to see if their
@@ -3697,12 +3928,12 @@
 
   double cur_merit = m_organism->GetPhenotype().GetMerit().GetDouble();
   cur_merit -= merit_given;
-  if(cur_merit < 0) cur_merit=0; 
+  if(cur_merit < 0) cur_merit=0;
 
   // Plug the current merit back into this organism and notify the scheduler.
   m_organism->UpdateMerit(cur_merit);
   m_organism->GetPhenotype().SetIsEnergyDonor();
-  
+
   // Update the merit of the organism being donated to...
   double other_merit = to_org->GetPhenotype().GetMerit().GetDouble();
   other_merit += merit_received;
@@ -3716,19 +3947,19 @@
   assert(to_org != NULL);
 
   const double frac_energy_given = m_organism->GetFracEnergyDonating();
-  
+
   cPhenotype& phenotype = m_organism->GetPhenotype();
 
   double cur_energy = phenotype.GetStoredEnergy();
   double energy_given = cur_energy * frac_energy_given;
-  
+
   //update energy store and merit of donor
   phenotype.ReduceEnergy(energy_given);
   phenotype.IncreaseEnergyDonated(energy_given);
   double senderMerit = phenotype.ConvertEnergyToMerit(phenotype.GetStoredEnergy()  * phenotype.GetEnergyUsageRatio());
   m_organism->UpdateMerit(senderMerit);
   phenotype.SetIsEnergyDonor();
-  
+
   // update energy store and merit of donee
   to_org->GetPhenotype().ReduceEnergy(-1.0*energy_given);
   to_org->GetPhenotype().IncreaseEnergyReceived(energy_given);
@@ -3739,13 +3970,13 @@
 
 
 void cHardwareCPU::DoEnergyDonatePercent(cOrganism* to_org, const double frac_energy_given)
-{  
+{
   assert(to_org != NULL);
   assert(frac_energy_given >= 0);
   assert(frac_energy_given <= 1);
 
   DoEnergyDonateAmount(to_org, m_organism->GetPhenotype().GetStoredEnergy() * frac_energy_given);
-  
+
 } //End DoEnergyDonatePercent()
 
 
@@ -3755,54 +3986,54 @@
 void cHardwareCPU::DoEnergyDonateAmount(cOrganism* to_org, const double amount)
 {
   double losspct = m_world->GetConfig().ENERGY_SHARING_LOSS.Get();
-  
+
   assert(to_org != NULL);
   assert(amount >= 0);
   assert(losspct >= 0);
   assert(losspct <= 1);
 
   cPhenotype& phenotype = m_organism->GetPhenotype();
-  
+
   const int update_metabolic = m_world->GetConfig().ENERGY_SHARING_UPDATE_METABOLIC.Get();
   double energy_given = min(phenotype.GetStoredEnergy(), amount);
   double energy_received;
-  
+
   //update energy store and merit of donor
   phenotype.ReduceEnergy(energy_given);
   phenotype.SetIsEnergyDonor();
   phenotype.IncreaseEnergyDonated(energy_given);
   phenotype.IncreaseNumEnergyDonations();
-  
+
   m_organism->GetDeme()->IncreaseEnergyDonated(energy_given);
-  
+
   if(update_metabolic == 1) {
     double senderMerit = phenotype.ConvertEnergyToMerit(phenotype.GetStoredEnergy()  * phenotype.GetEnergyUsageRatio());
     m_organism->UpdateMerit(senderMerit);
   }
-  
+
   //apply loss in transfer
   energy_received = energy_given * (1 - losspct);
-  
+
   //place energy into receiver's incoming energy buffer
   to_org->GetPhenotype().ReceiveDonatedEnergy(energy_received);
   to_org->GetDeme()->IncreaseEnergyReceived(energy_received);   // Harder for phenotype to get the deme, so it's done here
-  
+
   //if we are using the push energy method, pass the new energy into the receiver's energy store and recalculate merit
   if(m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) {
     to_org->GetPhenotype().ApplyDonatedEnergy();
-	  
+
 	  if(update_metabolic == 1) {
       double receiverMerit = to_org->GetPhenotype().ConvertEnergyToMerit(to_org->GetPhenotype().GetStoredEnergy() * to_org->GetPhenotype().GetEnergyUsageRatio());
       to_org->UpdateMerit(receiverMerit);
 	  }
   }
-  
-  
-  if(m_world->GetConfig().LOG_ENERGY_SHARING.Get() == 1) {    
+
+
+  if(m_world->GetConfig().LOG_ENERGY_SHARING.Get() == 1) {
     cString tmpfilename = cStringUtil::Stringf("energy_sharing_log.dat");
     cDataFile& df = m_world->GetDataFile(tmpfilename);
-    
-    cString UpdateStr = cStringUtil::Stringf("%d,%d,%d,%f,%f,%d,%f,%f", 
+
+    cString UpdateStr = cStringUtil::Stringf("%d,%d,%d,%f,%f,%d,%f,%f",
                                              m_world->GetStats().GetUpdate(),
                                              m_world->GetConfig().ENERGY_SHARING_METHOD.Get(),
                                              m_organism->GetID(),
@@ -3812,9 +4043,9 @@
                                              energy_received,
                                              to_org->GetPhenotype().GetStoredEnergy());
     df.WriteRaw(UpdateStr);
-    
+
   }
-  
+
 } //End DoEnergyDonateAmount()
 
 
@@ -3827,11 +4058,11 @@
 
   // Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   // Donate only if we have found a neighbor.
   if (neighbor != NULL) {
     DoEnergyDonate(neighbor);
-    
+
     neighbor->GetPhenotype().SetIsReceiver();
   }
   return true;
@@ -3839,38 +4070,38 @@
 
 bool cHardwareCPU::Inst_DonateRandom(cAvidaContext& ctx)
 {
-  
+
   if (m_organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-	
+
   m_organism->GetPhenotype().IncDonates();
   m_organism->GetPhenotype().SetIsDonorRand();
-	
+
   // Turn to a random neighbor, get it, and turn back...
   int neighbor_id = ctx.GetRandom().GetInt(m_organism->GetNeighborhoodSize());
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(1);
   cOrganism * neighbor = m_organism->GetNeighbor();
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(-1);
-  
+
   // Donate only if we have found a neighbor.
   if (neighbor != NULL) {
     DoDonate(neighbor);
-    
+
 		// Code to track the edit distance between kin donors and recipients
 		const int edit_dist = cGenomeUtil::FindEditDistance(m_organism->GetGenome(),neighbor->GetGenome());
-		
+
 		/*static ofstream rand_file("rand_dists.dat");*/
 		static int num_rand_donates = 0;
 		static int num_rand_donates_15_dist = 0;
 		static int tot_dist_rand_donate = 0;
-		
+
 		num_rand_donates++;
 		if (edit_dist > 15) num_rand_donates_15_dist++;
 		tot_dist_rand_donate += edit_dist;
-		
+
 		if (num_rand_donates == 1000) {
-			
+
 			/*rand_file << num_rand_donates << " "
 			<< (double) num_rand_donates_15_dist / (double) num_rand_donates << " "
 			<< (double) tot_dist_rand_donate / (double) num_rand_donates << endl;
@@ -3879,9 +4110,9 @@
 			num_rand_donates_15_dist = 0;
 			tot_dist_rand_donate = 0;
 		}
-		
-		
-		
+
+
+
     //print out how often random donations go to kin
     /*
 		 static ofstream kinDistanceFile("kinDistance.dat");
@@ -3889,14 +4120,14 @@
 		 kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=2) << " ";
 		 kinDistanceFile << (genotype->GetPhyloDistance(neighbor->GetGenotype())<=3) << " ";
 		 kinDistanceFile << genotype->GetPhyloDistance(neighbor->GetGenotype());
-		 kinDistanceFile << endl; 
+		 kinDistanceFile << endl;
 		 */
-		
+
     neighbor->GetPhenotype().SetIsReceiverRand();
   }
-	
+
   return true;
-	
+
 }
 
 
@@ -3905,19 +4136,19 @@
   if (m_organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-  
+
   m_organism->GetPhenotype().IncDonates();
   m_organism->GetPhenotype().SetIsDonorKin();
-	
-	
+
+
   // Find the target as the first Kin found in the neighborhood.
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-  
+
   // Turn to face a random neighbor
   int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(1);
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   // If there is no max distance, just take the random neighbor we're facing.
   const int max_dist = m_world->GetConfig().MAX_DONATE_KIN_DIST.Get();
   if (max_dist != -1) {
@@ -3928,22 +4159,22 @@
       neighbor = m_organism->GetNeighbor();
       if (neighbor != NULL &&
           genotype->GetPhyloDistance(neighbor->GetGenotype()) <= max_dist) {
-				
+
 				// Code to track the edit distance between kin donors and recipients
 				const int edit_dist = cGenomeUtil::FindEditDistance(m_organism->GetGenome(),neighbor->GetGenome());
-				
+
 				/*static ofstream kin_file("kin_dists.dat");*/
 				static int num_kin_donates = 0;
 				static int num_kin_donates_15_dist = 0;
 				static int tot_dist_kin_donate = 0;
-				
+
 				num_kin_donates++;
 				if (edit_dist > 15) num_kin_donates_15_dist++;
 				tot_dist_kin_donate += edit_dist;
-				
-				
+
+
 				if (num_kin_donates == 1000) {
-					/* 
+					/*
 					 kin_file << num_kin_donates << " "
 					 << (double) num_kin_donates_15_dist / (double) num_kin_donates << " "
 					 << (double) tot_dist_kin_donate / (double) num_kin_donates << endl;
@@ -3952,7 +4183,7 @@
 					num_kin_donates_15_dist = 0;
 					tot_dist_kin_donate = 0;
 				}
-				
+
         found = true;
         break;
       }
@@ -3961,10 +4192,10 @@
     }
     if (found == false) neighbor = NULL;
   }
-  
+
   // Put the facing back where it was.
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(-1);
-  
+
   // Donate only if we have found a close enough relative...
   if (neighbor != NULL){
     DoDonate(neighbor);
@@ -3978,18 +4209,18 @@
   if (m_organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-	
+
   m_organism->GetPhenotype().IncDonates();
   m_organism->GetPhenotype().SetIsDonorEdit();
-  
+
   // Find the target as the first Kin found in the neighborhood.
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-  
+
   // Turn to face a random neighbor
   int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(1);
   cOrganism* neighbor = m_organism->GetNeighbor();
-  
+
   // If there is no max edit distance, take the random neighbor we're facing.
   const int max_dist = m_world->GetConfig().MAX_DONATE_EDIT_DIST.Get();
   if (max_dist != -1) {
@@ -4004,32 +4235,32 @@
       }
       if (edit_dist <= max_dist) {
         found = true;
-				
+
 				// Code to track the edit distance between edt donors and recipients
 				const int edit_dist = cGenomeUtil::FindEditDistance(m_organism->GetGenome(),neighbor->GetGenome());
-				
+
 				/*static ofstream edit_file("edit_dists.dat");*/
 				static int num_edit_donates = 0;
 				static int num_edit_donates_15_dist = 0;
 				static int tot_dist_edit_donate = 0;
-				
+
 				num_edit_donates++;
 				if (edit_dist > 15) num_edit_donates_15_dist++;
 				tot_dist_edit_donate += edit_dist;
-				
+
 				if (num_edit_donates == 1000) {
 					/*
 					 edit_file << num_edit_donates << " "
 					 << (double) num_edit_donates_15_dist / (double) num_edit_donates << " "
 					 << (double) tot_dist_edit_donate / (double) num_edit_donates << endl;
 					 */
-					
+
 					num_edit_donates = 0;
 					num_edit_donates_15_dist = 0;
 					tot_dist_edit_donate = 0;
 				}
-				
-				
+
+
         break;
       }
       m_organism->Rotate(1);
@@ -4037,107 +4268,107 @@
     }
     if (found == false) neighbor = NULL;
   }
-  
+
   // Put the facing back where it was.
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(-1);
-  
+
   // Donate only if we have found a close enough relative...
   if (neighbor != NULL){
     DoDonate(neighbor);
     neighbor->GetPhenotype().SetIsReceiverEdit();
   }
   return true;
-	
+
 }
 
 bool cHardwareCPU::Inst_DonateGreenBeardGene(cAvidaContext& ctx)
 {
   //this donates to organisms that have this instruction anywhere
-  //in their genome (see Dawkins 1976, The Selfish Gene, for 
+  //in their genome (see Dawkins 1976, The Selfish Gene, for
   //the history of the theory and the name 'green beard'
   cPhenotype & phenotype = m_organism->GetPhenotype();
-	
+
   if (m_organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-	
+
   phenotype.IncDonates();
   phenotype.SetIsDonorGbg();
-	
+
   // Find the target as the first match found in the neighborhood.
-	
+
   //get the neighborhood size
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-	
+
   // Turn to face a random neighbor
   int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(1);
   cOrganism * neighbor = m_organism->GetNeighbor();
-	
-	
+
+
   int max_id = neighbor_id + num_neighbors;
-	
+
   //we have not found a match yet
   bool found = false;
-	
-  // rotate through orgs in neighborhood  
+
+  // rotate through orgs in neighborhood
   while (neighbor_id < max_id) {
 		neighbor = m_organism->GetNeighbor();
-		
+
 		//if neighbor exists, do they have the green beard gene?
 		if (neighbor != NULL) {
 			const cGenome & neighbor_genome = neighbor->GetGenome();
-			
+
 			// for each instruction in the genome...
 			for(int i=0;i<neighbor_genome.GetSize();i++){
-				
+
 				// ...see if it is donate-gbg
 				if (neighbor_genome[i] == IP().GetInst()) {
 					found = true;
 					break;
 				}
-				
+
 			}
 		}
-		
+
 		// stop searching through the neighbors if we already found one
 		if (found == true){
     	break;
 		}
-		
+
 		m_organism->Rotate(1);
 		neighbor_id++;
   }
-	
+
 	if (found == false) neighbor = NULL;
-	
+
   // Put the facing back where it was.
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(-1);
-	
+
   // Donate only if we have found a close enough relative...
   if (neighbor != NULL) {
     DoDonate(neighbor);
     neighbor->GetPhenotype().SetIsReceiverGbg();
   }
-  
+
   return true;
-  
+
 }
 
 /* This instruction donates to other organisms that have at least
- as many donate-shaded-greenbeard instructions in their organism 
+ as many donate-shaded-greenbeard instructions in their organism
  as this organism does. */
 bool cHardwareCPU::Inst_DonateShadedGreenBeard(cAvidaContext& ctx)
 {
 	cPhenotype & phenotype = m_organism->GetPhenotype();
-	
+
 	// Determine if this m_organism is below the threshold and thus eligible to donate.
   if (m_organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-	
+
 	// Identify how many green beard donations the parent of this organism made
-	
+
 	// Identify how many shaded green beard donations this organisms made
 	// First figure out what number instruction donate-shadedgb is
 	cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
@@ -4145,105 +4376,105 @@
 	int shade_of_gb = 0;
 	int neighbor_shade_of_gb = 0;
 	int inst_number = 0;
-	for (int i = 0; i < num_inst; i++) { 
-		if ((inst_set.GetName(i) == "donate-shadedgb") && 
+	for (int i = 0; i < num_inst; i++) {
+		if ((inst_set.GetName(i) == "donate-shadedgb") &&
 				(phenotype.GetTestCPUInstCount().GetSize() > 0)) {
 			shade_of_gb = phenotype.GetTestCPUInstCount()[i];
 			inst_number = i;
 		}
 	}
-	
-	
+
+
 	// Update stats.
 	phenotype.IncDonates();
   phenotype.SetIsDonorShadedGb();
   phenotype.IncNumShadedGbDonations();
-	
+
   // Find the target as the first match found in the neighborhood.
   //get the neighborhood size
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-	
+
   // Turn to face a random neighbor
 	// Part of the reason the donates fail so frequently is that this code
 	// although it randomizes the neighbor, does not take into account whether
-	// a neigbhor is there or not. 
+	// a neigbhor is there or not.
   int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(1);
   cOrganism * neighbor = m_organism->GetNeighbor();
-	
+
   int max_id = neighbor_id + num_neighbors;
-	
+
   //we have not found a match yet
   bool found = false;
-	
-  // rotate through orgs in neighborhood  
+
+  // rotate through orgs in neighborhood
   while (neighbor_id < max_id) {
 		neighbor = m_organism->GetNeighbor();
 		//if neighbor exists, AND if their parent attempted to donate >= shaded of green beard,
 		if (neighbor != NULL) {
-			
+
 			// Get the neighbor's shade
-			neighbor_shade_of_gb = 0; 
-			if (neighbor->GetPhenotype().GetTestCPUInstCount().GetSize() > 0) { 
+			neighbor_shade_of_gb = 0;
+			if (neighbor->GetPhenotype().GetTestCPUInstCount().GetSize() > 0) {
 				neighbor_shade_of_gb = neighbor->GetPhenotype().GetTestCPUInstCount()[inst_number];
 			}
-			
-			// Changing this line makes shaded gb ONLY donate to organisms with the exact same 
+
+			// Changing this line makes shaded gb ONLY donate to organisms with the exact same
 			// shade (color/number of donations)
 			//			if (neighbor_shade_of_gb >=  shade_of_gb) {
 			if (neighbor_shade_of_gb ==  shade_of_gb) {
-				
+
 				// Code to track the edit distance between shaded donors and recipients
 				const int edit_dist = cGenomeUtil::FindEditDistance(m_organism->GetGenome(),neighbor->GetGenome());
-				
+
 				/*static ofstream gb_file("shaded_gb_dists.dat");*/
 				static int num_gb_donates = 0;
 				static int num_gb_donates_15_dist = 0;
 				static int tot_dist_gb_donate = 0;
-				
+
 				num_gb_donates++;
 				if (edit_dist > 15) num_gb_donates_15_dist++;
 				tot_dist_gb_donate += edit_dist;
-				
+
 				if (num_gb_donates == 1000) {
 					/*
 					 gb_file << num_gb_donates << " "
 					 << (double) num_gb_donates_15_dist / (double) num_gb_donates << " "
 					 << (double) tot_dist_gb_donate / (double) num_gb_donates << endl;
 					 */
-					
+
 					num_gb_donates = 0;
 					num_gb_donates_15_dist = 0;
 					tot_dist_gb_donate = 0;
 				}
-				
+
 				found = true;
 			}
 		}
-		
+
 		// stop searching through the neighbors if we already found one
 		if (found == true){
     	break;
 		}
-		
+
 		m_organism->Rotate(1);
 		neighbor_id++;
   }
-	
+
 	if (found == false) neighbor = NULL;
-	
+
   // Put the facing back where it was.
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(-1);
-	
+
   // Donate only if we have found a close enough relative...
   if (neighbor != NULL) {
     DoDonate(neighbor);
     neighbor->GetPhenotype().SetIsReceiverShadedGb();
-    
+
   }
-	
+
   return true;
-	
+
 }
 
 
@@ -4252,197 +4483,197 @@
 {
   //this donates to organisms that have this instruction anywhere
   //in their genome AND their parents excuted it
-  //(see Dawkins 1976, The Selfish Gene, for 
+  //(see Dawkins 1976, The Selfish Gene, for
   //the history of the theory and the name 'green beard'
   //  cout << "i am about to donate to a green beard" << endl;
   cPhenotype & phenotype = m_organism->GetPhenotype();
-	
+
   if (m_organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-	
+
   phenotype.IncDonates();
   phenotype.SetIsDonorTrueGb();
-	
+
   // Find the target as the first match found in the neighborhood.
-	
+
   //get the neighborhood size
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-	
+
 	// Get greenbeard instruction number
 	cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
 	const int num_inst = m_world->GetNumInstructions();
 	int inst_number = 0;
-	for (int i = 0; i < num_inst; i++) { 
+	for (int i = 0; i < num_inst; i++) {
 		if (inst_set.GetName(i) == "donate-tgb") {
 			inst_number = i;
 		}
 	}
-	
+
   // Turn to face a random neighbor
   int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(1);
   cOrganism * neighbor = m_organism->GetNeighbor();
-	
+
   int max_id = neighbor_id + num_neighbors;
-	
+
   //we have not found a match yet
   bool found = false;
-	
-  // rotate through orgs in neighborhood  
+
+  // rotate through orgs in neighborhood
   while (neighbor_id < max_id) {
 		neighbor = m_organism->GetNeighbor();
 		//if neighbor is a green beard
 		if (neighbor->GetPhenotype().GetTestCPUInstCount()[inst_number]) {
 			found = true;
 		}
-		
+
 		// stop searching through the neighbors if we already found one
 		if (found == true){
     	break;
 		}
-		
+
 		m_organism->Rotate(1);
 		neighbor_id++;
   }
-	
+
 	if (found == false) neighbor = NULL;
-	
+
   // Put the facing back where it was.
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(-1);
-	
+
   // Donate only if we have found a close enough relative...
   if (neighbor != NULL) {
     DoDonate(neighbor);
     neighbor->GetPhenotype().SetIsReceiverTrueGb();
   }
-	
-  
-  return true;	
-  
+
+
+  return true;
+
 }
 
 bool cHardwareCPU::Inst_DonateThreshGreenBeard(cAvidaContext& ctx)
 {
   //this donates to organisms that have this instruction anywhere
   //in their genome AND their parents excuted it >=THRESHOLD number of times
-  //(see Dawkins 1976, The Selfish Gene, for 
+  //(see Dawkins 1976, The Selfish Gene, for
   //the history of the theory and the name 'green beard'
   //  cout << "i am about to donate to a green beard" << endl;
   cPhenotype & phenotype = m_organism->GetPhenotype();
-	
+
   if (m_organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-	
-	
+
+
   phenotype.IncDonates();
   phenotype.SetIsDonorThreshGb();
   phenotype.IncNumThreshGbDonations();
-	
-	
+
+
 	// Identify how many thresh green beard donations this organisms made
-	// First figure out what number instruction donate-threshgb is	
+	// First figure out what number instruction donate-threshgb is
 	cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
 	const int num_inst = m_world->GetNumInstructions();
 	int neighbor_thresh_of_gb = 0;
 	int inst_number = 0;
-	for (int i = 0; i < num_inst; i++) { 
-		if ((inst_set.GetName(i) == "donate-threshgb") && 
+	for (int i = 0; i < num_inst; i++) {
+		if ((inst_set.GetName(i) == "donate-threshgb") &&
 				(phenotype.GetTestCPUInstCount().GetSize() > 0)) {
 			inst_number = i;
 		}
 	}
-	
+
   // Find the target as the first match found in the neighborhood.
-	
+
   //get the neighborhood size
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-	
+
   // Turn to face a random neighbor
   int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(1);
   cOrganism * neighbor = m_organism->GetNeighbor();
-	
+
   int max_id = neighbor_id + num_neighbors;
-	
+
   //we have not found a match yet
   bool found = false;
-	
-  // rotate through orgs in neighborhood  
+
+  // rotate through orgs in neighborhood
   while (neighbor_id < max_id) {
 		neighbor = m_organism->GetNeighbor();
 		//if neighbor exists, AND if their parent attempted to donate >= threshhold,
 		if (neighbor != NULL) {
-			
+
 			// Get neighbor threshold
-			neighbor_thresh_of_gb = 0; 
-			if (neighbor->GetPhenotype().GetTestCPUInstCount().GetSize() > 0) { 
+			neighbor_thresh_of_gb = 0;
+			if (neighbor->GetPhenotype().GetTestCPUInstCount().GetSize() > 0) {
 				neighbor_thresh_of_gb = neighbor->GetPhenotype().GetTestCPUInstCount()[inst_number];
 			}
-			
+
 			if (neighbor_thresh_of_gb >= m_world->GetConfig().MIN_GB_DONATE_THRESHOLD.Get() ) {
 				const cGenome & neighbor_genome = neighbor->GetGenome();
-				
+
 				// Code to track the edit distance between tgb donors and recipients
 				const int edit_dist = cGenomeUtil::FindEditDistance(m_organism->GetGenome(),neighbor->GetGenome());
-				
+
 				/*static ofstream tgb_file("thresh_gb_dists.dat");*/
 				static int num_tgb_donates = 0;
 				static int num_tgb_donates_15_dist = 0;
 				static int tot_dist_tgb_donate = 0;
-				
+
 				num_tgb_donates++;
 				if (edit_dist > 15) num_tgb_donates_15_dist++;
 				tot_dist_tgb_donate += edit_dist;
-				
+
 				if (num_tgb_donates == 1000) {
 					/*
 					 tgb_file << num_tgb_donates << " "
 					 << (double) num_tgb_donates_15_dist / (double) num_tgb_donates << " "
 					 << (double) tot_dist_tgb_donate / (double) num_tgb_donates << endl;
 					 */
-					
+
 					num_tgb_donates = 0;
 					num_tgb_donates_15_dist = 0;
 					tot_dist_tgb_donate = 0;
 				}
-				
+
 				// for each instruction in the genome...
 				for(int i=0;i<neighbor_genome.GetSize();i++){
-					
+
 					// ...see if it is donate-threshgb, if so, we found a target
 					if (neighbor_genome[i] == IP().GetInst()) {
 						found = true;
 						break;
 					}
-					
+
 				}
 			}
 		}
-		
+
 		// stop searching through the neighbors if we already found one
 		if (found == true){
     	break;
 		}
-		
+
 		m_organism->Rotate(1);
 		neighbor_id++;
   }
-	
+
 	if (found == false) neighbor = NULL;
-	
+
   // Put the facing back where it was.
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(-1);
-	
+
   // Donate only if we have found a close enough relative...
   if (neighbor != NULL) {
     DoDonate(neighbor);
     neighbor->GetPhenotype().SetIsReceiverThreshGb();
     // cout << "************ neighbor->GetPhenotype().GetNumThreshGbDonationsLast() is " << neighbor->GetPhenotype().GetNumThreshGbDonationsLast() << endl;
-    
+
   }
-	
+
   return true;
 }
 
@@ -4456,91 +4687,91 @@
   // using this instruction.  The threshold levels are multiples of
   // the quanta value set in genesis, and the highest level that
   // the donor qualifies for is the one used.
-	
-  // (see Dawkins 1976, The Selfish Gene, for 
+
+  // (see Dawkins 1976, The Selfish Gene, for
   // the history of the theory and the name 'green beard'
   //  cout << "i am about to donate to a green beard" << endl;
   cPhenotype & phenotype = m_organism->GetPhenotype();
-	
+
   if (phenotype.GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
     return false;
   }
-	
+
   phenotype.IncDonates();
   phenotype.SetIsDonorQuantaThreshGb();
   phenotype.IncNumQuantaThreshGbDonations();
   //cout << endl << "quanta_threshgb attempt.. " ;
-	
-	
+
+
   // Find the target as the first match found in the neighborhood.
-	
+
   //get the neighborhood size
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-	
+
   // Turn to face a random neighbor
   int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(1);
   cOrganism * neighbor = m_organism->GetNeighbor();
-	
+
   int max_id = neighbor_id + num_neighbors;
-	
+
   //we have not found a match yet
   bool found = false;
-	
+
   // Get the quanta (step size) between threshold levels.
   const int donate_quanta = m_world->GetConfig().DONATE_THRESH_QUANTA.Get();
-  
+
   // Calculate what quanta level we should be at for this individual.  We do a
   // math trick to make sure its the next lowest event multiple of donate_quanta.
   const int quanta_donate_thresh =
 	(phenotype.GetNumQuantaThreshGbDonationsLast() / donate_quanta) * donate_quanta;
   //cout << " phenotype.GetNumQuantaThreshGbDonationsLast() is " << phenotype.GetNumQuantaThreshGbDonationsLast();
   //cout << " quanta thresh=  " << quanta_donate_thresh;
-  // rotate through orgs in neighborhood  
+  // rotate through orgs in neighborhood
   while (neighbor_id < max_id) {
 		neighbor = m_organism->GetNeighbor();
 		//if neighbor exists, AND if their parent attempted to donate >= threshhold,
 		if (neighbor != NULL &&
 				neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast() >= quanta_donate_thresh) {
-			
+
 			const cGenome & neighbor_genome = neighbor->GetGenome();
-			
+
 			// for each instruction in the genome...
 			for(int i=0;i<neighbor_genome.GetSize();i++){
-				
+
 				// ...see if it is donate-quantagb, if so, we found a target
 				if (neighbor_genome[i] == IP().GetInst()) {
 					found = true;
 					break;
 				}
-				
+
 			}
 		}
-		
+
 		// stop searching through the neighbors if we already found one
 		if (found == true);{
     	break;
 		}
-		
+
 		m_organism->Rotate(1);
 		neighbor_id++;
   }
-	
+
 	if (found == false) neighbor = NULL;
-	
+
   // Put the facing back where it was.
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(-1);
-	
+
   // Donate only if we have found a close enough relative...
   if (neighbor != NULL) {
     DoDonate(neighbor);
     neighbor->GetPhenotype().SetIsReceiverQuantaThreshGb();
     //cout << " ************ neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast() is " << neighbor->GetPhenotype().GetNumQuantaThreshGbDonationsLast();
-    
+
   }
-	
+
   return true;
-  
+
 }
 
 
@@ -4552,17 +4783,17 @@
 
   m_organism->GetPhenotype().IncDonates();
   m_organism->GetPhenotype().SetIsDonorNull();
-  
+
   // This is a fake donate command that causes the organism to lose merit,
   // but no one else to gain any.
-  
+
   const double merit_given = m_world->GetConfig().MERIT_GIVEN.Get();
   double cur_merit = m_organism->GetPhenotype().GetMerit().GetDouble();
   cur_merit -= merit_given;
-  
+
   // Plug the current merit back into this organism and notify the scheduler.
   m_organism->UpdateMerit(cur_merit);
-  
+
   return true;
 }
 
@@ -4573,19 +4804,19 @@
   if (m_organism->GetCellID() < 0) {
     return false;
   }
-  
+
   cPhenotype& phenotype = m_organism->GetPhenotype();
   if (phenotype.GetEnergyInBufferAmount() > 0) {
     phenotype.ApplyDonatedEnergy();
-	 
+
 	  if (m_world->GetConfig().ENERGY_SHARING_UPDATE_METABOLIC.Get() == 1) {
       double receiverMerit = phenotype.ConvertEnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio());
       m_organism->UpdateMerit(receiverMerit);
   	}
   }
-  
+
   return true;
-  
+
 } //End Inst_ReceiveDonatedEnergy()
 
 
@@ -4600,7 +4831,7 @@
   if(msg == 0) {
     return false;
   }
-  
+
   /* MJM - by this point, the pointer returned by GetSender() may no longer
    * be any good. Instead, we should use the cell and organism ID of the
    * message sender to get hold of the sender (if it still exists and hasn't moved)
@@ -4617,11 +4848,11 @@
 	  // we can't donate...
 	  return false;
   }
-  
+
   DoEnergyDonatePercent(energyReceiver, m_organism->GetFracEnergyDonating());
-  
+
   return true;
-  
+
 } //End Inst_DonateEnergy()
 
 
@@ -4631,7 +4862,7 @@
   cPhenotype& phenotype = m_organism->GetPhenotype();
   double newmerit = phenotype.ConvertEnergyToMerit(phenotype.GetStoredEnergy()  * phenotype.GetEnergyUsageRatio());
   m_organism->UpdateMerit(newmerit);
-  
+
   return true;
 } //End Inst_UpdateMetabolocRate()
 
@@ -4641,21 +4872,21 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
+  }
 
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
-    
+
     // If the neighbor has requested energy or if we're allowing push sharing, share energy
     if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) )
     {
       DoEnergyDonatePercent(neighbor, m_organism->GetFracEnergyDonating());
     }
-  }  
-  
+  }
+
   return true;
-  
+
 } //End Inst_DonateEnergyFaced()
 
 
@@ -4663,21 +4894,21 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
-    
+
     // If the neighbor has requested energy or if we're allowing push sharing, share energy
     if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) )
     {
       DoEnergyDonateAmount(neighbor, 1);
     }
-  }  
-  
+  }
+
   return true;
-  
+
 } //End Inst_DonateEnergyFaced1()
 
 
@@ -4685,21 +4916,21 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
-    
+
     // If the neighbor has requested energy or if we're allowing push sharing, share energy
     if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) )
     {
       DoEnergyDonateAmount(neighbor, 2);
     }
-  }  
-  
+  }
+
   return true;
-  
+
 } //End Inst_DonateEnergyFaced2()
 
 
@@ -4707,21 +4938,21 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
-    
+
     // If the neighbor has requested energy or if we're allowing push sharing, share energy
     if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) )
     {
       DoEnergyDonateAmount(neighbor, 5);
     }
-  }  
-  
+  }
+
   return true;
-  
+
 } //End Inst_DonateEnergyFaced5()
 
 
@@ -4729,21 +4960,21 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
-    
+
     // If the neighbor has requested energy or if we're allowing push sharing, share energy
     if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) )
     {
       DoEnergyDonateAmount(neighbor, 10);
     }
-  }  
-  
+  }
+
   return true;
-  
+
 } //End Inst_DonateEnergyFaced10()
 
 
@@ -4751,21 +4982,21 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
-    
+
     // If the neighbor has requested energy or if we're allowing push sharing, share energy
     if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) )
     {
       DoEnergyDonateAmount(neighbor, 20);
     }
-  }  
-  
+  }
+
   return true;
-  
+
 } //End Inst_DonateEnergyFaced20()
 
 
@@ -4773,21 +5004,21 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
-    
+
     // If the neighbor has requested energy or if we're allowing push sharing, share energy
     if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) )
     {
       DoEnergyDonateAmount(neighbor, 50);
     }
-  }  
-  
+  }
+
   return true;
-  
+
 } //End Inst_DonateEnergyFaced50()
 
 
@@ -4795,21 +5026,21 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
-    
+
     // If the neighbor has requested energy or if we're allowing push sharing, share energy
     if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) )
     {
       DoEnergyDonateAmount(neighbor, 100);
     }
-  }  
-  
+  }
+
   return true;
-  
+
 } //End Inst_DonateEnergyFaced100()
 
 
@@ -4818,11 +5049,11 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cPopulation& pop = m_world->GetPopulation();
   cPopulationCell& mycell = pop.GetCell(m_organism->GetCellID());
-  
+
   double min_energy = m_world->GetConfig().ENERGY_CAP.Get();
   int num_rotations = 0;
   cOrganism *neighbor;
@@ -4832,26 +5063,26 @@
   for(int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
     mycell.ConnectionList().CircNext();
     neighbor = m_organism->GetNeighbor();
-        
+
     // If this neighbor is alive and has a request for energy or we're allowing pushing of energy, look at it
     if ( (neighbor != NULL) && (!neighbor->IsDead()) &&
          ((neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1)) ) {
       neighbor_energy = neighbor->GetPhenotype().GetStoredEnergy();
-      
+
       if( (neighbor_energy > 0) && (neighbor_energy < min_energy) ) {
         num_rotations = i;
       }
     }
-    
+
   }
-    
+
   //Rotate to face the most needy neighbor
   for(int i = 0; i < num_rotations; i++) {
     mycell.ConnectionList().CircNext();
   }
-  
+
   return true;
-  
+
 } //End Inst_RotateToMostNeedy()
 
 
@@ -4861,16 +5092,16 @@
   if(m_organism->GetCellID() < 0) {
     return false;
   }
-      
+
   cOrgMessage msg(m_organism);
   // Could set the data field of the message to be the multiplier
-  
+
   m_organism->BroadcastMessage(ctx, msg, m_world->GetConfig().MESSAGE_BCAST_RADIUS.Get());
   m_organism->GetPhenotype().SetIsEnergyRequestor();
   m_organism->GetPhenotype().IncreaseNumEnergyRequests();
-  
+
   return true;
-  
+
 } //End Inst_RequestEnergy()
 
 
@@ -4879,12 +5110,12 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   m_organism->GetPhenotype().SetIsEnergyRequestor();
   m_organism->GetPhenotype().IncreaseNumEnergyRequests();
   m_organism->GetPhenotype().SetHasOpenEnergyRequest();
-  
+
   return true;
 } //End Inst_RequestEnergyFlagOn()
 
@@ -4894,8 +5125,8 @@
 {
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   m_organism->GetPhenotype().ClearHasOpenEnergyRequest();
   return true;
 } //End Inst_RequestEnergyFlagOff()
@@ -4907,10 +5138,10 @@
   double curr_amount = m_organism->GetFracEnergyDonating();
   double increment = m_world->GetConfig().ENERGY_SHARING_INCREMENT.Get();
 
-  m_organism->SetFracEnergyDonating(min(1.0, curr_amount + increment));  
-  
+  m_organism->SetFracEnergyDonating(min(1.0, curr_amount + increment));
+
   return true;
-  
+
 } //End Inst_IncreaseEnergyDonation()
 
 
@@ -4919,11 +5150,11 @@
 {
   double curr_amount = m_organism->GetFracEnergyDonating();
   double increment = m_world->GetConfig().ENERGY_SHARING_INCREMENT.Get();
-  
-  m_organism->SetFracEnergyDonating(max(0.0, curr_amount - increment));  
-  
+
+  m_organism->SetFracEnergyDonating(max(0.0, curr_amount - increment));
+
   return true;
-  
+
 } //End Inst_DecreaseEnergyDonation()
 
 
@@ -4954,38 +5185,38 @@
 }
 
 bool cHardwareCPU::Inst_IOBufAdd1(cAvidaContext& ctx)
-{ 
+{
 	m_organism->AddOutput(1);
 	return true;
 }
 bool cHardwareCPU::Inst_IOBufAdd0(cAvidaContext& ctx)
-{ 
+{
 	m_organism->AddOutput(0);
-	return true; 
+	return true;
 }
 
 bool cHardwareCPU::Inst_RotateL(cAvidaContext& ctx)
 {
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-  
+
   // If this organism has no neighbors, ignore rotate.
   if (num_neighbors == 0) return false;
-  
+
   ReadLabel();
-  
+
   // Always rotate at least once.
   m_organism->Rotate(-1);
-  
+
   // If there is no label, then the one rotation was all we want.
   if (!GetLabel().GetSize()) return true;
-  
+
   // Rotate until a complement label is found (or all have been checked).
   GetLabel().Rotate(1, NUM_NOPS);
   for (int i = 1; i < num_neighbors; i++) {
     cOrganism* neighbor = m_organism->GetNeighbor();
-    
+
     if (neighbor != NULL && neighbor->GetHardware().FindLabelFull(GetLabel()).InMemory()) return true;
-    
+
     // Otherwise keep rotating...
     m_organism->Rotate(-1);
   }
@@ -4995,25 +5226,25 @@
 bool cHardwareCPU::Inst_RotateR(cAvidaContext& ctx)
 {
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-  
+
   // If this organism has no neighbors, ignore rotate.
   if (num_neighbors == 0) return false;
-  
+
   ReadLabel();
-  
+
   // Always rotate at least once.
   m_organism->Rotate(1);
-  
+
   // If there is no label, then the one rotation was all we want.
   if (!GetLabel().GetSize()) return true;
-  
+
   // Rotate until a complement label is found (or all have been checked).
   GetLabel().Rotate(1, NUM_NOPS);
   for (int i = 1; i < num_neighbors; i++) {
     cOrganism* neighbor = m_organism->GetNeighbor();
-    
+
     if (neighbor != NULL && neighbor->GetHardware().FindLabelFull(GetLabel()).InMemory()) return true;
-    
+
     // Otherwise keep rotating...
     m_organism->Rotate(1);
   }
@@ -5039,7 +5270,7 @@
 {
   int standardNeighborhoodSize, actualNeighborhoodSize, newFacing, currentFacing;
   actualNeighborhoodSize = m_organism->GetNeighborhoodSize();
-  
+
   ReadLabel();
   if(m_world->GetConfig().WORLD_GEOMETRY.Get() == nGeometry::TORUS || m_world->GetConfig().WORLD_GEOMETRY.Get() == nGeometry::GRID)
     standardNeighborhoodSize = 8;
@@ -5047,7 +5278,7 @@
     exit(-1);
   }
   newFacing = GetLabel().AsIntGreyCode(NUM_NOPS) % standardNeighborhoodSize;
-  
+
   for(int i = 0; i < actualNeighborhoodSize; i++) {
     currentFacing = m_organism->GetFacing();
     if(newFacing == currentFacing)
@@ -5059,29 +5290,29 @@
 
 bool cHardwareCPU::Inst_RotateUnoccupiedCell(cAvidaContext& ctx) {
   const int reg_used = FindModifiedRegister(REG_BX);
-  
+
   for(int i = 0; i < m_organism->GetNeighborhoodSize(); i++) {
     if(!m_organism->IsNeighborCellOccupied()) // faced cell is unoccupied
     {
-      GetRegister(reg_used) = 1;      
+      GetRegister(reg_used) = 1;
       return true;
     }
     m_organism->Rotate(1); // continue to rotate
-  }  
+  }
   GetRegister(reg_used) = 0;
   return true;
 }
 
 bool cHardwareCPU::Inst_RotateOccupiedCell(cAvidaContext& ctx) {
   const int reg_used = FindModifiedRegister(REG_BX);
-  
+
   for(int i = 0; i < m_organism->GetNeighborhoodSize(); i++) {
     if(m_organism->IsNeighborCellOccupied()) { // faced cell is occupied
-      GetRegister(reg_used) = 1;      
+      GetRegister(reg_used) = 1;
       return true;
     }
     m_organism->Rotate(1); // continue to rotate
-  }  
+  }
   GetRegister(reg_used) = 0;
   return true;
 }
@@ -5098,14 +5329,14 @@
 
 bool cHardwareCPU::Inst_RotateEventCell(cAvidaContext& ctx) {
   const int reg_used = FindModifiedRegister(REG_BX);
-  
+
   for(int i = 0; i < m_organism->GetNeighborhoodSize(); i++) {
     if(m_organism->GetCellData() > 0) { // event in faced cell
-      GetRegister(reg_used) = 1;      
+      GetRegister(reg_used) = 1;
       return true;
     }
     m_organism->Rotate(1); // continue to rotate
-  }  
+  }
   GetRegister(reg_used) = 0;
   return true;
 }
@@ -5128,7 +5359,7 @@
 
 // @WRE addition for movement
 // Tumble sets the organism and cell to a new random facing
-// 
+//
 bool cHardwareCPU::Inst_Tumble(cAvidaContext& ctx)
 {
   // Get number of neighbor cells that the organism can move to.
@@ -5156,25 +5387,25 @@
 bool cHardwareCPU::Inst_SGMove(cAvidaContext& ctx)
 {
   assert(m_ext_mem.GetSize() > 3);
-  
+
   const cStateGrid& sg = m_organism->GetStateGrid();
-  
+
   int& x = m_ext_mem[0];
   int& y = m_ext_mem[1];
-  
+
   const int facing = m_ext_mem[2];
-  
+
   // State grid is treated as a 2-dimensional toroidal grid with size [0, width) and [0, height)
   switch (facing) {
     case 0: // N
       if (++y == sg.GetHeight()) y = 0;
       break;
-      
+
     case 1: // NE
       if (++x == sg.GetWidth()) x = 0;
       if (++y == sg.GetHeight()) y = 0;
       break;
-      
+
     case 2: // E
       if (++x == sg.GetWidth()) x = 0;
       break;
@@ -5183,7 +5414,7 @@
       if (++x == sg.GetWidth()) x = 0;
       if (--y == -1) y = sg.GetHeight() - 1;
       break;
-      
+
     case 4: // S
       if (--y == -1) y = sg.GetHeight() - 1;
       break;
@@ -5192,7 +5423,7 @@
       if (--x == -1) x = sg.GetWidth() - 1;
       if (--y == -1) y = sg.GetHeight() - 1;
       break;
-      
+
     case 6: // W
       if (--x == -1) x = sg.GetWidth() - 1;
       break;
@@ -5201,14 +5432,14 @@
       if (--x == -1) x = sg.GetWidth() - 1;
       if (++y == sg.GetHeight()) y = 0;
       break;
-            
+
     default:
       assert(facing >= 0 && facing <= 7);
   }
-  
+
   // Increment state observed count
   m_ext_mem[3 + sg.GetStateAt(x, y)]++;
-  
+
   // Save this location in the movement history
   m_ext_mem.Push(sg.GetIDFor(x, y));
   return true;
@@ -5233,7 +5464,7 @@
   const cStateGrid& sg = m_organism->GetStateGrid();
   const int reg_used = FindModifiedRegister(REG_BX);
   GetRegister(reg_used) = sg.SenseStateAt(m_ext_mem[0], m_ext_mem[1]);
-  return true; 
+  return true;
 }
 
 // @WRE addition for movement
@@ -5246,15 +5477,15 @@
   int fromcellID, destcellID; //, actualNeighborhoodSize, fromFacing, destFacing, currentFacing;
 
   fromcellID = m_organism->GetCellID(); //absolute id of current cell
-	
+
   if(fromcellID == -1) {
     return false;
   }
-	
+
   // Get population
   cPopulation& pop = m_world->GetPopulation();
   cDeme &deme = pop.GetDeme(pop.GetCell(m_organism->GetCellID()).GetDemeID());
-  
+
   // Get stepsize. Currently, all moves are one cell regardless of stepsize.
   // This could be changed in the future.
   const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
@@ -5271,7 +5502,7 @@
     if (-1  == fromcellID) return false;
     // Destination cell
     destcellID = pop.GetCell(fromcellID).GetCellFaced().GetID();
-    
+
     /*********************/
     // TEMP.  Remove once movement tasks are implemented.
     if(pop.GetCell(fromcellID).GetCellData() < pop.GetCell(destcellID).GetCellData()) { // move up gradient
@@ -5279,15 +5510,15 @@
     } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
       m_organism->SetGradientMovement(0.0);
     } else { // move down gradient
-      m_organism->SetGradientMovement(-1.0);    
+      m_organism->SetGradientMovement(-1.0);
     }
-    /*********************/    
-    
+    /*********************/
+
     // Actually perform the move using SwapCells
     pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
     // Swap inputs and facings between cells using helper function
     pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-    
+
     // updates movement predicates
     m_world->GetStats().Move(*m_organism);
 
@@ -5297,7 +5528,7 @@
 
         pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
 	drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
-	
+
 	if(drop_mode == 0) {
           deme.AddPheromone(fromcellID, pher_amount/2);
           deme.AddPheromone(destcellID, pher_amount/2);
@@ -5344,9 +5575,9 @@
 bool cHardwareCPU::Inst_MoveToEvent(cAvidaContext& ctx) {
   const int reg_used = FindModifiedRegister(REG_BX);
   int orginalFacing = m_organism->GetFacing();
-  
+
   for(int i = 0; i < m_organism->GetNeighborhoodSize(); i++) {
-    if(m_organism->GetNeighborCellContents() > 0) { 
+    if(m_organism->GetNeighborCellContents() > 0) {
       Inst_Move(ctx);
       GetRegister(reg_used) = 1;
       return true;
@@ -5361,9 +5592,9 @@
 
 bool cHardwareCPU::Inst_IfNeighborEventInUnoccupiedCell(cAvidaContext& ctx) {
   int orginalFacing = m_organism->GetFacing();
-  
+
   for(int i = 0; i < m_organism->GetNeighborhoodSize(); i++) {
-    if(m_organism->GetNeighborCellContents() > 0 && !m_organism->IsNeighborCellOccupied()) { 
+    if(m_organism->GetNeighborCellContents() > 0 && !m_organism->IsNeighborCellOccupied()) {
       return true;
     }
     m_organism->Rotate(1);
@@ -5374,7 +5605,7 @@
 }
 
 bool cHardwareCPU::Inst_IfFacingEventCell(cAvidaContext& ctx) {
-  if(m_organism->GetNeighborCellContents() > 0) { 
+  if(m_organism->GetNeighborCellContents() > 0) {
       return true;
   }
   IP().Advance();
@@ -5382,7 +5613,7 @@
 }
 
 bool cHardwareCPU::Inst_IfEventInCell(cAvidaContext& ctx) {
-  if(m_organism->GetCellData() > 0) { 
+  if(m_organism->GetCellData() > 0) {
       return true;
   }
   IP().Advance();
@@ -5401,13 +5632,13 @@
 {
   ReadLabel();
   GetLabel().Rotate(1, NUM_NOPS);
-  
+
   // If there is no label, then do normal fork behavior
   if (GetLabel().GetSize() == 0)
   {
     return Inst_ForkThread(ctx);
   }
-  
+
   cHeadCPU searchHead = FindLabel(+1);
   if ( searchHead.GetPosition() != IP().GetPosition() )
   {
@@ -5416,13 +5647,13 @@
     if (!ForkThread()) m_organism->Fault(FAULT_LOC_THREAD_FORK, FAULT_TYPE_FORK_TH);
     IP().Set( save_pos );
   }
-  
+
   return true;
 }
 
 bool cHardwareCPU::Inst_ForkThreadLabelIfNot0(cAvidaContext& ctx)
 {
-  if (GetRegister(REG_BX) == 0) 
+  if (GetRegister(REG_BX) == 0)
   {
     ReadLabel();
     return false;
@@ -5535,13 +5766,13 @@
   bool ret_val = Divide_Main(ctx, divide_pos, extra_lines, mut_multiplier);
   // Re-adjust heads.
   AdjustHeads();
-  return ret_val; 
+  return ret_val;
 }
 
 bool cHardwareCPU::Inst_HeadDivide(cAvidaContext& ctx)
 {
   return Inst_HeadDivideMut(ctx, 1);
-  
+
 }
 
 /*
@@ -5558,7 +5789,7 @@
   bool ret_val = Divide_MainRS(ctx, divide_pos, extra_lines, 1);
   // Re-adjust heads.
   AdjustHeads();
-  return ret_val; 
+  return ret_val;
 }
 
 /*
@@ -5575,7 +5806,7 @@
   bool ret_val = Divide_Main1RS(ctx, divide_pos, extra_lines, 1);
   // Re-adjust heads.
   AdjustHeads();
-  return ret_val; 
+  return ret_val;
 }
 
 /*
@@ -5592,42 +5823,42 @@
   bool ret_val = Divide_Main2RS(ctx, divide_pos, extra_lines, 1);
   // Re-adjust heads.
   AdjustHeads();
-  return ret_val; 
+  return ret_val;
 }
 
 
-bool cHardwareCPU::Inst_HeadDivideSex(cAvidaContext& ctx)  
-{ 
+bool cHardwareCPU::Inst_HeadDivideSex(cAvidaContext& ctx)
+{
   m_organism->GetPhenotype().SetDivideSex(true);
   m_organism->GetPhenotype().SetCrossNum(1);
-  return Inst_HeadDivide(ctx); 
+  return Inst_HeadDivide(ctx);
 }
 
-bool cHardwareCPU::Inst_HeadDivideAsex(cAvidaContext& ctx)  
-{ 
+bool cHardwareCPU::Inst_HeadDivideAsex(cAvidaContext& ctx)
+{
   m_organism->GetPhenotype().SetDivideSex(false);
   m_organism->GetPhenotype().SetCrossNum(0);
-  return Inst_HeadDivide(ctx); 
+  return Inst_HeadDivide(ctx);
 }
 
-bool cHardwareCPU::Inst_HeadDivideAsexWait(cAvidaContext& ctx)  
-{ 
+bool cHardwareCPU::Inst_HeadDivideAsexWait(cAvidaContext& ctx)
+{
   m_organism->GetPhenotype().SetDivideSex(true);
   m_organism->GetPhenotype().SetCrossNum(0);
-  return Inst_HeadDivide(ctx); 
+  return Inst_HeadDivide(ctx);
 }
 
-bool cHardwareCPU::Inst_HeadDivideMateSelect(cAvidaContext& ctx)  
-{ 
+bool cHardwareCPU::Inst_HeadDivideMateSelect(cAvidaContext& ctx)
+{
   // Take the label that follows this divide and use it as the ID for which
   // other organisms this one is willing to mate with.
   ReadLabel();
   m_organism->GetPhenotype().SetMateSelectID( GetLabel().AsInt(NUM_NOPS) );
-  
+
   // Proceed as normal with the rest of mate selection.
   m_organism->GetPhenotype().SetDivideSex(true);
   m_organism->GetPhenotype().SetCrossNum(1);
-  return Inst_HeadDivide(ctx); 
+  return Inst_HeadDivide(ctx);
 }
 
 bool cHardwareCPU::Inst_HeadDivide1(cAvidaContext& ctx)  { return Inst_HeadDivideMut(ctx, 1); }
@@ -5658,10 +5889,10 @@
 bool cHardwareCPU::Inst_HeadRead(cAvidaContext& ctx)
 {
   const int dst = REG_BX;
-  
+
   const int head_id = FindModifiedHead(nHardware::HEAD_READ);
   GetHead(head_id).Adjust();
-  
+
   // Mutations only occur on the read, for the moment.
   int read_inst = 0;
   if (m_organism->TestCopyMut(ctx)) {
@@ -5671,7 +5902,7 @@
   }
   GetRegister(dst) = read_inst;
   ReadInst(read_inst);
-  
+
   if (m_slip_read_head && m_organism->TestCopySlip(ctx))
     GetHead(head_id).Set(ctx.GetRandom().GetInt(GetHead(head_id).GetMemory().GetSize()));
 
@@ -5684,24 +5915,24 @@
   const int src = REG_BX;
   const int head_id = FindModifiedHead(nHardware::HEAD_WRITE);
   cHeadCPU& active_head = GetHead(head_id);
-  
+
   active_head.Adjust();
-  
+
   int value = GetRegister(src);
   if (value < 0 || value >= m_inst_set->GetSize()) value = 0;
-  
+
   active_head.SetInst(cInstruction(value));
   active_head.SetFlagCopied();
-  
+
   if (m_organism->TestCopyIns(ctx)) active_head.InsertInst(m_inst_set->GetRandomInst(ctx));
   if (m_organism->TestCopyDel(ctx)) active_head.RemoveInst();
   if (m_organism->TestCopyUniform(ctx)) doUniformCopyMutation(ctx, active_head);
-  if (!m_slip_read_head && m_organism->TestCopySlip(ctx)) 
+  if (!m_slip_read_head && m_organism->TestCopySlip(ctx))
     doSlipMutation(ctx, active_head.GetMemory(), active_head.GetPosition());
 
   // Advance the head after write...
   active_head.Advance();
-  
+
   return true;
 }
 
@@ -5710,14 +5941,14 @@
   // For the moment, this cannot be nop-modified.
   cHeadCPU& read_head = GetHead(nHardware::HEAD_READ);
   cHeadCPU& write_head = GetHead(nHardware::HEAD_WRITE);
-  
+
   read_head.Adjust();
   write_head.Adjust();
-  
+
   // Do mutations.
   cInstruction read_inst = read_head.GetInst();
   ReadInst(read_inst.GetOp());
-  
+
   if (m_organism->TestCopyMut(ctx)) {
     read_inst = m_inst_set->GetRandomInst(ctx);
     write_head.SetFlagMutated();
@@ -5726,17 +5957,17 @@
 
   write_head.SetInst(read_inst);
   write_head.SetFlagCopied();  // Set the copied flag...
-  
+
   if (m_organism->TestCopyIns(ctx)) write_head.InsertInst(m_inst_set->GetRandomInst(ctx));
   if (m_organism->TestCopyDel(ctx)) write_head.RemoveInst();
   if (m_organism->TestCopyUniform(ctx)) doUniformCopyMutation(ctx, write_head);
   if (m_organism->TestCopySlip(ctx)) {
     if (m_slip_read_head) {
       read_head.Set(ctx.GetRandom().GetInt(read_head.GetMemory().GetSize()));
-    } else 
+    } else
       doSlipMutation(ctx, write_head.GetMemory(), write_head.GetPosition());
   }
-  
+
   read_head.Advance();
   write_head.Advance();
   return true;
@@ -5747,10 +5978,10 @@
   // For the moment, this cannot be nop-modified.
   cHeadCPU & read_head = GetHead(nHardware::HEAD_READ);
   cHeadCPU & write_head = GetHead(nHardware::HEAD_WRITE);
-  
+
   read_head.Adjust();
   write_head.Adjust();
-  
+
   // Do mutations.
   cInstruction read_inst = read_head.GetInst();
   ReadInst(read_inst.GetOp());
@@ -5759,20 +5990,20 @@
     write_head.SetFlagMutated();
     write_head.SetFlagCopyMut();
   }
-  
+
   write_head.SetInst(read_inst);
   write_head.SetFlagCopied();  // Set the copied flag...
-  
+
   if (ctx.GetRandom().P(m_organism->GetCopyInsProb() / reduction)) write_head.InsertInst(m_inst_set->GetRandomInst(ctx));
   if (ctx.GetRandom().P(m_organism->GetCopyDelProb() / reduction)) write_head.RemoveInst();
   if (ctx.GetRandom().P(m_organism->GetCopyUniformProb() / reduction)) doUniformCopyMutation(ctx, write_head);
   if (ctx.GetRandom().P(m_organism->GetCopySlipProb() / reduction)) {
     if (m_slip_read_head) {
       read_head.Set(ctx.GetRandom().GetInt(read_head.GetMemory().GetSize()));
-    } else 
+    } else
       doSlipMutation(ctx, write_head.GetMemory(), write_head.GetPosition());
   }
-  
+
   read_head.Advance();
   write_head.Advance();
   return true;
@@ -5798,7 +6029,7 @@
   GetRegister(REG_CX) = GetLabel().GetSize();
   GetHead(nHardware::HEAD_FLOW).Set(found_pos);
   GetHead(nHardware::HEAD_FLOW).Advance();
-  return true; 
+  return true;
 }
 
 bool cHardwareCPU::Inst_HeadSearchDirect(cAvidaContext& ctx)
@@ -5810,107 +6041,107 @@
   GetRegister(REG_CX) = GetLabel().GetSize();
   GetHead(nHardware::HEAD_FLOW).Set(found_pos);
   GetHead(nHardware::HEAD_FLOW).Advance();
-  return true; 
+  return true;
 }
 
 bool cHardwareCPU::Inst_SetFlow(cAvidaContext& ctx)
 {
   const int reg_used = FindModifiedRegister(REG_CX);
   GetHead(nHardware::HEAD_FLOW).Set(GetRegister(reg_used));
-  return true; 
+  return true;
 }
 
 
 /* Execute the next instruction if the organism's energy level is low */
 bool cHardwareCPU::Inst_IfEnergyLow(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   // Note: these instructions should probably also make sure the returned energy level is not -1.
   if(m_organism->GetPhenotype().GetDiscreteEnergyLevel() != cPhenotype::ENERGY_LEVEL_LOW) {
     IP().Advance();
   }
-	
+
   return true;
-	
+
 } //End Inst_IfEnergyLow()
 
 
 /* Execute the next instruction if the organism's energy level is not low */
 bool cHardwareCPU::Inst_IfEnergyNotLow(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   if(m_organism->GetPhenotype().GetDiscreteEnergyLevel() == cPhenotype::ENERGY_LEVEL_LOW) {
     IP().Advance();
   }
-	
+
   return true;
-	
+
 } //End Inst_IfEnergyNotLow()
 
 
 /* Execute the next instruction if the faced organism's energy level is low */
 bool cHardwareCPU::Inst_IfFacedEnergyLow(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   // Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ){
     // Note: these instructions should probably also make sure the returned energy level is not -1.
     if(neighbor->GetPhenotype().GetDiscreteEnergyLevel() != cPhenotype::ENERGY_LEVEL_LOW) {
       IP().Advance();
-    }    
-  }  
-	
+    }
+  }
+
   return true;
-	
+
 } //End Inst_IfFacedEnergyLow()
 
 
 /* Execute the next instruction if the faced organism's energy level is low */
 bool cHardwareCPU::Inst_IfFacedEnergyNotLow(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   // Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
     // Note: these instructions should probably also make sure the returned energy level is not -1.
     if(neighbor->GetPhenotype().GetDiscreteEnergyLevel() == cPhenotype::ENERGY_LEVEL_LOW) {
       IP().Advance();
-    }    
-  }  
-	
+    }
+  }
+
   return true;
-	
+
 } //End Inst_IfFacedEnergyNotLow()
 
 
 /* Execute the next instruction if the organism's energy level is high */
 bool cHardwareCPU::Inst_IfEnergyHigh(cAvidaContext& ctx) {
-	
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   if(m_organism->GetPhenotype().GetDiscreteEnergyLevel() != cPhenotype::ENERGY_LEVEL_HIGH) {
     IP().Advance();
   }
-	
+
   return true;
-	
+
 } //End Inst_IfEnergyHigh()
 
 
@@ -5919,58 +6150,58 @@
 
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   if(m_organism->GetPhenotype().GetDiscreteEnergyLevel() == cPhenotype::ENERGY_LEVEL_HIGH) {
     IP().Advance();
   }
-	
+
   return true;
-	
+
 } //End Inst_IfEnergyNotHigh()
 
 
 /* Execute the next instruction if the faced organism's energy level is high */
 bool cHardwareCPU::Inst_IfFacedEnergyHigh(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   // Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
     // Note: these instructions should probably also make sure the returned energy level is not -1.
     if(neighbor->GetPhenotype().GetDiscreteEnergyLevel() != cPhenotype::ENERGY_LEVEL_HIGH) {
       IP().Advance();
-    }    
-  }  
-	
+    }
+  }
+
   return true;
-	
+
 } //End Inst_IfFacedEnergyHigh()
 
 
 /* Execute the next instruction if the faced organism's energy level is not high */
 bool cHardwareCPU::Inst_IfFacedEnergyNotHigh(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   // Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
     // Note: these instructions should probably also make sure the returned energy level is not -1.
     if(neighbor->GetPhenotype().GetDiscreteEnergyLevel() == cPhenotype::ENERGY_LEVEL_HIGH) {
       IP().Advance();
-    }    
-  }  
-	
+    }
+  }
+
   return true;
-	
+
 } //End Inst_IfFacedEnergyNotHigh()
 
 
@@ -5979,74 +6210,74 @@
 
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
+  }
 
   if(m_organism->GetPhenotype().GetDiscreteEnergyLevel() != cPhenotype::ENERGY_LEVEL_MEDIUM) {
     IP().Advance();
   }
-		
+
   return true;
-	
+
 } //End Inst_IfEnergyMed()
 
 
 /* Execute the next instruction if the faced organism's energy level is medium */
 bool cHardwareCPU::Inst_IfFacedEnergyMed(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   // Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
     // Note: these instructions should probably also make sure the returned energy level is not -1.
     if(neighbor->GetPhenotype().GetDiscreteEnergyLevel() != cPhenotype::ENERGY_LEVEL_MEDIUM) {
       IP().Advance();
-    }    
-  }  
-	
+    }
+  }
+
   return true;
-	
+
 } //End Inst_IfFacedEnergyMed()
 
 
 /* Execute the next instruction if the faced organism has less energy */
 bool cHardwareCPU::Inst_IfFacedEnergyLess(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   // Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
     const double neighbor_energy = neighbor->GetPhenotype().GetStoredEnergy();
     const double my_energy = m_organism->GetPhenotype().GetStoredEnergy();
     const double epsilon = m_world->GetConfig().ENERGY_COMPARISON_EPSILON.Get();
-    
+
     if(neighbor_energy >= (my_energy * (1 - epsilon))) {
       IP().Advance();
-    }    
-  }  
-	
+    }
+  }
+
   return true;
-	
+
 } //End Inst_IfFacedEnergyLess()
 
 
 /* Execute the next instruction if the faced organism has more energy */
 bool cHardwareCPU::Inst_IfFacedEnergyMore(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-	
+  }
+
   // Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
     const double neighbor_energy = neighbor->GetPhenotype().GetStoredEnergy();
     const double my_energy = m_organism->GetPhenotype().GetStoredEnergy();
@@ -6054,164 +6285,164 @@
 
     if(neighbor_energy <= (my_energy * (1 + epsilon))) {
       IP().Advance();
-    }    
-  }  
-	
+    }
+  }
+
   return true;
-	
+
 } //End Inst_IfFacedEnergyMore()
 
 
 /* Execute the next instruction if the organism has received energy */
 bool cHardwareCPU::Inst_IfEnergyInBuffer(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   if(m_organism->GetPhenotype().GetEnergyInBufferAmount() == 0) {
     IP().Advance();
   }
-  
+
   return true;
-	
+
 } //End Inst_IfEnergyInBuffer()
 
 
 /* Execute the next instruction if the organism has not received energy */
 bool cHardwareCPU::Inst_IfEnergyNotInBuffer(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   if(m_organism->GetPhenotype().GetEnergyInBufferAmount() > 0) {
     IP().Advance();
   }
-  
+
   return true;
-	
+
 } //End Inst_IfEnergyNotInBuffer()
 
 
 bool cHardwareCPU::Inst_GetEnergyLevel(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   const int reg = FindModifiedRegister(REG_BX);
   GetRegister(reg) = (int) floor(m_organism->GetPhenotype().GetStoredEnergy());
-  
+
   return true;
-	
+
 } //End Inst_GetEnergyLevel()
 
 
 bool cHardwareCPU::Inst_GetFacedEnergyLevel(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if( (neighbor == NULL) || (neighbor->IsDead()) ) {
-    return false;  
+    return false;
   }
-    
+
   const int reg = FindModifiedRegister(REG_BX);
   GetRegister(reg) = (int) floor(neighbor->GetPhenotype().GetStoredEnergy());
-  
+
   return true;
-	
+
 } //End Inst_GetFacedEnergyLevel()
 
 
 bool cHardwareCPU::Inst_IfFacedEnergyRequestOn(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if( (neighbor == NULL) || (neighbor->IsDead()) ) {
-    return false;  
+    return false;
   }
-  
+
   if(neighbor->GetPhenotype().IsEnergyRequestor() == false) {
     IP().Advance();
   }
-  
+
   return true;
-	
+
 } //End Inst_IfFacedEnergyRequestOn()
 
 bool cHardwareCPU::Inst_IfFacedEnergyRequestOff(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if( (neighbor == NULL) || (neighbor->IsDead()) ) {
-    return false;  
+    return false;
   }
-  
+
   if(neighbor->GetPhenotype().IsEnergyRequestor() == true) {
     IP().Advance();
   }
-  
+
   return true;
-	
+
 } //End Inst_IfFacedEnergyRequestOff()
 
 
 bool cHardwareCPU::Inst_GetEnergyRequestStatus(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   const int reg = FindModifiedRegister(REG_BX);
   int status = 0;
-  
+
   if(m_organism->GetPhenotype().IsEnergyRequestor() == true) {
-    status = 1; 
+    status = 1;
   }
-  
+
   GetRegister(reg) = status;
-  
+
   return true;
-  
+
 } //End Inst_GetEnergyRequestStatus()
 
 
 bool cHardwareCPU::Inst_GetFacedEnergyRequestStatus(cAvidaContext& ctx) {
-  
+
   if(m_organism->GetCellID() < 0) {
     return false;
-  }	
-  
+  }
+
   cOrganism * neighbor = m_organism->GetNeighbor();
-  
+
   if( (neighbor == NULL) || (neighbor->IsDead()) ) {
-    return false;  
+    return false;
   }
-  
+
   const int reg = FindModifiedRegister(REG_BX);
   int status = 0;
-  
+
   if(neighbor->GetPhenotype().IsEnergyRequestor() == true) {
-    status = 1; 
+    status = 1;
   }
-  
+
   GetRegister(reg) = status;
-  
+
   return true;
-  
+
 } //End Inst_GetFacedEnergyRequestStatus()
 
 
@@ -6254,8 +6485,8 @@
   int deme_id = m_organism->GetOrgInterface().GetDemeID();
   // Fail if we're running in the test CPU.
   if((deme_id < 0) || (absolute_cell_ID < 0)) return false;
-  
-  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);  
+
+  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
   const int xreg = FindModifiedRegister(REG_BX);
   const int yreg = FindNextRegister(xreg);
   GetRegister(xreg) = pos.first;
@@ -6273,8 +6504,8 @@
   int deme_id = m_organism->GetOrgInterface().GetDemeID();
   // Fail if we're running in the test CPU.
   if((deme_id < 0) || (absolute_cell_ID < 0)) return false;
-  
-  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);  
+
+  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
   const int xreg = FindModifiedRegister(REG_BX);
   GetRegister(xreg) = pos.first;
   return true;
@@ -6290,8 +6521,8 @@
   int deme_id = m_organism->GetOrgInterface().GetDemeID();
   // Fail if we're running in the test CPU.
   if((deme_id < 0) || (absolute_cell_ID < 0)) return false;
-  
-  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);  
+
+  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
   const int yreg = FindModifiedRegister(REG_BX);
   GetRegister(yreg) = pos.second;
   return true;
@@ -6302,10 +6533,10 @@
   int deme_id = m_organism->GetOrgInterface().GetDemeID();
   // Fail if we're running in the test CPU.
   if((deme_id < 0) || (absolute_cell_ID < 0)) return false;
-  
-  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);  
+
+  std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
   const int reg = FindModifiedRegister(REG_BX);
-  
+
   if(pos.first > pos.second) {
     GetRegister(reg) = (int)ceil((pos.first - pos.second)/2.0);
   } else {
@@ -6335,35 +6566,35 @@
     m_threads[m_cur_thread].Reset(this, m_threads[m_cur_thread].GetID());
     //GetHead(nHardware::HEAD_WRITE).Set(write_head_pos);
     //GetHead(nHardware::HEAD_READ).Set(read_head_pos);
-    
+
     //Setting this makes it harder to do things. You have to be modular.
     m_organism->GetOrgInterface().ResetInputs(ctx);   // Re-randomize the inputs this organism sees
     m_organism->ClearInput();                         // Also clear their input buffers, or they can still claim
                                                     // rewards for numbers no longer in their environment!
   }
-  
+
   // Reset our count
   m_threads[m_cur_thread].ResetPromoterInstExecuted();
   m_advance_ip = false;
   const int reg_used = REG_BX; // register to put chosen promoter code in, for now always BX
 
-  // Search for an active promoter  
+  // Search for an active promoter
   int start_offset = m_promoter_offset;
   int start_index  = m_promoter_index;
-  
+
   bool no_promoter_found = true;
-  if ( m_promoters.GetSize() > 0 ) 
+  if ( m_promoters.GetSize() > 0 )
   {
     while( true )
     {
       // If the next promoter is active, then break out
       NextPromoter();
-      if (IsActivePromoter()) 
+      if (IsActivePromoter())
       {
         no_promoter_found = false;
         break;
       }
-      
+
       // If we just checked the promoter that we were originally on, then there
       // are no active promoters.
       if ( (start_offset == m_promoter_offset) && (start_index == m_promoter_index) ) break;
@@ -6374,9 +6605,9 @@
       {
           start_index = 0;
       }
-    } 
+    }
   }
-  
+
   if (no_promoter_found)
   {
     if ((m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 0) || (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() == 2))
@@ -6401,7 +6632,7 @@
     // We found an active match, offset to just after it.
     // cHeadCPU will do the mod genome size for us
     IP().Set(m_promoters[m_promoter_index].m_pos + 1);
-    
+
     // Put its bit code in BX for the organism to have if option is set
     if ( m_world->GetConfig().PROMOTER_TO_REGISTER.Get() )
     {
@@ -6429,18 +6660,18 @@
 {
   const int reg_used = FindModifiedRegister(REG_BX);
   int regulation_code = GetRegister(reg_used);
-  
+
   const int reg_promoter = FindModifiedRegister((reg_used+1) % NUM_REGISTERS);
   int regulation_promoter = GetRegister(reg_promoter);
-  
+
   for (int i=0; i< m_promoters.GetSize();i++)
   {
     //Look for consensus bit matches over the length of the promoter code
-    int test_p_code = m_promoters[i].m_bit_code;    
+    int test_p_code = m_promoters[i].m_bit_code;
     int test_r_code = regulation_promoter;
     int bit_count = 0;
     for (int j=0; j<m_world->GetConfig().PROMOTER_EXE_LENGTH.Get();j++)
-    {      
+    {
       if ((test_p_code & 1) == (test_r_code & 1)) bit_count++;
       test_p_code >>= 1;
       test_r_code >>= 1;
@@ -6464,8 +6695,8 @@
     int b = i % res_count.GetSize();
     bits <<= 1;
     bits += (res_count[b] != 0);
-  }  
-  
+  }
+
   for (int i=0; i< m_promoters.GetSize();i++)
   {
     m_promoters[i].m_regulation = bits;
@@ -6477,11 +6708,11 @@
 bool cHardwareCPU::Do_Numberate(cAvidaContext& ctx, int num_bits)
 {
   const int reg_used = FindModifiedRegister(REG_BX);
-  
+
   // advance the IP now, so that it rests on the beginning of our number
   IP().Advance();
   m_advance_ip = false;
-  
+
   int num = Numberate(IP().GetPosition(), +1, num_bits);
   GetRegister(reg_used) = num;
   return true;
@@ -6495,7 +6726,7 @@
   if (m_promoter_index == m_promoters.GetSize())
   {
     m_promoter_index = 0;
-    
+
     // Move offset, rolling over when there are not enough bits before we would have to wrap around left
     m_promoter_offset+=m_world->GetConfig().PROMOTER_EXE_LENGTH.Get();
     if (m_promoter_offset + m_world->GetConfig().PROMOTER_EXE_LENGTH.Get() > m_world->GetConfig().PROMOTER_CODE_SIZE.Get())
@@ -6525,13 +6756,13 @@
 
 // Construct a promoter bit code from instruction bit codes
 int cHardwareCPU::Numberate(int _pos, int _dir, int _num_bits)
-{  
+{
   int code_size = 0;
   unsigned int code = 0;
   unsigned int max_bits = sizeof(code) * 8;
   assert(_num_bits <= (int)max_bits);
   if (_num_bits == 0) _num_bits = max_bits;
-  
+
   // Enforce a boundary, sometimes -1 can be passed for _pos
   int j = _pos + m_memory.GetSize();
   j %= m_memory.GetSize();
@@ -6547,23 +6778,23 @@
       {
         code >>= 1; // shift first so we don't go one too far at the end
         code += (1 << (_num_bits - 1)) * (inst_code & 1);
-        inst_code >>= 1; 
+        inst_code >>= 1;
       }
       else
       {
-        code <<= 1; // shift first so we don't go one too far at the end;        
+        code <<= 1; // shift first so we don't go one too far at the end;
         code += (inst_code >> (m_world->GetConfig().INST_CODE_LENGTH.Get() - 1)) & 1;
-        inst_code <<= 1; 
+        inst_code <<= 1;
       }
       code_size++;
     }
-    
+
      // move back one inst
     j += m_memory.GetSize() + _dir;
     j %= m_memory.GetSize();
 
   }
-  
+
   return code;
 }
 
@@ -6586,7 +6817,7 @@
   const int reg_used = FindModifiedRegister(REG_BX);
   const int op1 = FindModifiedNextRegister(reg_used);
   GetRegister(reg_used) = (BitCount(GetRegister(op1)) >= CONSENSUS) ? 1 : 0;
-  return true; 
+  return true;
 }
 
 bool cHardwareCPU::Inst_BitConsensus24(cAvidaContext& ctx)
@@ -6594,7 +6825,7 @@
   const int reg_used = FindModifiedRegister(REG_BX);
   const int op1 = FindModifiedNextRegister(reg_used);
   GetRegister(reg_used) = (BitCount(GetRegister(op1) & MASK24) >= CONSENSUS24) ? 1 : 0;
-  return true; 
+  return true;
 }
 
 bool cHardwareCPU::Inst_IfConsensus(cAvidaContext& ctx)
@@ -6638,7 +6869,7 @@
 {
   const int label_reg = FindModifiedRegister(REG_BX);
   const int data_reg = FindNextRegister(label_reg);
-  
+
   cOrgMessage msg = cOrgMessage(m_organism);
   msg.SetLabel(GetRegister(label_reg));
   msg.SetData(GetRegister(data_reg));
@@ -6651,22 +6882,22 @@
 If a message is available, ?BX? is set to the message's label, and ~?BX? is set
 to its data.
 */
-bool cHardwareCPU::Inst_RetrieveMessage(cAvidaContext& ctx) 
+bool cHardwareCPU::Inst_RetrieveMessage(cAvidaContext& ctx)
 {
   const cOrgMessage* msg = m_organism->RetrieveMessage();
   if(msg == 0)
     return false;
-  
+
   const int label_reg = FindModifiedRegister(REG_BX);
   const int data_reg = FindNextRegister(label_reg);
-  
+
   GetRegister(label_reg) = msg->GetLabel();
   GetRegister(data_reg) = msg->GetData();
   return true;
 }
 
 bool cHardwareCPU::Inst_Alarm_MSG_multihop(cAvidaContext& ctx) {
-  const int reg_used = FindModifiedRegister(REG_BX);  
+  const int reg_used = FindModifiedRegister(REG_BX);
   return m_organism->BcastAlarmMSG(ctx, abs(GetRegister(reg_used)%2), m_world->GetConfig().BCAST_HOPS.Get()); // jump to Alarm-label-  odd=high  even=low
 }
 
@@ -6676,7 +6907,7 @@
 }
 
 bool cHardwareCPU::Inst_Alarm_MSG_local(cAvidaContext& ctx) {
-  const int reg_used = FindModifiedRegister(REG_BX);  
+  const int reg_used = FindModifiedRegister(REG_BX);
   return m_organism->BcastAlarmMSG(ctx, abs(GetRegister(reg_used)%2), 1); // jump to Alarm-label-  odd=high  even=low
 }
 
@@ -6696,7 +6927,7 @@
   }
 
   cString channel;
-  
+
   if(jump_label == 1) {
     channel = "high";
   } else if(jump_label == 0) {
@@ -6704,13 +6935,13 @@
   } else {
     assert(false);
   }
-  
+
   cInstruction label_inst = GetInstSet().GetInst(cStringUtil::Stringf("alarm-label-")+channel);
-  
+
   cHeadCPU search_head(IP());
   int start_pos = search_head.GetPosition();
   search_head++;
-  
+
   while (start_pos != search_head.GetPosition()) {
     if (search_head.GetInst() == label_inst) {
       // move IP to here
@@ -6757,62 +6988,62 @@
 
   int faced_id = mycell.GetCellFaced().GetID();
 
-  // Returns the amount of a resource or resources 
+  // Returns the amount of a resource or resources
   // specified by modifying NOPs into register BX
-  const tArray<double> & res_count = m_world->GetPopulation().GetCellResources(faced_id); 
-  
+  const tArray<double> & res_count = m_world->GetPopulation().GetCellResources(faced_id);
+
   // Arbitrarily set to BX since the conditional instructions use this directly.
   int reg_to_set = REG_BX;
-  
+
   // There are no resources, return
   if (res_count.GetSize() == 0) return false;
-  
+
   // Only recalculate logs if these values have changed
   static int last_num_resources = 0;
   static int max_label_length = 0;
   int num_nops = GetInstSet().GetNumNops();
-  
+
   if ((last_num_resources != res_count.GetSize()))
   {
     max_label_length = (int) ceil(log((double)res_count.GetSize())/log((double)num_nops));
     last_num_resources = res_count.GetSize();
   }
-  
+
   // Convert modifying NOPs to the index of the resource.
   // If there are fewer than the number of NOPs required
   // to uniquely specify a resource, then add together
   // a subset of resources (motivation: regulation can evolve
   // to be more specific if there is an advantage)
-  
+
   // Find the maximum number of NOPs needed to specify this number of resources
   // Note: It's a bit wasteful to recalculate this every time and organisms will
   // definitely be confused if the number of resources changes during a run
   // because their mapping to resources will be disrupted
-  
+
   // Attempt to read a label with this maximum length
   ReadLabel(max_label_length);
-  
+
   // Find the length of the label that we actually obtained (max is max_reg_needed)
   int real_label_length = GetLabel().GetSize();
-  
-  // Start and end labels to define the start and end indices of  
+
+  // Start and end labels to define the start and end indices of
   // resources that we need to add together
   cCodeLabel start_label = cCodeLabel(GetLabel());
   cCodeLabel   end_label = cCodeLabel(GetLabel());
-  
+
   for (int i = 0; i < max_label_length - real_label_length; i++)
   {
     start_label.AddNop(0);
     end_label.AddNop(num_nops-1);
   }
-  
+
   int start_index = start_label.AsInt(num_nops);
   int   end_index =   end_label.AsInt(num_nops);
-  
-  // If the label refers to ONLY resources that 
+
+  // If the label refers to ONLY resources that
   // do not exist, then the operation fails
   if (start_index >= res_count.GetSize()) return false;
-  
+
   // Otherwise sum all valid resources that it might refer to
   // (this will only be ONE if the label was of the maximum length).
   int resource_result = 0;
@@ -6833,9 +7064,9 @@
         // Do some range checking to make sure we don't overflow
         resource_result = (INT_MAX - resource_result <= add_amount) ? INT_MAX : resource_result + add_amount;
       }
-    } 
+    }
   }
-  
+
   // Take the log after adding resource amounts together! This way a zero can be assigned to INT_MIN
   if (conversion_method == 0) // Log2
   {
@@ -6849,10 +7080,10 @@
       resource_result = (int)(log(dresource_result)/log(base));
     }
   }
-  
+
   //Dump this value into an arbitrary register: BX
   GetRegister(reg_to_set) = resource_result;
-  
+
   //We have to convert this to a different index that includes all degenerate labels possible: shortest to longest
   int sensed_index = 0;
   int on = 1;
@@ -6863,9 +7094,9 @@
   }
   sensed_index+= GetLabel().AsInt(num_nops);
   m_organism->GetPhenotype().IncSenseCount(sensed_index);
-  
-  return true; 
-  
+
+  return true;
+
   // Note that we are converting <double> resources to <int> register values
 } //End DoSenseFacing()
 
@@ -6892,10 +7123,10 @@
   if(cellid == -1) {
     return false;
   }
-	
+
   int cell_data = m_world->GetPopulation().GetCell(cellid).GetCellData();
   int val = 0;
-	
+
   if(cell_data > 0) {
     val = 1;
   }
@@ -6910,16 +7141,16 @@
 
   cPopulation& pop = m_world->GetPopulation();
   int cellid = m_organism->GetCellID();
-	
+
   if(cellid == -1) {
     return false;
   }
-	
+
   cPopulationCell& mycell = pop.GetCell(cellid);
-	
+
   int cell_data = mycell.GetCellFaced().GetCellData(); //absolute id of faced cell
   int val = 0;
-	
+
   if(cell_data > 0) {
     val = 1;
   }
@@ -6947,7 +7178,7 @@
   double pher_amount = 0;
 
   if(deme_resource_count.GetSize() == 0) return false;
-  
+
   for (int i = 0; i < deme_resource_count.GetSize(); i++) {
     if(strncmp(deme_resource_count.GetResName(i), "pheromone", 9) == 0) {
       pher_amount += cell_resources[i];
@@ -7011,7 +7242,7 @@
   tArray<double> cell_resources;
 
   int fromcellID, destcellID;
-  
+
   // Get stepsize. Currently, all moves are one cell regardless of stepsize.
   // This could be changed in the future.
   const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
@@ -7068,13 +7299,13 @@
     } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
       m_organism->SetGradientMovement(0.0);
     } else { // move down gradient
-      m_organism->SetGradientMovement(-1.0);    
+      m_organism->SetGradientMovement(-1.0);
     }
-    /*********************/ 
+    /*********************/
 
     pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
     pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-    
+
     m_world->GetStats().Move(*m_organism);
 
     // If organism is dropping pheromones, mark the appropriate cell(s)
@@ -7083,7 +7314,7 @@
 
         pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
 	drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
-	
+
 	if(drop_mode == 0) {
           deme.AddPheromone(fromcellID, pher_amount/2);
           deme.AddPheromone(destcellID, pher_amount/2);
@@ -7149,7 +7380,7 @@
   tArray<double> cell_resources;
 
   int fromcellID, destcellID;
-  
+
   // Get stepsize. Currently, all moves are one cell regardless of stepsize.
   // This could be changed in the future.
   const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
@@ -7180,7 +7411,7 @@
           phero_amount += cell_resources[j];
         }
       }
- 
+
       if(phero_amount > max_pheromone) {
         num_rotations = i;
         max_pheromone = phero_amount;
@@ -7213,13 +7444,13 @@
     } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
       m_organism->SetGradientMovement(0.0);
     } else { // move down gradient
-      m_organism->SetGradientMovement(-1.0);    
+      m_organism->SetGradientMovement(-1.0);
     }
-    /*********************/ 
+    /*********************/
 
     pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
     pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-    
+
     m_world->GetStats().Move(*m_organism);
 
     // If organism is dropping pheromones, mark the appropriate cell(s)
@@ -7228,7 +7459,7 @@
 
         pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
 	drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
-	
+
 	if(drop_mode == 0) {
           deme.AddPheromone(fromcellID, pher_amount/2);
           deme.AddPheromone(destcellID, pher_amount/2);
@@ -7293,7 +7524,7 @@
   tArray<double> cell_resources;
 
   int fromcellID, destcellID;
-  
+
   // Get stepsize. Currently, all moves are one cell regardless of stepsize.
   // This could be changed in the future.
   const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
@@ -7356,13 +7587,13 @@
     } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
       m_organism->SetGradientMovement(0.0);
     } else { // move down gradient
-      m_organism->SetGradientMovement(-1.0);    
+      m_organism->SetGradientMovement(-1.0);
     }
-    /*********************/ 
+    /*********************/
 
     pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
     pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-    
+
     m_world->GetStats().Move(*m_organism);
 
     // If organism is dropping pheromones, mark the appropriate cell(s)
@@ -7371,7 +7602,7 @@
 
         pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
 	drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
-	
+
 	if(drop_mode == 0) {
           deme.AddPheromone(fromcellID, pher_amount/2);
           deme.AddPheromone(destcellID, pher_amount/2);
@@ -7460,13 +7691,13 @@
     } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
       m_organism->SetGradientMovement(0.0);
     } else { // move down gradient
-      m_organism->SetGradientMovement(-1.0);    
+      m_organism->SetGradientMovement(-1.0);
     }
-    /*********************/ 
+    /*********************/
 
     pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
     pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-    
+
     m_world->GetStats().Move(*m_organism);
 
     // If organism is dropping pheromones, mark the cells appropriately
@@ -7475,7 +7706,7 @@
 
         pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
 	drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
-	
+
 	if(drop_mode == 0) {
           deme.AddPheromone(fromcellID, pher_amount/2);
           deme.AddPheromone(destcellID, pher_amount/2);
@@ -7535,7 +7766,7 @@
 
   int fromcellID, destcellID;
   int cell_data;
-  
+
   // Get stepsize. Currently, all moves are one cell regardless of stepsize.
   // This could be changed in the future.
   const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
@@ -7580,13 +7811,13 @@
     } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
       m_organism->SetGradientMovement(0.0);
     } else { // move down gradient
-      m_organism->SetGradientMovement(-1.0);    
+      m_organism->SetGradientMovement(-1.0);
     }
-    /*********************/ 
+    /*********************/
 
     pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
     pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-    
+
     m_world->GetStats().Move(*m_organism);
 
 
@@ -7596,7 +7827,7 @@
 
         pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
 	drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
-	
+
 	if(drop_mode == 0) {
           deme.AddPheromone(fromcellID, pher_amount/2);
           deme.AddPheromone(destcellID, pher_amount/2);
@@ -7659,7 +7890,7 @@
 
   int fromcellID, destcellID;
   int cell_data;
-  
+
   // Get stepsize. Currently, all moves are one cell regardless of stepsize.
   // This could be changed in the future.
   const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
@@ -7672,7 +7903,7 @@
 
   // Find if any neighbor is a target
   for(int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
-    
+
     // Skip the cells behind
     if(i == 3 || i == 4 || i == 5) {
       mycell.ConnectionList().CircNext();
@@ -7713,13 +7944,13 @@
     } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
       m_organism->SetGradientMovement(0.0);
     } else { // move down gradient
-      m_organism->SetGradientMovement(-1.0);    
+      m_organism->SetGradientMovement(-1.0);
     }
-    /*********************/ 
+    /*********************/
 
     pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
     pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-    
+
     m_world->GetStats().Move(*m_organism);
 
 
@@ -7729,7 +7960,7 @@
 
         pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
 	drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
-	
+
 	if(drop_mode == 0) {
           deme.AddPheromone(fromcellID, pher_amount/2);
           deme.AddPheromone(destcellID, pher_amount/2);
@@ -7791,7 +8022,7 @@
 
   int fromcellID, destcellID;
   int cell_data;
-  
+
   // Get stepsize. Currently, all moves are one cell regardless of stepsize.
   // This could be changed in the future.
   const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
@@ -7804,7 +8035,7 @@
 
   // Find if any neighbor is a target
   for(int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
-    
+
     // Skip the cells behind
     if(i==2 || i == 3 || i == 4 || i == 5 || i == 6) {
       mycell.ConnectionList().CircNext();
@@ -7845,13 +8076,13 @@
     } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
       m_organism->SetGradientMovement(0.0);
     } else { // move down gradient
-      m_organism->SetGradientMovement(-1.0);    
+      m_organism->SetGradientMovement(-1.0);
     }
-    /*********************/ 
+    /*********************/
 
     pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
     pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-    
+
     m_world->GetStats().Move(*m_organism);
 
 
@@ -7861,7 +8092,7 @@
 
         pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
 	drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
-	
+
 	if(drop_mode == 0) {
           deme.AddPheromone(fromcellID, pher_amount/2);
           deme.AddPheromone(destcellID, pher_amount/2);
@@ -7921,7 +8152,7 @@
 
   int fromcellID, destcellID;
   int cell_data;
-  
+
   // Get stepsize. Currently, all moves are one cell regardless of stepsize.
   // This could be changed in the future.
   const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
@@ -7989,13 +8220,13 @@
     } else if(pop.GetCell(fromcellID).GetCellData() == pop.GetCell(destcellID).GetCellData()) {
       m_organism->SetGradientMovement(0.0);
     } else { // move down gradient
-      m_organism->SetGradientMovement(-1.0);    
+      m_organism->SetGradientMovement(-1.0);
     }
-    /*********************/ 
+    /*********************/
 
     pop.SwapCells(pop.GetCell(fromcellID),pop.GetCell(destcellID));
     pop.MoveOrganisms(ctx, pop.GetCell(fromcellID), pop.GetCell(destcellID));
-    
+
     m_world->GetStats().Move(*m_organism);
 
     // If organism is dropping pheromones, mark the appropriate cell(s)
@@ -8004,7 +8235,7 @@
 
         pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
 	drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
-	
+
 	if(drop_mode == 0) {
           deme.AddPheromone(fromcellID, pher_amount/2);
           deme.AddPheromone(destcellID, pher_amount/2);
@@ -8046,11 +8277,11 @@
 bool cHardwareCPU::Inst_IfTarget(cAvidaContext& ctx)
 {
   int cellid = m_organism->GetCellID(); //absolute id of current cell
-	
+
   if(cellid == -1) {
 	return true;
-  }		
-	
+  }
+
   int cell_data = m_world->GetPopulation().GetCell(cellid).GetCellData();
 
   if(cell_data == -1) {
@@ -8064,11 +8295,11 @@
 bool cHardwareCPU::Inst_IfNotTarget(cAvidaContext& ctx)
 {
   int cellid = m_organism->GetCellID(); //absolute id of current cell
-	
+
   if(cellid == -1) {
     return true;
-  }	
-	
+  }
+
   int cell_data = m_world->GetPopulation().GetCell(cellid).GetCellData();
 
   if(cell_data > 0) {
@@ -8097,7 +8328,7 @@
   if(deme_resource_count.GetSize() == 0) return false;
 
   double pher_amount = 0;
-  
+
   for (int i = 0; i < deme_resource_count.GetSize(); i++) {
     if(strncmp(deme_resource_count.GetResName(i), "pheromone", 9) == 0) {
       pher_amount += cell_resources[i];
@@ -8131,7 +8362,7 @@
   if(deme_resource_count.GetSize() == 0) return false;
 
   double pher_amount = 0;
-  
+
   for (int i = 0; i < deme_resource_count.GetSize(); i++) {
     if(strncmp(deme_resource_count.GetResName(i), "pheromone", 9) == 0) {
       pher_amount += cell_resources[i];
@@ -8162,7 +8393,7 @@
   // Note: right now, we're ignoring the organism's pheromone status and always
   //   dropping if pheromones are enabled
   if(m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) {
-	
+
     const double pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
     //const int drop_mode =  m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
 
@@ -8179,7 +8410,7 @@
     }
     */
     deme.AddPheromone(cellid, pher_amount);
-    
+
     // Write some logging information if LOG_PHEROMONE is set.  This is done
     // out here so that non-pheromone moves are recorded.
     if( (m_world->GetConfig().LOG_PHEROMONE.Get() == 1) &&
@@ -8230,7 +8461,7 @@
   if(m_organism->HasOpinion()) {
     const int opinion_reg = FindModifiedRegister(REG_BX);
     const int age_reg = FindNextRegister(opinion_reg);
-  
+
     GetRegister(opinion_reg) = m_organism->GetOpinion().first;
     GetRegister(age_reg) = m_world->GetStats().GetUpdate() - m_organism->GetOpinion().second;
   }
@@ -8266,7 +8497,7 @@
 	if(!m_last_cell_data.first || (m_last_cell_data.second == m_organism->GetCellData())) {
 		IP().Advance();
 	}
-	
+
 	return true;
 }
 
@@ -8275,7 +8506,7 @@
   // Fail if we're running in the test CPU.
   if((m_organism->GetOrgInterface().GetDemeID() < 0) || (m_organism->GetCellID() < 0))
     return false;
-	
+
   const int reg = FindModifiedRegister(REG_BX);
   int eventID = m_organism->GetCellData();
   GetRegister(reg) = m_organism->GetOrgInterface().GetDeme()->KillCellEvent(eventID);
@@ -8287,14 +8518,14 @@
   // Fail if we're running in the test CPU.
   if((m_organism->GetOrgInterface().GetDemeID() < 0) || (m_organism->GetCellID() < 0))
     return false;
-	
+
   const int reg = FindModifiedRegister(REG_BX);
   int eventID = m_organism->GetNeighborCellContents();
   GetRegister(reg) = m_organism->GetOrgInterface().GetDeme()->KillCellEvent(eventID);
-  
+
   if(GetRegister(reg))
     m_organism->SetEventKilled();
-  
+
   return true;
 }
 
@@ -8303,11 +8534,11 @@
   // Fail if we're running in the test CPU.
   if((m_organism->GetOrgInterface().GetDemeID() < 0) || (m_organism->GetCellID() < 0))
     return false;
-  
+
   const int out_reg = FindModifiedRegister(REG_BX);
   int eventID = m_organism->GetCellData();
   GetRegister(out_reg) = eventID;
-  
+
   m_organism->GetOrgInterface().GetDeme()->KillCellEvent(eventID);
   return true;
 }
@@ -8343,7 +8574,7 @@
   assert(m_organism != 0);
   const int bx = FindModifiedRegister(REG_BX);
   const int cx = FindNextRegister(bx);
-  
+
   if(m_flash_info.first > 0) {
     assert(m_cycle_counter >= m_flash_info.second);
     GetRegister(bx) = m_flash_info.first;
@@ -8360,7 +8591,7 @@
 bool cHardwareCPU::Inst_FlashInfoB(cAvidaContext& ctx) {
   assert(m_organism != 0);
   const int bx = FindModifiedRegister(REG_BX);
-  
+
   if(m_flash_info.first > 0) {
     assert(m_cycle_counter >= m_flash_info.second);
     GetRegister(bx) = m_flash_info.first;
@@ -8407,7 +8638,7 @@
   if(!m_organism->HasNeighborhoodChanged()) {
 		IP().Advance();
 	}
-	
+
 	return true;
 }
 
@@ -8433,7 +8664,7 @@
 bool cHardwareCPU::Inst_IfLessEnd(cAvidaContext& ctx) {
   const int x = FindModifiedRegister(REG_BX);
   const int y = FindNextRegister(x);
-	
+
   if(GetRegister(x) >= GetRegister(y)) { Else_TopHalf(); }
   return true;
 }
@@ -8442,16 +8673,16 @@
 bool cHardwareCPU::Inst_IfNotEqualEnd(cAvidaContext& ctx) {
   const int x = FindModifiedRegister(REG_BX);
   const int y = FindNextRegister(x);
-  
+
   if(GetRegister(x) == GetRegister(y)) { Else_TopHalf(); }
-  return true;  
+  return true;
 }
 
 
 bool cHardwareCPU::Inst_IfGrtEquEnd(cAvidaContext& ctx) {
   const int x = FindModifiedRegister(REG_BX);
   const int y = FindNextRegister(x);
-  
+
   if(GetRegister(x) < GetRegister(y)) { Else_TopHalf(); }
   return true;
 }
@@ -8462,8 +8693,8 @@
  */
 void cHardwareCPU::Else_TopHalf() {
   cHeadCPU else_head = Find("else");
-  cHeadCPU endif_head = Find("endif");  
-	
+  cHeadCPU endif_head = Find("endif");
+
   // Condition failed.  If there's an else-clause, jump to it.
   // If there isn't an else-clause, try to jump to the endif.
   // Note that the IP is unconditionally advanced *after* this instruction
@@ -8492,13 +8723,13 @@
     // Otherwise, just skip one instruction.
     IP().Advance();
   }
-  return true; 
+  return true;
 }
 
 /*! This is just a placeholder; it has no functionality of its own.
  */
-bool cHardwareCPU::Inst_EndIf(cAvidaContext& ctx) { 
-  return true; 
+bool cHardwareCPU::Inst_EndIf(cAvidaContext& ctx) {
+  return true;
 }
 
 
@@ -8508,7 +8739,7 @@
 bool cHardwareCPU::BroadcastX(cAvidaContext& ctx, int depth) {
 	const int label_reg = FindModifiedRegister(REG_BX);
   const int data_reg = FindNextRegister(label_reg);
-  
+
   cOrgMessage msg = cOrgMessage(m_organism);
   msg.SetLabel(GetRegister(label_reg));
   msg.SetData(GetRegister(data_reg));
@@ -8557,25 +8788,25 @@
 		// check if the neighbor was a donor
 		if (m_organism->IsDonor(neighbor->GetID())) {
 			m_world->GetStats().IncDonateToDonor();
-			Inst_DonateFacingRawMaterialsOtherSpecies(ctx);	
+			Inst_DonateFacingRawMaterialsOtherSpecies(ctx);
 		}
 	}
 	return true;
 }
 
-/* Donate raw materials (of one kind) to a neighbor, but 
- only if the neighbor is of a different species. If the 
+/* Donate raw materials (of one kind) to a neighbor, but
+ only if the neighbor is of a different species. If the
  instruction fails, there is no consequence. */
-bool cHardwareCPU::Inst_DonateFacingRawMaterialsOtherSpecies(cAvidaContext& ctx) 
-{ 
+bool cHardwareCPU::Inst_DonateFacingRawMaterialsOtherSpecies(cAvidaContext& ctx)
+{
 	cOrganism * neighbor = m_organism->GetNeighbor();
 	if (neighbor != NULL) {
-		
+
 		int spec_self =  m_organism->GetLineageLabel();
 		int spec_neighbor = neighbor->GetLineageLabel();
-		
+
 		if (spec_self != spec_neighbor) {
-			Inst_DonateFacingString(ctx);	
+			Inst_DonateFacingString(ctx);
 		}
 	}
 	return true;
@@ -8586,74 +8817,74 @@
 {
 	// Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-	int cost = m_world->GetConfig().ALT_COST.Get(); 
+	int cost = m_world->GetConfig().ALT_COST.Get();
 	int my_string = m_organism->GetLineageLabel();
-	
-	
+
+
   // Donate only if we have found a neighbor.
   if (neighbor != NULL) {
-		
+
     // Check if the organism has enough of this string on hand.
-		if ((m_organism->GetNumberStringsOnHand(my_string) >= cost) && (neighbor->CanReceiveString(my_string, cost))) { 
-			
-			// sometimes the donation will fail. 
+		if ((m_organism->GetNumberStringsOnHand(my_string) >= cost) && (neighbor->CanReceiveString(my_string, cost))) {
+
+			// sometimes the donation will fail.
 			// get the probability of failure
-			unsigned int prob_fail = m_world->GetConfig().DONATION_FAILURE_PERCENT.Get(); 
-			unsigned int rand_num = m_world->GetRandom().GetUInt(0, 100); 
+			unsigned int prob_fail = m_world->GetConfig().DONATION_FAILURE_PERCENT.Get();
+			unsigned int rand_num = m_world->GetRandom().GetUInt(0, 100);
 			// neighbor donates to organism.
-			if (rand_num < prob_fail) { 
+			if (rand_num < prob_fail) {
 				// EXIT
-				return true; 
+				return true;
 			}
-			
-			
+
+
 			m_organism->DonateString(my_string, cost);
-			neighbor->AddOtherRawMaterials(cost, m_organism->GetID()); 
-			neighbor->ReceiveString(my_string, cost, m_organism->GetID()); 
+			neighbor->AddOtherRawMaterials(cost, m_organism->GetID());
+			neighbor->ReceiveString(my_string, cost, m_organism->GetID());
 			neighbor->AddDonatedLineage(m_organism->GetLineageLabel());
-			
+
 			// track stats
 			m_organism->Donated();
-			
-			ComputeReputation();			
+
+			ComputeReputation();
 		}
   }
   return true;
-	
-	
+
+
 }
 
 /* Donate raw materials to the facing organism. */
 bool cHardwareCPU::Inst_DonateFacingRawMaterials(cAvidaContext& ctx)
 {
-  
+
 	// Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-	int cost = m_world->GetConfig().ALT_COST.Get(); 
-	
-	
+	int cost = m_world->GetConfig().ALT_COST.Get();
+
+
   // Donate only if we have found a neighbor.
   if (neighbor != NULL) {
-		
+
     // Subtract raw materials from the organism (currently subtracts 1 resource...)
 		// fails if the organism does not have any more resources
 		if (m_organism->SubtractSelfRawMaterials(cost)) {
-			
-			// sometimes the donation will fail. 
+
+			// sometimes the donation will fail.
 			// get the probability of failure
-			unsigned int prob_fail = m_world->GetConfig().DONATION_FAILURE_PERCENT.Get(); 
-			unsigned int rand_num = m_world->GetRandom().GetUInt(0, 100); 
+			unsigned int prob_fail = m_world->GetConfig().DONATION_FAILURE_PERCENT.Get();
+			unsigned int rand_num = m_world->GetRandom().GetUInt(0, 100);
 			// neighbor donates to organism.
-			if (rand_num < prob_fail) { 
+			if (rand_num < prob_fail) {
 				// EXIT
-				return true; 
+				return true;
 			}
-			
-			
-			neighbor->AddOtherRawMaterials(cost, m_organism->GetID()); 
+
+
+			neighbor->AddOtherRawMaterials(cost, m_organism->GetID());
 			neighbor->AddDonatedLineage(m_organism->GetLineageLabel());
-			
-			// rotate recipient to face donor 
+
+			// rotate recipient to face donor
 			// by rotating until the recipient faces the donor
 			// adding a new comment.
 			if (m_world->GetConfig().ROTATE_ON_DONATE.Get()) {
@@ -8661,17 +8892,17 @@
 					neighbor->Rotate(1);
 				}
 			}
-			
-			
+
+
 			// track stats
 			m_organism->Donated();
-			
+
 			ComputeReputation();
-			
+
 		}
   }
   return true;
-}  
+}
 
 
 
@@ -8680,17 +8911,17 @@
 bool cHardwareCPU::Inst_Pose(cAvidaContext& ctx)
 {
 	// update reputation to include this phony donation.
-	// get the current reputation; increment by 1.	
+	// get the current reputation; increment by 1.
 	m_organism->SetReputation(m_organism->GetReputation() + 1);
-	
+
   return true;
 }
 
 
 
-/*! An organism's reputation is stored as an opinion. This instruction 
+/*! An organism's reputation is stored as an opinion. This instruction
  uses Inst_GetNeighborsOpinion to do the heavy lifting, but includes
- default behavior suitable for reputations. Specifically, if an 
+ default behavior suitable for reputations. Specifically, if an
  neighbor has no reputation (i.e., it has not donated) or does not
  exist, then this instruction puts zeros into the registers.
  */
@@ -8698,18 +8929,18 @@
 {
   // Get faced neighbor
   cOrganism * neighbor = m_organism->GetNeighbor();
-  if (neighbor != NULL) { 
+  if (neighbor != NULL) {
 		const int raw_mat_reg = FindModifiedRegister(REG_AX);
-		GetRegister(raw_mat_reg) = neighbor->GetReputation();	
-	} 
+		GetRegister(raw_mat_reg) = neighbor->GetReputation();
+	}
   return true;
 }
 
 
-/*! An organism's reputation is stored as an opinion. This instruction 
+/*! An organism's reputation is stored as an opinion. This instruction
  uses Inst_GetOpinion to do the heavy lifting, but includes
- default behavior suitable for reputations. Specifically, if an 
- organism has no reputation (i.e., it has not donated), then this 
+ default behavior suitable for reputations. Specifically, if an
+ organism has no reputation (i.e., it has not donated), then this
  instruction puts zeros into the registers.
  */
 bool cHardwareCPU::Inst_GetReputation(cAvidaContext& ctx)
@@ -8740,11 +8971,11 @@
 
 
 /* Rotate to face the organism with the highest reputation */
-bool cHardwareCPU::Inst_RotateToGreatestReputation(cAvidaContext& ctx) 
+bool cHardwareCPU::Inst_RotateToGreatestReputation(cAvidaContext& ctx)
 {
 	m_organism->GetOrgInterface().RotateToGreatestReputation();
-	
-	return true;	
+
+	return true;
 }
 
 /* Rotate to face the organism with the highest reputation that has
@@ -8752,7 +8983,7 @@
 bool cHardwareCPU::Inst_RotateToGreatestReputationWithDifferentTag(cAvidaContext& ctx)
 {
 	m_organism->GetOrgInterface().RotateToGreatestReputationWithDifferentTag(m_organism->GetTagLabel());
-	return true;	
+	return true;
 }
 
 /* Rotate to face the organism with the highest reputation that has
@@ -8760,13 +8991,13 @@
 bool cHardwareCPU::Inst_RotateToGreatestReputationWithDifferentLineage(cAvidaContext& ctx)
 {
 	m_organism->GetOrgInterface().RotateToGreatestReputationWithDifferentLineage(m_organism->GetLineageLabel());
-	return true;	
+	return true;
 }
 
 
 /* Rotate to face the organism with the highest reputation and then
  immediately donate */
-bool cHardwareCPU::Inst_RotateToGreatestReputationAndDonate(cAvidaContext& ctx) 
+bool cHardwareCPU::Inst_RotateToGreatestReputationAndDonate(cAvidaContext& ctx)
 {
 	Inst_RotateToGreatestReputation(ctx);
 	Inst_DonateFacingRawMaterials(ctx);
@@ -8780,44 +9011,44 @@
 {
 	//get the neighborhood size
   const int num_neighbors = m_organism->GetNeighborhoodSize();
-	
+
   // Turn to face a random neighbor
   int neighbor_id = ctx.GetRandom().GetInt(num_neighbors);
   for (int i = 0; i < neighbor_id; i++) m_organism->Rotate(1);
   cOrganism * neighbor = m_organism->GetNeighbor();
-	
+
   int max_id = neighbor_id + num_neighbors;
-	
+
   //we have not found a match yet
   bool found = false;
-	
-  // rotate through orgs in neighborhood  
+
+  // rotate through orgs in neighborhood
   while (neighbor_id < max_id) {
 		neighbor = m_organism->GetNeighbor();
-		
+
 		//if neighbor exists, do they have a different tag?
 		if (neighbor != NULL) {
 			if (m_organism->GetTagLabel() != neighbor->GetTagLabel()) found = true;
-			
+
 		}
-		
+
 		// stop searching through the neighbors if we already found one
 		if (found == true){
 			break;
 		}
-		
+
 		m_organism->Rotate(1);
 		neighbor_id++;
 	}
-	
+
 	return true;
 }
 
 
 
 
-/* Execute the next instruction if the neighbor was a donor. */ 
-bool cHardwareCPU::Inst_IfDonor(cAvidaContext& ctx) 
+/* Execute the next instruction if the neighbor was a donor. */
+bool cHardwareCPU::Inst_IfDonor(cAvidaContext& ctx)
 {
 	bool donor = false;
 	cOrganism * neighbor = m_organism->GetNeighbor();
@@ -8828,16 +9059,16 @@
 		}
 	}
   if (!donor)  IP().Advance();
-	
-  return true; 
-	
+
+  return true;
+
 }
 
 
-void cHardwareCPU::ComputeReputation() 
+void cHardwareCPU::ComputeReputation()
 {
 	cOrganism * neighbor = m_organism->GetNeighbor();
-	
+
 	// update reputation to include this donation.
 	// get the current reputation; increment by 1.
 	// includes a concept of standing
@@ -8845,7 +9076,7 @@
 		int my_rep = m_organism->GetReputation();
 		m_organism->SetReputation(my_rep +1);
 		// get neighbor reputation
-		int rep = neighbor->GetReputation(); 
+		int rep = neighbor->GetReputation();
 		// if the organism has not yet donated, put it into bad standing
 		if (rep == 0) neighbor->SetReputation(-1);
 	} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 2) {
@@ -8853,75 +9084,75 @@
 		int my_rep = m_organism->GetReputation();
 		m_organism->SetReputation(my_rep +1);
 		// get neighbor reputation
-		int rep = neighbor->GetReputation(); 
+		int rep = neighbor->GetReputation();
 		neighbor->SetReputation(rep-1);
 	} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 3)  {
 		// set rep to 1, since the organism donated
 		m_organism->SetReputation(1);
 		// get neighbor reputation
-		int rep = neighbor->GetReputation(); 
+		int rep = neighbor->GetReputation();
 		// if the organism has not yet donated, put it into bad standing
-		if (rep == 0) neighbor->SetReputation(-1);		
+		if (rep == 0) neighbor->SetReputation(-1);
 	} else if (m_world->GetConfig().AUTO_REPUTATION.Get() == 4) {
 		// Similar to 1, except does not include standing.
 		int my_rep = m_organism->GetReputation();
 		m_organism->SetReputation(my_rep +1);
 	}
-	
+
 }
 
 
 
 
-/* Check if the string in the organisms buffer corresponds to the 
- string it is producing. If so, -1 out the buffer and increment the 
+/* Check if the string in the organisms buffer corresponds to the
+ string it is producing. If so, -1 out the buffer and increment the
  number of raw materials the organism has. Otherwise, do nothing. */
 bool cHardwareCPU::Inst_ProduceString(cAvidaContext& ctx)
 {
-	
+
 	int num = 0;
-	int max_num = 0; 
+	int max_num = 0;
 	int max_string = -1;
 	int string_size = 0;
-	bool val; 
-	
-	m_organism->InitStringMap(); 
-	
-	// Figure out if it has produced any of the strings 
-	std::vector < cString > temp_strings = m_world->GetEnvironment().GetMatchStringsFromTask(); 
+	bool val;
+
+	m_organism->InitStringMap();
+
+	// Figure out if it has produced any of the strings
+	std::vector < cString > temp_strings = m_world->GetEnvironment().GetMatchStringsFromTask();
 	if (temp_strings.size()) string_size = temp_strings[0].GetSize();
 	for (unsigned int i=0; i < temp_strings.size(); i++){
-		num = m_organism->MatchOutputBuffer(temp_strings[i]); 
-		if (num > max_num) { 
-			max_num = num; 
-			max_string = i; 
+		num = m_organism->MatchOutputBuffer(temp_strings[i]);
+		if (num > max_num) {
+			max_num = num;
+			max_string = i;
 		}
 	}
-	
-	// Determine if it has to produce one in particular. 
-	if (m_world->GetConfig().SPECIALISTS.Get()) { 
-		if (m_organism->GetLineageLabel() != max_string) { 
+
+	// Determine if it has to produce one in particular.
+	if (m_world->GetConfig().SPECIALISTS.Get()) {
+		if (m_organism->GetLineageLabel() != max_string) {
 			max_num = 0;
 		}
 	}
-	
-	
+
+
 	// If still ok, add the raw material and clear the buffer
-	if (max_num == string_size) { 
+	if (max_num == string_size) {
 		// Indicate organism has produced the string
-		val = m_organism->ProduceString(max_string); 
-		
-		// temp until old code is phased out: 
-		m_organism->AddSelfRawMaterials(1); 
-		
+		val = m_organism->ProduceString(max_string);
+
+		// temp until old code is phased out:
+		m_organism->AddSelfRawMaterials(1);
+
 		// Clear buffer if the organism has received credit for the string
-		if (val) m_organism->SetOutputNegative1(); 
+		if (val) m_organism->SetOutputNegative1();
 	}
-	
+
 	return true;
 }
 
-//! An organism joins a group by setting it opinion to the group id. 
+//! An organism joins a group by setting it opinion to the group id.
 bool cHardwareCPU::Inst_JoinGroup(cAvidaContext& ctx)
 {
 	int opinion;
@@ -8932,18 +9163,18 @@
 		// subtract org from group
 		m_world->GetPopulation().LeaveGroup(opinion);
   }
-	
-	
+
+
 	// Call the set opinion instruction, which does all the dirty work.
 	Inst_SetOpinion(ctx);
-	
+
 	// Add org to group count
-	opinion = m_organism->GetOpinion().first;	
+	opinion = m_organism->GetOpinion().first;
 	m_world->GetPopulation().JoinGroup(opinion);
 	return true;
 }
 
-//! Gets the number of organisms in the current organism's group 
+//! Gets the number of organisms in the current organism's group
 //! and places the value in the ?CX? register
 bool cHardwareCPU::Inst_NumberOrgsInGroup(cAvidaContext& ctx)
 {
@@ -8951,7 +9182,7 @@
 	assert(m_organism != 0);
 	const int num_org_reg = FindModifiedRegister(REG_CX);
 	int opinion;
-	
+
   if(m_organism->HasOpinion()) {
 		opinion = m_organism->GetOpinion().first;
 		num_orgs = m_world->GetPopulation().NumberOfOrganismsInGroup(opinion);

Added: branches/topology-manager/source/main/cDemeInterface.h
===================================================================
--- branches/topology-manager/source/main/cDemeInterface.h	                        (rev 0)
+++ branches/topology-manager/source/main/cDemeInterface.h	2009-06-10 17:57:13 UTC (rev 3308)
@@ -0,0 +1,119 @@
+/*
+ *  cDemeInterface.h
+ *  Avida
+ *
+ *  Created by Anu on 6/9/08.
+ *  Copyright 1999-2009 Michigan State University. All rights reserved.
+ *
+ *
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public License
+ *  as published by the Free Software Foundation; version 2
+ *  of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ */
+
+// This class is responsible for establishing the interface that links an
+// organism back to its population.  It is a base class that is derived in:
+//
+//   cpu/cTestCPUInterface.{h,cc}      - Test CPU interface
+//   main/cPopulationInterface.{h,cc}  - Main population interface.
+//
+// Make sure that any new function you implment here also has versions in
+// those classes.
+
+#ifndef cDemeInterface_h
+#define cDemeInterface_h
+
+class cAvidaContext;
+class cCodeLabel;
+class cDeme;
+class cGenome;
+class cMetaGenome;
+class cOrganism;
+class cOrgMessage;
+class cOrgSinkMessage;
+template <class T> class tArray;
+
+
+class cDemeInterface
+{
+private:
+  cDemeInterface(const cDemeInterface&); // @not_implemented
+  cDemeInterface& operator=(const cDemeInterface&); // @not_implemented
+
+public:
+  cDemeInterface() { ; }
+  virtual ~cDemeInterface() { ; }
+
+  virtual int GetCellID() = 0;
+  virtual int GetDemeID() = 0;
+  virtual cDeme* GetDeme() = 0;
+  virtual void SetCellID(int in_id) = 0;
+  virtual void SetDemeID(int in_id) = 0;
+
+  virtual int GetCellData() = 0;
+  virtual void SetCellData(const int newData) = 0;
+
+  virtual int GetPrevSeenCellID() = 0;
+  virtual int GetPrevTaskCellID() = 0;
+  virtual int GetNumTaskCellsReached() = 0;
+  virtual void AddReachedTaskCell() = 0;
+  virtual void SetPrevSeenCellID(int in_id) = 0;
+  virtual void SetPrevTaskCellID(int in_id) = 0;
+
+  virtual bool Divide(cAvidaContext& ctx, cOrganism* parent, const cMetaGenome& offspring_genome) = 0;
+
+  virtual cOrganism* GetNeighbor() = 0;
+  virtual bool IsNeighborCellOccupied() = 0;
+  virtual int GetNumNeighbors() = 0;
+  virtual void GetNeighborhoodCellIDs(tArray<int>& list) = 0;
+  virtual int GetFacing() = 0; //!< Returns the facing of this organism.
+  virtual int GetNeighborCellContents() = 0;
+  virtual void Rotate(int direction = 1) = 0;
+
+  virtual void Breakpoint() = 0;
+
+  virtual int GetInputAt(int& input_pointer) = 0;
+  virtual void ResetInputs(cAvidaContext& ctx) = 0;
+  virtual const tArray<int>& GetInputs() const = 0;
+  virtual int Debug() = 0;
+  virtual const tArray<double>& GetResources() = 0;
+  virtual const tArray<double>& GetDemeResources(int deme_id) = 0;
+  virtual const tArray< tArray<int> >& GetCellIdLists() = 0;
+  virtual void UpdateResources(const tArray<double>& res_change) = 0;
+  virtual void UpdateDemeResources(const tArray<double>& res_change) = 0;
+  virtual void Die() = 0;
+  virtual void Kaboom(int distance) = 0;
+  virtual void SpawnDeme() = 0;
+  virtual cOrgSinkMessage* NetReceive() = 0;
+  virtual bool NetRemoteValidate(cAvidaContext& ctx, cOrgSinkMessage* msg) = 0;
+  virtual int ReceiveValue() = 0;
+  virtual void SellValue(const int data, const int label, const int sell_price, const int org_id) = 0;
+  virtual int BuyValue(const int label, const int buy_price) = 0;
+  virtual bool InjectParasite(cOrganism* parent, const cCodeLabel& label, const cGenome& injected_code) = 0;
+  virtual bool UpdateMerit(double new_merit) = 0;
+  virtual bool TestOnDivide() = 0;
+  virtual bool SendMessage(cOrgMessage& msg) = 0;
+	virtual bool BroadcastMessage(cOrgMessage& msg, int depth) = 0;
+  virtual bool BcastAlarm(int jump_jabel, int bcast_range) = 0;
+  virtual void DivideOrgTestamentAmongDeme(double value) = 0;
+	virtual void SendFlash() = 0;
+
+  virtual int GetStateGridID(cAvidaContext& ctx) = 0;
+	virtual void RotateToGreatestReputation() =0;
+	virtual void RotateToGreatestReputationWithDifferentTag(int tag) =0;
+	virtual void RotateToGreatestReputationWithDifferentLineage(int line) =0;
+
+};
+
+#endif

Modified: branches/topology-manager/source/main/cPopulationInterface.h
===================================================================
--- branches/topology-manager/source/main/cPopulationInterface.h	2009-06-10 13:57:47 UTC (rev 3307)
+++ branches/topology-manager/source/main/cPopulationInterface.h	2009-06-10 17:57:13 UTC (rev 3308)
@@ -41,7 +41,7 @@
 class cOrgMessage;
 
 
-class cPopulationInterface : public cOrgInterface
+class cPopulationInterface : public cOrgInterface, cDemeInterface
 {
 private:
   cWorld* m_world;
@@ -55,7 +55,7 @@
   cPopulationInterface(); // @not_implemented
   cPopulationInterface(const cPopulationInterface&); // @not_implemented
   cPopulationInterface operator=(const cPopulationInterface&); // @not_implemented
-  
+
 public:
   cPopulationInterface(cWorld* world) : m_world(world), m_cell_id(-1), m_deme_id(-1) { ; }
   virtual ~cPopulationInterface() { ; }
@@ -65,7 +65,7 @@
   cDeme* GetDeme();
   void SetCellID(int in_id) { m_cell_id = in_id; }
   void SetDemeID(int in_id) { m_deme_id = in_id; }
-  
+
   int GetCellData();
   void SetCellData(const int newData);
 
@@ -109,17 +109,17 @@
   bool SendMessage(cOrgMessage& msg);
   bool SendMessage(cOrganism* recvr, cOrgMessage& msg);
   bool BroadcastMessage(cOrgMessage& msg, int depth);
-  bool BcastAlarm(int jump_label, int bcast_range);  
+  bool BcastAlarm(int jump_label, int bcast_range);
   void DivideOrgTestamentAmongDeme(double value);
 	//! Send a flash to all neighboring organisms.
   void SendFlash();
 
   int GetStateGridID(cAvidaContext& ctx);
-	
+
 	// Reputation
 	void RotateToGreatestReputation();
 	void RotateToGreatestReputationWithDifferentTag(int tag);
-	void RotateToGreatestReputationWithDifferentLineage(int line);	
+	void RotateToGreatestReputationWithDifferentLineage(int line);
 };
 
 
@@ -132,6 +132,6 @@
    **/
   void UnitTests(bool full = false);
 }
-#endif  
+#endif
 
 #endif




More information about the Avida-cvs mailing list