Skip to content

fix detachments #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

drbergman
Copy link
Collaborator

  • PR disallow random detachment from attack #340 put the correct check in the wrong place to prevent detachment when a cell is attacking another cell. This fixes that by first moving the check into the spring attachments function as an attack produces a spring attachment. Second, it moves the check into the detachment block rather than the attachment block.

  • also, fix bug iterating over the attached cells. when detaching cells, the for loop would skip checking the last cell in the list if any cells were detached. So, instead iterate backwards through the list of attached cells.

Here's a movie showing that the cells remain attached throughout the attack despite the high detach rate of the defender cell:

fix_attack_detach.mp4

- PR MathCancer#340 put the correct check in the wrong place to prevent detachment when a cell is attacking another cell.
This fixes that by first moving the check into the spring attachments function as an attack produces a spring attachment.
Second, it moves the check into the detachment block rather than the attachment block.

- also, fix bug iterating over the attached cells.
when detaching cells, the for loop would skip checking the last cell in the list if any cells were detached.
So, instead iterate backwards through the list of attached cells.
@@ -1441,8 +1442,6 @@ void dynamic_attachments( Cell* pCell , Phenotype& phenotype, double dt )
while( done == false && j < pCell->state.neighbors.size() )
{
Cell* pTest = pCell->state.neighbors[j];
if (phenotype.cell_interactions.pAttackTarget==pTest || pTest->phenotype.cell_interactions.pAttackTarget==pCell) // do not let attackers detach randomly
{ continue; }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the right check, but in the wrong place

Cell* pTest = pCell->state.spring_attachments[j];
Cell* pTest = pCell->state.spring_attachments[j];
if (phenotype.cell_interactions.pAttackTarget==pTest || pTest->phenotype.cell_interactions.pAttackTarget==pCell) // do not let attackers detach randomly
{ continue; }
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check in the correct place

@drbergman drbergman requested a review from Copilot May 14, 2025 00:25
Copilot

This comment was marked as resolved.

@drbergman drbergman self-assigned this May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant