[Avida-SVN] r1045 - in branches/coopcomm: Avida.xcodeproj source/cpu source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Fri Oct 13 06:16:46 PDT 2006


Author: beckma24
Date: 2006-10-13 09:16:45 -0400 (Fri, 13 Oct 2006)
New Revision: 1045

Modified:
   branches/coopcomm/Avida.xcodeproj/project.pbxproj
   branches/coopcomm/source/cpu/cHardwareCPU.cc
   branches/coopcomm/source/cpu/cHardwareCPU.h
   branches/coopcomm/source/main/cOrganism.h
   branches/coopcomm/source/main/cPopulationCell.cc
Log:
Reimplemented get-facing with gray codes, added rotate-value and retrieve-msg-0-0 instructions

Modified: branches/coopcomm/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/coopcomm/Avida.xcodeproj/project.pbxproj	2006-10-13 00:07:41 UTC (rev 1044)
+++ branches/coopcomm/Avida.xcodeproj/project.pbxproj	2006-10-13 13:16:45 UTC (rev 1045)
@@ -360,6 +360,23 @@
 		E626209E0A372C2A00C07685 /* SaveLoadActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 708051A80A1F65FE00CBB8B6 /* SaveLoadActions.cc */; };
 /* End PBXBuildFile section */
 
