[Avida-SVN] r2886 - in branches/hjg-dev/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Mon Oct 27 09:54:45 PDT 2008
Author: hjg
Date: 2008-10-27 12:54:45 -0400 (Mon, 27 Oct 2008)
New Revision: 2886
Modified:
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/main/cPopulationInterface.cc
Log:
bug fix
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-27 15:38:47 UTC (rev 2885)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-27 16:54:45 UTC (rev 2886)
@@ -6950,3 +6950,5 @@
Inst_DonateFacingRawMaterials(ctx);
return true;
}
+
+
Modified: branches/hjg-dev/source/main/cPopulationInterface.cc
===================================================================
--- branches/hjg-dev/source/main/cPopulationInterface.cc 2008-10-27 15:38:47 UTC (rev 2885)
+++ branches/hjg-dev/source/main/cPopulationInterface.cc 2008-10-27 16:54:45 UTC (rev 2886)
@@ -342,8 +342,10 @@
{
cPopulationCell& cell = m_world->GetPopulation().GetCell(GetCellID());
- int high_rep=-1, k=0;
+ int high_rep=-1;
+ vector <int> high_rep_orgs;
+
// loop to find the max reputation
for(int i=0; i<cell.ConnectionList().GetSize(); ++i) {
const cPopulationCell* faced_cell = cell.ConnectionList().GetFirst();
@@ -352,18 +354,44 @@
cOrganism* cur_neighbor = faced_cell->GetOrganism();
// if it has high reputation
- if (cur_neighbor->GetReputation() > high_rep) {
- high_rep = cur_neighbor->GetReputation();
- k=i;
- }
+ if (cur_neighbor->GetReputation() >= high_rep) {
+ if (cur_neighbor->GetReputation() > high_rep) {
+ high_rep = cur_neighbor->GetReputation();
+ high_rep_orgs.clear();
+ }
+ high_rep_orgs.push_back(cur_neighbor->GetID());
+ }
}
+ // check the next neighbor
+ cell.ConnectionList().CircNext();
}
+
+ // Pick an organism to donate to
- // loop to face the max reputation
- for (int i=0; i<k; i++) {
- cell.ConnectionList().CircNext(); // or right...
-// int test_rep = cell.ConnectionList().GetFirst()->GetOrganism()->GetReputation();
- }
+ if (high_rep_orgs.size() > 0) {
+ unsigned int rand_num = m_world->GetRandom().GetUInt(0, high_rep_orgs.size());
+ int high_org_id = high_rep_orgs[rand_num];
+ for(int i=0; i<cell.ConnectionList().GetSize(); ++i) {
+ const cPopulationCell* faced_cell = cell.ConnectionList().GetFirst();
+
+ if (IsNeighborCellOccupied()) {
+
+ cOrganism* cur_neighbor = faced_cell->GetOrganism();
+ // int test_rep = cell.ConnectionList().GetFirst()->GetOrganism()->GetReputation();
+
+ // if it has high reputation
+ if (cur_neighbor->GetID() == high_org_id) {
+ int test_id = cur_neighbor->GetID();
+ int test_rep = cur_neighbor->GetReputation();
+ break;
+ }
+ }
+
+ cell.ConnectionList().CircNext();
+
+ }
+ }
+
}
More information about the Avida-cvs
mailing list