[Avida-SVN] r2851 - in branches/hjg-dev/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Wed Oct 15 21:16:56 PDT 2008
Author: hjg
Date: 2008-10-16 00:16:56 -0400 (Thu, 16 Oct 2008)
New Revision: 2851
Modified:
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/cpu/cHardwareCPU.h
branches/hjg-dev/source/cpu/cTestCPUInterface.h
branches/hjg-dev/source/main/cOrgInterface.h
branches/hjg-dev/source/main/cPopulationInterface.cc
branches/hjg-dev/source/main/cPopulationInterface.h
Log:
new rotate to face greatest reputation instruction
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-16 00:08:39 UTC (rev 2850)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-16 04:16:56 UTC (rev 2851)
@@ -19,7 +19,7 @@
*
* 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.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
@@ -462,6 +462,8 @@
tInstLibEntry<tMethod>("praise-neighbor", &cHardwareCPU::Inst_PraiseNeighbor, nInstFlag::STALL),
tInstLibEntry<tMethod>("inc-recip", &cHardwareCPU::Inst_IncRecipProb, nInstFlag::STALL),
tInstLibEntry<tMethod>("dec-recip", &cHardwareCPU::Inst_DecRecipProb, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("rotate-to-rep", &cHardwareCPU::Inst_RotateToGreatestReputation, nInstFlag::STALL),
+
// Must always be the last instruction in the array
@@ -6863,7 +6865,7 @@
{
cOrganism * neighbor = organism->GetNeighbor();
if (neighbor == NULL) return true;
-
+
// improve neighbor reputation
if (neighbor->HasOpinion()) {
int opinion = neighbor->GetOpinion().first + 1;
@@ -6889,4 +6891,10 @@
return true;
}
-
+// move guts to organism interface.
+bool cHardwareCPU::Inst_RotateToGreatestReputation(cAvidaContext& ctx)
+{
+ organism->GetOrgInterface().RotateToGreatestReputation();
+
+ return true;
+}
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-16 00:08:39 UTC (rev 2850)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-16 04:16:56 UTC (rev 2851)
@@ -696,8 +696,10 @@
bool Inst_IncRecipProb(cAvidaContext& ctx);
// Decrease the reciprocation probability
bool Inst_DecRecipProb(cAvidaContext& ctx);
-
+ // Rotate to the organims with the greatest reputation
+ bool Inst_RotateToGreatestReputation(cAvidaContext& ctx);
+
};
Modified: branches/hjg-dev/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/hjg-dev/source/cpu/cTestCPUInterface.h 2008-10-16 00:08:39 UTC (rev 2850)
+++ branches/hjg-dev/source/cpu/cTestCPUInterface.h 2008-10-16 04:16:56 UTC (rev 2851)
@@ -92,6 +92,8 @@
bool BcastAlarm(int jump_label, int bcast_range) { return false; }
void DivideOrgTestamentAmongDeme(double value) {;}
+
+ void RotateToGreatestReputation(){ }
};
Modified: branches/hjg-dev/source/main/cOrgInterface.h
===================================================================
--- branches/hjg-dev/source/main/cOrgInterface.h 2008-10-16 00:08:39 UTC (rev 2850)
+++ branches/hjg-dev/source/main/cOrgInterface.h 2008-10-16 04:16:56 UTC (rev 2851)
@@ -102,6 +102,8 @@
virtual bool BcastAlarm(int jump_jabel, int bcast_range) = 0;
virtual void DivideOrgTestamentAmongDeme(double value) = 0;
+ virtual void RotateToGreatestReputation() =0;
+
};
#endif
Modified: branches/hjg-dev/source/main/cPopulationInterface.cc
===================================================================
--- branches/hjg-dev/source/main/cPopulationInterface.cc 2008-10-16 00:08:39 UTC (rev 2850)
+++ branches/hjg-dev/source/main/cPopulationInterface.cc 2008-10-16 04:16:56 UTC (rev 2851)
@@ -335,3 +335,34 @@
}
}
}
+
+
+/* Rotate an organism to face the neighbor with the highest reputation */
+void cPopulationInterface::RotateToGreatestReputation()
+{
+
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(GetCellID());
+ int high_rep=-1, k=0;
+
+ // loop to find the max reputation
+ for(int i=0; i<cell.ConnectionList().GetSize(); ++i) {
+ const cPopulationCell* faced_cell = cell.ConnectionList().GetFirst();
+ // cell->organism, if occupied, check reputation, etc.
+ if (IsNeighborCellOccupied()) {
+ cOrganism* cur_neighbor = faced_cell->GetOrganism();
+
+ // if it has high reputation
+ if (cur_neighbor->GetReputation() > high_rep) {
+ high_rep = cur_neighbor->GetReputation();
+ k=i;
+ }
+ }
+
+ }
+
+ // loop to face the max reputation
+ for (int i=0; i<=k; i++) {
+ cell.ConnectionList().CircNext(); // or right...
+ }
+
+}
Modified: branches/hjg-dev/source/main/cPopulationInterface.h
===================================================================
--- branches/hjg-dev/source/main/cPopulationInterface.h 2008-10-16 00:08:39 UTC (rev 2850)
+++ branches/hjg-dev/source/main/cPopulationInterface.h 2008-10-16 04:16:56 UTC (rev 2851)
@@ -106,6 +106,9 @@
//! Send a message to the faced organism.
bool SendMessage(cOrgMessage& msg);
bool BcastAlarm(int jump_label, int bcast_range);
+
+ // Reputation
+ void RotateToGreatestReputation();
void DivideOrgTestamentAmongDeme(double value);
};
More information about the Avida-cvs
mailing list