+/* Begin PBXBuildStyle section */
+		B5B24AE30ADD50AE0045FB66 /* Development */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+			};
+			name = Development;
+		};
+		B5B24AE40ADD50AE0045FB66 /* Deployment */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+			};
+			name = Deployment;
+		};
+/* End PBXBuildStyle section */
+
 /* Begin PBXCopyFilesBuildPhase section */
 		700E2B6D085DE50C00CF158A /* CopyFiles */ = {
 			isa = PBXCopyFilesBuildPhase;
@@ -1745,6 +1762,12 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
+			buildSettings = {
+			};
+			buildStyles = (
+				B5B24AE30ADD50AE0045FB66 /* Development */,
+				B5B24AE40ADD50AE0045FB66 /* Deployment */,
+			);
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;

Modified: branches/coopcomm/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/coopcomm/source/cpu/cHardwareCPU.cc	2006-10-13 00:07:41 UTC (rev 1044)
+++ branches/coopcomm/source/cpu/cHardwareCPU.cc	2006-10-13 13:16:45 UTC (rev 1045)
@@ -227,6 +227,7 @@
     
     cInstEntryCPU("rotate-l",  &cHardwareCPU::Inst_RotateL),
     cInstEntryCPU("rotate-r",  &cHardwareCPU::Inst_RotateR),
+    cInstEntryCPU("rotate-value", &cHardwareCPU::Inst_RotateValue),
     
     cInstEntryCPU("set-cmut",  &cHardwareCPU::Inst_SetCopyMut),
     cInstEntryCPU("mod-cmut",  &cHardwareCPU::Inst_ModCopyMut),
@@ -353,7 +354,8 @@
     
     // Coop-comm
     cInstEntryCPU("send-msg", &cHardwareCPU::Inst_SendMessage),
-    cInstEntryCPU("retrieve-msg", &cHardwareCPU::Inst_ReceiveMessage),
+    cInstEntryCPU("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
+    cInstEntryCPU("retrieve-msg-0-0", &cHardwareCPU::Inst_RetrieveMessage_0_0),
     cInstEntryCPU("get-id", &cHardwareCPU::Inst_GetID),
     cInstEntryCPU("get-pos", &cHardwareCPU::Inst_GetPosition),
     cInstEntryCPU("get-facing", &cHardwareCPU::Inst_GetFacing),
@@ -2986,6 +2988,29 @@
   return true;
 }
 
+/** Written by: Ben Beckmann
+  Read ?BX? and rotate left or right by the number stored in the register.
+  Positive ?BX? value = rotate right
+  Negative ?BX? value = rotate left
+*/
+bool cHardwareCPU::Inst_RotateValue(cAvidaContext& ctx) {
+  int neighborhoodSize = organism->GetNeighborhoodSize();
+  const int num_rotate_reg = FindModifiedRegister(REG_BX);
+  int total_rotate = GetRegister(num_rotate_reg);
+  int actual_rotate;
+  
+  if(total_rotate > 0) { //rotate right
+    actual_rotate = total_rotate % neighborhoodSize;
+    for(int i = 0; i < actual_rotate; i++)
+      organism->Rotate(1);
+  } else if(total_rotate < 0) { //rotate left
+    actual_rotate = neighborhoodSize - (total_rotate % neighborhoodSize);
+    for(int i = 0; i < actual_rotate; i++)
+      organism->Rotate(-1);  
+  } //else num_rotate = 0 so don't rotate.
+  return true;
+}
+
 bool cHardwareCPU::Inst_SetCopyMut(cAvidaContext& ctx)
 {
   const int reg_used = FindModifiedRegister(REG_BX);
@@ -3397,7 +3422,7 @@
 Note that though this instruction is named "receive," the act of bringing a 
 message into the CPU is termed "retrieving a message."
 */
-bool cHardwareCPU::Inst_ReceiveMessage(cAvidaContext& ctx) 
+bool cHardwareCPU::Inst_RetrieveMessage(cAvidaContext& ctx) 
 {
   const cOrgMessage* msg = organism->RetrieveMessage();
   if(msg==NULL)
@@ -3412,6 +3437,28 @@
 }
 
 
+/*!  Tests show this version of RetieveMessage works as well as the other one,
+     and allows for organisms to tell when it has failed.
+*/
+bool cHardwareCPU::Inst_RetrieveMessage_0_0(cAvidaContext& ctx)
+{
+  const cOrgMessage* msg = organism->RetrieveMessage();
+  const int label_reg = FindModifiedRegister(REG_BX);
+  const int data_reg = FindNextRegister(label_reg);
+  
+  if(msg==NULL) { // not message to retrieve so registers are set to 0.
+    GetRegister(label_reg) = 0;
+    GetRegister(data_reg) = 0;  
+    return false;
+  } 
+  //else set register values
+  GetRegister(label_reg) = msg->GetLabel();
+  GetRegister(data_reg) = msg->GetData();
+  return true;
+}
+
+
+
 /*! Places this organism's random-cell-id in register ?BX?.
 */
 bool cHardwareCPU::Inst_GetID(cAvidaContext& ctx) {
@@ -3431,16 +3478,16 @@
 }
 
 /*! Places the facing of this organism into the ?BX? register.
-Note that facing is a number from -4..3, where the following represent the 
+Note that facing is a interger representation of a gray code value, where the following represent the 
 cardinal directions:
-3 = NE
-2 = E
-1 = SE
-0 = S
--1 = SW
--2 = W
--3 = NW
--4 = N
+111 = NE
+101 = E
+100 = SE
+000 = S
+001 = SW
+011 = W
+010 = NW
+110 = N
 */
 bool cHardwareCPU::Inst_GetFacing(cAvidaContext& ctx) {
 	const int facing = FindModifiedRegister(REG_BX);

Modified: branches/coopcomm/source/cpu/cHardwareCPU.h
===================================================================
--- branches/coopcomm/source/cpu/cHardwareCPU.h	2006-10-13 00:07:41 UTC (rev 1044)
+++ branches/coopcomm/source/cpu/cHardwareCPU.h	2006-10-13 13:16:45 UTC (rev 1045)
@@ -400,6 +400,7 @@
 
   bool Inst_RotateL(cAvidaContext& ctx);
   bool Inst_RotateR(cAvidaContext& ctx);
+  bool Inst_RotateValue(cAvidaContext& ctx);
   bool Inst_SetCopyMut(cAvidaContext& ctx);
   bool Inst_ModCopyMut(cAvidaContext& ctx);
 
@@ -473,7 +474,8 @@
   
   // Coop-comm
   bool Inst_SendMessage(cAvidaContext& ctx); //!< Send a message to the faced organism.
-  bool Inst_ReceiveMessage(cAvidaContext& ctx); //!< Receive a message.
+  bool Inst_RetrieveMessage(cAvidaContext& ctx); //!< Retrieve a message.
+  bool Inst_RetrieveMessage_0_0(cAvidaContext& ctx); //!< Retrieve a message and write 0,0 to regs if failed.
   bool Inst_GetID(cAvidaContext& ctx); //!< Retrieve this organism's ID.
   bool Inst_GetPosition(cAvidaContext& ctx); //!< Retrieve this organism's position.
   bool Inst_GetFacing(cAvidaContext& ctx); //!< Retrieve this organism's facing.

Modified: branches/coopcomm/source/main/cOrganism.h
===================================================================
--- branches/coopcomm/source/main/cOrganism.h	2006-10-13 00:07:41 UTC (rev 1044)
+++ branches/coopcomm/source/main/cOrganism.h	2006-10-13 13:16:45 UTC (rev 1045)
@@ -311,7 +311,7 @@
   void GetPosition(int& x, int& y) { assert(m_interface); m_interface->GetPosition(x, y); }
   //! Returns the facing of this organism.
   int GetFacing() { assert(m_interface); return m_interface->GetFacing(); }
-  //!
+  //! Returns Cell ID of last cell sent to.
   int getLastSent(){ return last_cell_sent_to; }
   //! Set the leader of this organism to the organism currently faced.
   bool SetLeader();

Modified: branches/coopcomm/source/main/cPopulationCell.cc
===================================================================
--- branches/coopcomm/source/main/cPopulationCell.cc	2006-10-13 00:07:41 UTC (rev 1044)
+++ branches/coopcomm/source/main/cPopulationCell.cc	2006-10-13 13:16:45 UTC (rev 1045)
@@ -179,7 +179,14 @@
 }
 
 /*! These values are chosen so as to make loops on the facing 'easy'.
-S=0, SW=-1, W=-2, NW=-3, N=-4, NE=3, E=2, SE=1.
+111 = NE
+101 = E
+100 = SE
+000 = S
+001 = SW
+011 = W
+010 = NW
+110 = N
 
 Facing is determined by the relative positions of this cell and the cell that 
 is currently faced. Note that we cannot differentiate between directions on a 2x2 
@@ -205,13 +212,13 @@
   
 	// This is hackish.
 	if(lr==0 && du==-1) return 0; //S
-	if(lr==-1 && du==-1) return -1; //SW
-	if(lr==-1 && du==0) return -2; //W
-	if(lr==-1 && du==1) return -3; //NW
-	if(lr==0 && du==1) return -4; //N
-	if(lr==1 && du==1) return 3; //NE
-	if(lr==1 && du==0) return 2; //E
-	if(lr==1 && du==-1) return 1; //SE
+	if(lr==-1 && du==-1) return 1; //SW
+	if(lr==-1 && du==0) return 3; //W
+	if(lr==-1 && du==1) return 2; //NW
+	if(lr==0 && du==1) return 6; //N
+	if(lr==1 && du==1) return 7; //NE
+	if(lr==1 && du==0) return 5; //E
+	if(lr==1 && du==-1) return 4; //SE
   
 	assert(false);
 }




More information about the Avida-cvs mailing list