This command should move the organism to the neighbor cell that is a target. If more than one target exists, it moves towards the last-seen one. If no target exists, the organism moves forward in its original facing.
| 8901 | // one. If no target exists, the organism moves forward in its original |
| 8902 | // facing. |
| 8903 | bool cHardwareCPU::Inst_MoveTarget(cAvidaContext& ctx) |
| 8904 | { |
| 8905 | int num_rotations = 0; |
| 8906 | |
| 8907 | cPopulation& pop = m_world->GetPopulation(); |
| 8908 | int cellid = m_organism->GetCellID(); |
| 8909 | |
| 8910 | if (cellid == -1) { |
| 8911 | return true; |
| 8912 | } |
| 8913 | |
| 8914 | cPopulationCell& mycell = pop.GetCell(cellid); |
| 8915 | |
| 8916 | int cell_data; |
| 8917 | |
| 8918 | cPopulationCell faced = mycell.GetCellFaced(); |
| 8919 | |
| 8920 | // Find if any neighbor is a target |
| 8921 | for (int i = 0; i < mycell.ConnectionList().GetSize(); i++) { |
| 8922 | cell_data = mycell.GetCellFaced().GetCellData(); |
| 8923 | |
| 8924 | if (cell_data > 0) { |
| 8925 | num_rotations = i; |
| 8926 | } |
| 8927 | |
| 8928 | mycell.ConnectionList().CircNext(); |
| 8929 | } |
| 8930 | |
| 8931 | // Rotate until we face the neighbor with a target. |
| 8932 | // If there was no winner, just move forward. |
| 8933 | for (int i = 0; i < num_rotations; i++) { |
| 8934 | mycell.ConnectionList().CircNext(); |
| 8935 | } |
| 8936 | |
| 8937 | m_organism->Move(ctx); |
| 8938 | |
| 8939 | return true; |
| 8940 | } // End Inst_MoveTarget() |
| 8941 | |
| 8942 | |
| 8943 |
nothing calls this directly
no test coverage detected