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. This version ignores the neighbors beind the organism, i.e. the cells directly behind and behind and to the left and right.
| 8947 | // facing. This version ignores the neighbors beind the organism, i.e. |
| 8948 | // the cells directly behind and behind and to the left and right. |
| 8949 | bool cHardwareCPU::Inst_MoveTargetForward5(cAvidaContext& ctx) |
| 8950 | { |
| 8951 | int num_rotations = 0; |
| 8952 | |
| 8953 | cPopulation& pop = m_world->GetPopulation(); |
| 8954 | int cellid = m_organism->GetCellID(); |
| 8955 | |
| 8956 | if (cellid == -1) { |
| 8957 | return false; |
| 8958 | } |
| 8959 | |
| 8960 | cPopulationCell& mycell = pop.GetCell(cellid); |
| 8961 | |
| 8962 | int cell_data; |
| 8963 | |
| 8964 | cPopulationCell faced = mycell.GetCellFaced(); |
| 8965 | |
| 8966 | // Find if any neighbor is a target |
| 8967 | for (int i = 0; i < mycell.ConnectionList().GetSize(); i++) { |
| 8968 | |
| 8969 | // Skip the cells behind |
| 8970 | if (i == 3 || i == 4 || i == 5) { |
| 8971 | mycell.ConnectionList().CircNext(); |
| 8972 | continue; |
| 8973 | } |
| 8974 | |
| 8975 | cell_data = mycell.GetCellFaced().GetCellData(); |
| 8976 | |
| 8977 | if (cell_data > 0) { |
| 8978 | num_rotations = i; |
| 8979 | } |
| 8980 | |
| 8981 | mycell.ConnectionList().CircNext(); |
| 8982 | } |
| 8983 | |
| 8984 | // Rotate until we face the neighbor with a target. |
| 8985 | // If there was no winner, just move forward. |
| 8986 | for (int i = 0; i < num_rotations; i++) { |
| 8987 | mycell.ConnectionList().CircNext(); |
| 8988 | } |
| 8989 | |
| 8990 | m_organism->Move(ctx); |
| 8991 | |
| 8992 | return true; |
| 8993 | } // End Inst_MoveTargetForward5() |
| 8994 | |
| 8995 | |
| 8996 | // This command should move the organism to the neighbor cell that is a |
nothing calls this directly
no test coverage detected