Class ParticleSystem
Main container for a system of particles in the grid together with the execution logic for simulating rounds.
Unlike other IReplayHistory implementations, the system will automatically reactivate the tracking state as soon as the marker is set to the latest round.
Inheritance
Implements
Namespace: AS2.Sim
Assembly: .dll
Syntax
public class ParticleSystem : IReplayHistory
Constructors
| Edit this page View SourceParticleSystem(AmoebotSimulator, RenderSystem)
Declaration
public ParticleSystem(AmoebotSimulator sim, RenderSystem renderSystem)
Parameters
Type | Name | Description |
---|---|---|
AmoebotSimulator | sim | |
RenderSystem | renderSystem |
Fields
| Edit this page View Source_currentRound
Declaration
private int _currentRound
Field Value
Type | Description |
---|---|
int |
_earliestRound
Declaration
private int _earliestRound
Field Value
Type | Description |
---|---|
int |
_latestRound
Declaration
private int _latestRound
Field Value
Type | Description |
---|---|
int |
_previousRound
Declaration
private int _previousRound
Field Value
Type | Description |
---|---|
int |
anchorIdxHistory
The history of the anchor particle's index.
Declaration
private ValueHistory<int> anchorIdxHistory
Field Value
Type | Description |
---|---|
ValueHistory<int> |
anchorInit
The index of the anchor particle selected in initialization mode.
-1
means that no anchor has been selected, in which case the
first particle on the list will become the anchor.
Declaration
private int anchorInit
Field Value
Type | Description |
---|---|
int |
anchorIsObjectHistory
The history of the flag telling whether the anchor index refers to an object.
Declaration
private ValueHistory<bool> anchorIsObjectHistory
Field Value
Type | Description |
---|---|
ValueHistory<bool> |
anchorIsObjectInit
Flag telling whether the anchor index belongs to an object in Init Mode.
Declaration
private bool anchorIsObjectInit
Field Value
Type | Description |
---|---|
bool |
beepFailureProb
Declaration
private float beepFailureProb
Field Value
Type | Description |
---|---|
float |
collisionCheckEnabled
Indicates whether the collision check should be executed.
Declaration
private bool collisionCheckEnabled
Field Value
Type | Description |
---|---|
bool |
collisionDebugLines
Declaration
private CollisionChecker.DebugLine[] collisionDebugLines
Field Value
Type | Description |
---|---|
DebugLine[] |
edgeMovements
Declaration
private List<EdgeMovement> edgeMovements
Field Value
Type | Description |
---|---|
List<EdgeMovement> |
finished
true
as soon as all particles are finished.
Declaration
private bool finished
Field Value
Type | Description |
---|---|
bool |
finishedRound
The first round in which all particles were finished.
Declaration
private int finishedRound
Field Value
Type | Description |
---|---|
int |
inBeepPhase
true
while in the beep phase during round simulation.
Declaration
private bool inBeepPhase
Field Value
Type | Description |
---|---|
bool |
inCollisionState
true
when a collision occurred in the last recorded round.
Declaration
private bool inCollisionState
Field Value
Type | Description |
---|---|
bool |
inInitializationState
Declaration
private bool inInitializationState
Field Value
Type | Description |
---|---|
bool |
inMovePhase
true
while in the move phase during round simulation.
Declaration
private bool inMovePhase
Field Value
Type | Description |
---|---|
bool |
isTracking
true
while tracking the latest simulation round.
Useful for IReplayHistory implementation.
Declaration
private bool isTracking
Field Value
Type | Description |
---|---|
bool |
objectMap
A map of the grid positions of all objects in the simulation. Similar to particleMap.
Declaration
private Dictionary<Vector2Int, ParticleObject> objectMap
Field Value
Type | Description |
---|---|
Dictionary<Vector2Int, ParticleObject> |
objectMapInit
Declaration
private Dictionary<Vector2Int, ParticleObject> objectMapInit
Field Value
Type | Description |
---|---|
Dictionary<Vector2Int, ParticleObject> |
objects
A list of all objects in the system. Similar to particles.
Declaration
private List<ParticleObject> objects
Field Value
Type | Description |
---|---|
List<ParticleObject> |
objectsInit
Declaration
private List<ParticleObject> objectsInit
Field Value
Type | Description |
---|---|
List<ParticleObject> |
particleMap
A map of the grid positions of all particles in the simulation.
The map is updated at the end of each round simulation or when jumping to a round in the history.
Declaration
private Dictionary<Vector2Int, Particle> particleMap
Field Value
Type | Description |
---|---|
Dictionary<Vector2Int, Particle> |
particleMapInit
Map of InitializationParticle posiitons, similar to particleMap for the initialization mode.
Declaration
private Dictionary<Vector2Int, OpenInitParticle> particleMapInit
Field Value
Type | Description |
---|---|
Dictionary<Vector2Int, OpenInitParticle> |
particles
A list of all particles in the simulation.
This list does not change during the simulation.
Declaration
public List<Particle> particles
Field Value
Type | Description |
---|---|
List<Particle> |
particlesInit
List of InitializationParticles, similar to particles for the initialization mode.
Declaration
private List<OpenInitParticle> particlesInit
Field Value
Type | Description |
---|---|
List<OpenInitParticle> |
renderSystem
The object responsible for rendering this particle system.
Declaration
public RenderSystem renderSystem
Field Value
Type | Description |
---|---|
RenderSystem |
selectedAlgorithm
The name of the selected algorithm in initialization mode.
Declaration
private string selectedAlgorithm
Field Value
Type | Description |
---|---|
string |
sim
The simulator object to which this system belongs.
Declaration
public AmoebotSimulator sim
Field Value
Type | Description |
---|---|
AmoebotSimulator |
storedSimulationRound
The round we were in when we stored the simulation state.
Declaration
private int storedSimulationRound
Field Value
Type | Description |
---|---|
int |
storedSimulationState
Is true
when we entered initialization mode and saved
the previous simulation state.
Declaration
private bool storedSimulationState
Field Value
Type | Description |
---|---|
bool |
Properties
| Edit this page View SourceBeepFailureProb
The probability of a beep not being received on each partition set of a particle.
Value is always clamped between 0 and 1.
Declaration
public float BeepFailureProb { get; set; }
Property Value
Type | Description |
---|---|
float |
CollisionCheckEnabled
Indicates whether the collision check should be executed. Turn the collision check off for improved performance.
Declaration
public bool CollisionCheckEnabled { get; }
Property Value
Type | Description |
---|---|
bool |
CurrentRound
The current round describing the simulation state.
Before the first round is simulated, the current round is 0
.
After each simulated round, this counter is incremented by 1
.
Declaration
public int CurrentRound { get; private set; }
Property Value
Type | Description |
---|---|
int |
EarliestRound
The round of the initial configuration before the first simulation round.
This is assumed to be always 0
.
Declaration
public int EarliestRound { get; private set; }
Property Value
Type | Description |
---|---|
int |
Finished
true
if the simulation has reached a round after which all
particles in the system were finished, even if this round lies later
in the history than the currently marked round.
Declaration
public bool Finished { get; }
Property Value
Type | Description |
---|---|
bool |
InBeepPhase
true
while the look-compute-beep cycle of a round is being simulated.
Declaration
public bool InBeepPhase { get; }
Property Value
Type | Description |
---|---|
bool |
InCollisionState
true
if a collision has occurred in the last recorded round.
The simulation will not proceed until the last round is cut off
from the history.
Declaration
public bool InCollisionState { get; }
Property Value
Type | Description |
---|---|
bool |
InInitializationState
Indicates whether the system is currently in the initialization state. In this state, particles can be added, removed, moved and modified freely and new configurations can be generated.
In this state, no methods controlling the simulation or the history replay should be called.
Declaration
public bool InInitializationState { get; }
Property Value
Type | Description |
---|---|
bool |
InMovePhase
true
while the look-compute-move cycle of a round is being simulated.
Declaration
public bool InMovePhase { get; }
Property Value
Type | Description |
---|---|
bool |
LatestRound
The latest round that has been reached through simulation.
Any simulation state between round 0
and this round
can be restored at any time without having to simulate the
particles. To proceed to later rounds, the simulation must
be continued from this round.
Declaration
public int LatestRound { get; private set; }
Property Value
Type | Description |
---|---|
int |
PreviousRound
The round that was previously simulated.
While a simulation round is being computed and the particles are
being activated, this value will be CurrentRound - 1
.
Inbetween rounds, CurrentRound and PreviousRound
will have the same value.
Declaration
public int PreviousRound { get; private set; }
Property Value
Type | Description |
---|---|
int |
SelectedAlgorithm
The name of the currently selected algorithm in initialization mode.
Declaration
public string SelectedAlgorithm { get; }
Property Value
Type | Description |
---|---|
string |
Methods
| Edit this page View SourceActivateParticlesBeep()
Executes the beep activation of each particle.
Declaration
private void ActivateParticlesBeep()
ActivateParticlesMove()
Executes the movement activations of all particles in the system and prepares the particles for the joint movement computation.
The final bonds of each particle are computed by their global positions
and adjusted based on the scheduled movement. Additionally, it is
determined whether the head of the particle is its local origin and
the local movement offset is calculated. The global offset of the
particles is reset to (0, 0)
.
Declaration
private bool ActivateParticlesMove()
Returns
Type | Description |
---|---|
bool |
|
AddInitParticle(Vector2Int, bool, Direction, Direction)
General method for adding particles to the system in initialization mode.
Declaration
public InitializationParticle AddInitParticle(Vector2Int tailPos, bool chirality, Direction compassDir, Direction headDirection = Direction.NONE)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | tailPos | The grid position of the particle's tail. |
bool | chirality | The chirality of the particle. |
Direction | compassDir | The compass direction of the particle. This is the global direction that corresponds to the particle's local E direction. |
Direction | headDirection | The global direction pointing from the particle's tail towards its head. Set to NONE to make the particle contracted. |
Returns
Type | Description |
---|---|
InitializationParticle | The newly added particle or |
AddNewObject(Vector2Int)
Creates a new object and adds it to the system in Init Mode.
The object is registered in the render system and should push updates to the particle system (i.e., whenever positions are added or removed or the object is moved).
Declaration
public ParticleObject AddNewObject(Vector2Int position)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | position | The initial position of the new object. |
Returns
Type | Description |
---|---|
ParticleObject | The newly created object, if it was created successfully,
otherwise |
AddObject(ParticleObject)
Adds an object to the system in Init Mode.
The object is registered in the render system and should push updates to the particle system (i.e., whenever positions are added or removed or the object is moved).
Declaration
public void AddObject(ParticleObject o)
Parameters
Type | Name | Description |
---|---|---|
ParticleObject | o | The object to be added. |
AddParticleContracted(Vector2Int, Chirality, Compass)
Adds a contracted particle at the given position when in initialization mode.
Declaration
public void AddParticleContracted(Vector2Int gridPos, Initialization.Chirality chirality = Chirality.CounterClockwise, Initialization.Compass compassDir = Compass.E)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | gridPos | The grid position where the particle should be placed. |
Initialization.Chirality | chirality | The current chirality setting. |
Initialization.Compass | compassDir | The current compass direction setting. |
AddParticleExpanded(Vector2Int, Vector2Int, Chirality, Compass)
Adds an expanded particle at the given position when in initialization mode.
Declaration
public void AddParticleExpanded(Vector2Int gridPosHead, Vector2Int gridPosTail, Initialization.Chirality chirality = Chirality.CounterClockwise, Initialization.Compass compassDir = Compass.E)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | gridPosHead | The grid position of the particle's head. |
Vector2Int | gridPosTail | The grid position of the particle's tail. |
Initialization.Chirality | chirality | The current chirality setting. |
Initialization.Compass | compassDir | The current compass direction setting. |
AddPositionToObject(ParticleObject, Vector2Int)
Extends the given object by adding the given position to the object map. Should be called whenever a new position is added to a registered object. Works only in Init Mode.
Declaration
public bool AddPositionToObject(ParticleObject o, Vector2Int gridPos)
Parameters
Type | Name | Description |
---|---|---|
ParticleObject | o | The registered object that gains a new position. |
Vector2Int | gridPos | The global grid position that should be added to the object. |
Returns
Type | Description |
---|---|
bool |
|
AnchorPosition()
Returns the world coordinates of the system's current anchor particle or object.
Declaration
public Vector2 AnchorPosition()
Returns
Type | Description |
---|---|
Vector2 | The world coordinates of the system's anchor particle or
object, if it exists, otherwise |
ApplyAttributeValueToAllParticles(IParticleState, string)
Copies the attribute value of the given particle to all particles in the system.
All particles that have an attribute with name
attributeName
will try to read the string
representation of p
's attribute value.
This only works for attribute types that can be represented
as strings (i.e., pin configurations will not work).
Declaration
public void ApplyAttributeValueToAllParticles(IParticleState p, string attributeName)
Parameters
Type | Name | Description |
---|---|---|
IParticleState | p | The particle from which to copy the attribute value. |
string | attributeName | The name of the attribute to copy. |
ApplyNewPinConfigurations()
Updates the pin configuration for each particle.
If a particle has moved in the move phase and has not set a new pin configuration, it will be reset to a singleton pattern.
Declaration
public void ApplyNewPinConfigurations()
CallAutomaticStatusInfoMethods()
Calls all automatic status info methods of the currently selected algorithm. Only works in Simulation Mode.
Declaration
private void CallAutomaticStatusInfoMethods()
CenterPosition(bool)
Calculates the average world position of all particles and objects in the system.
Declaration
public Vector2 CenterPosition(bool includeObjects = true)
Parameters
Type | Name | Description |
---|---|---|
bool | includeObjects | Whether positions occupied by objects should be included. |
Returns
Type | Description |
---|---|
Vector2 | The average world of all particles. Will be
|
CheckForCollision()
Checks for joint movement collisions by searching for overlapping edge movements in the set of recorded edges.
This method also clears the sets of collected edge movements in any case.
Declaration
private bool CheckForCollision()
Returns
Type | Description |
---|---|
bool |
|
CleanupAfterRound()
Resets the helper information of all particles and objects to prepare for the simulation of the next round.
Declaration
private void CleanupAfterRound()
CollectBondInfo(Particle, int, Direction, Particle[], bool[], bool[], int[], ParticleObject[], int)
Helper method for finding the bonded neighbors of a particle.
Declaration
private void CollectBondInfo(Particle p, int numNbrs, Direction globalHeadDir, Particle[] nbrParts, bool[] bondNbrs, bool[] nbrHead, int[] nbrLabels, ParticleObject[] nbrObjs, int handoverLabelToCheck = -1)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle whose neighbors shall be found. |
int | numNbrs | The number of labels to be checked. Should be
|
Direction | globalHeadDir | The global head direction of the particle. |
Particle[] | nbrParts | A particle array that should hold references to the bonded neighbor particles that still have to be processed. |
bool[] | bondNbrs | A bool array that should have |
bool[] | nbrHead | A bool array that should have |
int[] | nbrLabels | An int array that should hold the bonded neighbor's label corresponding to each of the current particle's labels. |
ParticleObject[] | nbrObjs | An object array that should hold references to the neighboring objects to which the particle is bonded. |
int | handoverLabelToCheck | One label that must have a bonded neighbor
because the current particle intends to perform a handover in that direction.
If no such neighbor is found, a System.InvalidOperationException
is thrown. Use |
ComputeBondsStatic()
Computes bond information in the case that no movements have occurred. This method works similar to the joint movement simulation but it does not process any movements. It also does not check whether the particle bond structure is connected or not. Bonds will only be computed for the connected component that contains the anchor particle (or the first particle if the anchor is an object).
Declaration
private void ComputeBondsStatic()
ContinueTracking()
Resets the marker to track the latest recorded state and to continue evolving as the simulation progresses.
Declaration
public void ContinueTracking()
ContractParticle(Particle, bool)
Declaration
private void ContractParticle(Particle p, bool head)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | |
bool | head |
ContractParticleHead(Particle)
System-side implementation of ContractHead().
Schedules a ParticleAction to contract the given particle into its head if the action is applicable. A contraction action is definitely not applicable if the particle is already contracted.
Declaration
public void ContractParticleHead(Particle p)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle that should contract. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the particle is already contracted. |
ContractParticleTail(Particle)
System-side implementation of ContractTail().
Schedules a ParticleAction to contract the given particle into its tail if the action is applicable. A contraction action is definitely not applicable if the particle is already contracted.
Declaration
public void ContractParticleTail(Particle p)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle that should contract. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the particle is already contracted. |
CutOffAtMarker()
Deletes all recorded states after the currently marked round.
Declaration
public void CutOffAtMarker()
DiscoverCircuits(bool)
Uses the particles' pin configurations to determine all circuits in the system from scratch and send the planned beeps and messages accordingly.
The algorithm performs a breadth-first search on each connected component of the particle system to assign every partition set of each particle to a circuit, merging the circuits if they happen to be connected when a partition set is added.
Declaration
private void DiscoverCircuits(bool sendBeepsAndMessages)
Parameters
Type | Name | Description |
---|---|---|
bool | sendBeepsAndMessages | Determines whether beeps
and messages are sent. Set to |
ExpandParticle(Particle, Direction)
System-side implementation of Expand(Direction).
Schedules a ParticleAction to expand the given particle in the specified direction if the action is applicable. An expansion action is definitely not applicable if the particle is already expanded.
Declaration
public void ExpandParticle(Particle p, Direction locDir)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle that should expand. |
Direction | locDir | The local direction into which the particle should expand. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the particle is already expanded. |
FindFirstNeighborObjectWithProperty(Particle, Func<IParticleObject, bool>, out Neighbor<IParticleObject>, Direction, bool, bool, int)
System-side implementation of FindFirstNeighborObjectWithProperty(Func<IParticleObject, bool>, out Neighbor<IParticleObject>, Direction, bool, bool, int).
Declaration
public bool FindFirstNeighborObjectWithProperty(Particle p, Func<IParticleObject, bool> prop, out Neighbor<IParticleObject> neighbor, Direction startDir = Direction.E, bool startAtHead = true, bool withChirality = true, int maxNumber = -1)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for a neighbor. |
Func<IParticleObject, bool> | prop | The property to be satisfied by the neighbor object. |
Neighbor<IParticleObject> | neighbor | The neighbor to be returned. |
Direction | startDir | The direction in which to start searching. |
bool | startAtHead | If |
bool | withChirality | If |
int | maxNumber | Maximum number of neighbor nodes to search. |
Returns
Type | Description |
---|---|
bool |
|
FindFirstNeighborWithProperty<T>(Particle, Func<T, bool>, out Neighbor<T>, Direction, bool, bool, int)
System-side implementation of FindFirstNeighborWithProperty<T>(Func<T, bool>, out Neighbor<T>, Direction, bool, bool, int).
Declaration
public bool FindFirstNeighborWithProperty<T>(Particle p, Func<T, bool> prop, out Neighbor<T> neighbor, Direction startDir = Direction.E, bool startAtHead = true, bool withChirality = true, int maxNumber = -1) where T : ParticleAlgorithm
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for a neighbor. |
Func<T, bool> | prop | The property to be satisfied by the neighbor. |
Neighbor<T> | neighbor | The neighbor to be returned. |
Direction | startDir | The direction in which to start searching. |
bool | startAtHead | If |
bool | withChirality | If |
int | maxNumber | Maximum number of neighbor nodes to search. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T | The algorithm type to search for. |
FindFirstNeighbor<T>(Particle, out Neighbor<T>, Direction, bool, bool, int)
System-side implementation of FindFirstNeighbor<T>(out Neighbor<T>, Direction, bool, bool, int).
Declaration
public bool FindFirstNeighbor<T>(Particle p, out Neighbor<T> neighbor, Direction startDir = Direction.E, bool startAtHead = true, bool withChirality = true, int maxNumber = -1) where T : ParticleAlgorithm
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for a neighbor. |
Neighbor<T> | neighbor | The neighbor to be returned. |
Direction | startDir | The direction in which to start searching. |
bool | startAtHead | If |
bool | withChirality | If |
int | maxNumber | Maximum number of neighbor nodes to search. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
T | The algorithm type to search for. |
FindFirstObjectNeighbor(Particle, out Neighbor<IParticleObject>, Direction, bool, bool, int)
System-side implementation of FindFirstObjectNeighbor(out Neighbor<IParticleObject>, Direction, bool, bool, int).
Declaration
public bool FindFirstObjectNeighbor(Particle p, out Neighbor<IParticleObject> neighbor, Direction startDir = Direction.E, bool startAtHead = true, bool withChirality = true, int maxNumber = -1)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for a neighbor object. |
Neighbor<IParticleObject> | neighbor | The neighbor object to be returned. |
Direction | startDir | The direction in which to start searching. |
bool | startAtHead | If |
bool | withChirality | If |
int | maxNumber | Maximum number of neighbor nodes to search. |
Returns
Type | Description |
---|---|
bool |
|
FindNeighborObjects(Particle, Direction, bool, bool, int, int)
System-side implementation of FindNeighborObjects(Direction, bool, bool, int, int).
Declaration
public List<Neighbor<IParticleObject>> FindNeighborObjects(Particle p, Direction startDir = Direction.E, bool startAtHead = true, bool withChirality = true, int maxSearch = -1, int maxReturn = -1)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for a neighbor. |
Direction | startDir | The direction in which to start searching. |
bool | startAtHead | If |
bool | withChirality | If |
int | maxSearch | Maximum number of neighbor nodes to search. |
int | maxReturn | Maximum number of neighbors to return. |
Returns
Type | Description |
---|---|
List<Neighbor<IParticleObject>> | The list of discovered neighbor objects. |
FindNeighborObjectsWithProperty(Particle, Func<IParticleObject, bool>, Direction, bool, bool, int, int)
System-side implementation of FindNeighborObjectsWithProperty(Func<IParticleObject, bool>, Direction, bool, bool, int, int).
Declaration
public List<Neighbor<IParticleObject>> FindNeighborObjectsWithProperty(Particle p, Func<IParticleObject, bool> prop, Direction startDir = Direction.E, bool startAtHead = true, bool withChirality = true, int maxSearch = -1, int maxReturn = -1)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for a neighbor. |
Func<IParticleObject, bool> | prop | The property to be satisfied by the neighbor objects. |
Direction | startDir | The direction in which to start searching. |
bool | startAtHead | If |
bool | withChirality | If |
int | maxSearch | Maximum number of neighbor nodes to search. |
int | maxReturn | Maximum number of neighbors to return. |
Returns
Type | Description |
---|---|
List<Neighbor<IParticleObject>> | The list of discovered neighbor objects. |
FindNeighborsWithProperty<T>(Particle, Func<T, bool>, Direction, bool, bool, int, int)
System-side implementation of FindNeighborsWithProperty<T>(Func<T, bool>, Direction, bool, bool, int, int).
Declaration
public List<Neighbor<T>> FindNeighborsWithProperty<T>(Particle p, Func<T, bool> prop, Direction startDir = Direction.E, bool startAtHead = true, bool withChirality = true, int maxSearch = -1, int maxReturn = -1) where T : ParticleAlgorithm
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for a neighbor. |
Func<T, bool> | prop | The property to be satisfied by the neighbors. |
Direction | startDir | The direction in which to start searching. |
bool | startAtHead | If |
bool | withChirality | If |
int | maxSearch | Maximum number of neighbor nodes to search. |
int | maxReturn | Maximum number of neighbors to return. |
Returns
Type | Description |
---|---|
List<Neighbor<T>> | The list of discovered neighbors. |
Type Parameters
Name | Description |
---|---|
T | The algorithm type to search for. |
FindNeighbors<T>(Particle, Direction, bool, bool, int, int)
System-side implementation of FindNeighbors<T>(Direction, bool, bool, int, int).
Declaration
public List<Neighbor<T>> FindNeighbors<T>(Particle p, Direction startDir = Direction.E, bool startAtHead = true, bool withChirality = true, int maxSearch = -1, int maxReturn = -1) where T : ParticleAlgorithm
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for a neighbor. |
Direction | startDir | The direction in which to start searching. |
bool | startAtHead | If |
bool | withChirality | If |
int | maxSearch | Maximum number of neighbor nodes to search. |
int | maxReturn | Maximum number of neighbors to return. |
Returns
Type | Description |
---|---|
List<Neighbor<T>> | The list of discovered neighbors. |
Type Parameters
Name | Description |
---|---|
T | The algorithm type to search for. |
FinishBeepAndMessageInfo()
Stores the received beeps and messages and resets the planned beeps and messages for each particle. Use this to prepare the particles for the transmission and reception of beeps and messages in the next round.
Declaration
private void FinishBeepAndMessageInfo()
FinishMovementInfo()
Stores the released and marked bonds and resets them for each particle and resets joint movement info for every object. Use this to prepare the particles and objects for the joint movements in the next round.
Declaration
private void FinishMovementInfo()
GenerateInitSaveData(InitModeSaveData)
Writes the current initialization state into a serializable object.
Declaration
public InitializationStateSaveData GenerateInitSaveData(InitModeSaveData initModeSaveData = null)
Parameters
Type | Name | Description |
---|---|---|
InitModeSaveData | initModeSaveData | Serializable information describing the current UI state. |
Returns
Type | Description |
---|---|
InitializationStateSaveData | A serializable object containing the current initialization state including UI elements. |
GenerateInitSystem()
Generates the particle system in initialization mode using the selected algorithm's default parameters.
Declaration
private void GenerateInitSystem()
GenerateInitSystem(object[])
Generates the particle system in initialization mode using the given parameters.
Declaration
private void GenerateInitSystem(object[] parameters)
Parameters
Type | Name | Description |
---|---|---|
object[] | parameters | The parameters that should be passed to the selected algorithm's generation method. |
GenerateParticles(string, object[])
Invokes the specified system generation method to fill the system with particles in initialization mode.
Declaration
public void GenerateParticles(string methodName, object[] parameters)
Parameters
Type | Name | Description |
---|---|---|
string | methodName | The name of the generation method. |
object[] | parameters | The parameters for the generation method. |
GenerateSaveData()
Writes the current simulation state including its entire history into a serializable object.
Declaration
public SimulationStateSaveData GenerateSaveData()
Returns
Type | Description |
---|---|
SimulationStateSaveData | A serializable object containing the current simulation state and its history. |
GetBoundingBox(bool)
Computes the bounding box of the current particle system (including objects) in world coordinates. The bounding box is computed with respect to the current camera rotation, but this rotation is not preserved in the result.
Declaration
public Vector4 GetBoundingBox(bool includeObjects = true)
Parameters
Type | Name | Description |
---|---|---|
bool | includeObjects | Whether objects should be included in the calculation. |
Returns
Type | Description |
---|---|
Vector4 | A vector |
GetFirstRecordedRound()
Returns the first round for which a state has been recorded.
The object cannot be reset to a time before this round.
Declaration
public int GetFirstRecordedRound()
Returns
Type | Description |
---|---|
int | The first round for which a state has been recorded. |
GetInitParticles()
Returns an array storing all current particles in initialization mode.
Declaration
public InitializationParticle[] GetInitParticles()
Returns
Type | Description |
---|---|
InitializationParticle[] | An array containing all initialization particles. |
GetMarkedRound()
Returns the round that is currently marked.
If the marker is tracking the object's state, this round will increase every time a new value is recorded.
Declaration
public int GetMarkedRound()
Returns
Type | Description |
---|---|
int | The round that is currently marked. |
GetNeighborAt(Particle, Direction, bool)
System-side implementation of GetNeighborAt(Direction, bool).
See also HasNeighborAt(Particle, Direction, bool).
Declaration
public Particle GetNeighborAt(Particle p, Direction locDir, bool fromHead = true)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle trying to get its neighbor. |
Direction | locDir | The local direction of the particle in which to check. |
bool | fromHead | If |
Returns
Type | Description |
---|---|
Particle | The neighboring particle in the specified position, if it exists,
otherwise |
GetObjectAt(Particle, Direction, bool)
System-side implementation of GetObjectAt(Direction, bool).
See also HasObjectAt(Particle, Direction, bool).
Declaration
public IParticleObject GetObjectAt(Particle p, Direction locDir, bool fromHead = true)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle trying to get its neighbor object. |
Direction | locDir | The local direction of the particle in which to check. |
bool | fromHead | If |
Returns
Type | Description |
---|---|
IParticleObject | The neighboring object in the specified position, if it exists,
otherwise |
HasNeighborAt(Particle, Direction, bool)
System-side implementation of HasNeighborAt(Direction, bool).
See also GetNeighborAt(Particle, Direction, bool).
Declaration
public bool HasNeighborAt(Particle p, Direction locDir, bool fromHead = true)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle checking for a neighbor. |
Direction | locDir | The local direction of the particle in which to check. |
bool | fromHead | If |
Returns
Type | Description |
---|---|
bool |
|
HasObjectAt(Particle, Direction, bool)
System-side implementation of HasObjectAt(Direction, bool).
See also HasNeighborAt(Particle, Direction, bool).
Declaration
public bool HasObjectAt(Particle p, Direction locDir, bool fromHead = true)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle checking for a neighboring object. |
Direction | locDir | The local direction of the particle in which to check. |
bool | fromHead | If |
Returns
Type | Description |
---|---|
bool |
|
HasSimulationFinished()
Checks if the simulation has finished by calling the IsFinished() method on all particles.
Declaration
private bool HasSimulationFinished()
Returns
Type | Description |
---|---|
bool |
|
InitializationModeAborted()
Aborts the initialization mode and reloads the previous simulation state if possible.
Declaration
public void InitializationModeAborted()
InitializationModeFinished(string)
Exits the initialization mode and initializes the particle system based on the current configuration.
Declaration
public void InitializationModeFinished(string algorithmName)
Parameters
Type | Name | Description |
---|---|---|
string | algorithmName | The name of the selected algorithm. |
InitializationModeStarted(string)
Switches the system state to initialization mode.
Declaration
public void InitializationModeStarted(string selectedAlgo)
Parameters
Type | Name | Description |
---|---|---|
string | selectedAlgo | The name of the first algorithm that should be selected. |
InitializeBoundaryTest(int, float)
Declaration
public void InitializeBoundaryTest(int numParticles, float holeProb)
Parameters
Type | Name | Description |
---|---|---|
int | numParticles | |
float | holeProb |
InitializeChiralityCompass(int, float)
Declaration
public void InitializeChiralityCompass(int numParticles, float holeProb)
Parameters
Type | Name | Description |
---|---|---|
int | numParticles | |
float | holeProb |
InitializeExpandedTest(int)
Declaration
public void InitializeExpandedTest(int numParticles)
Parameters
Type | Name | Description |
---|---|---|
int | numParticles |
InitializeFixed(string, object[])
Helper for initializing the system with a specific algorithm and starting the simulation. Does not work in initialization mode.
Declaration
private void InitializeFixed(string algorithmName, object[] parameters)
Parameters
Type | Name | Description |
---|---|---|
string | algorithmName | The name of the algorithm to be initialized. |
object[] | parameters | The parameters that should be passed to the algorithm's generation method. |
InitializeFromSaveState(SimulationStateSaveData, bool)
Initializes the system to the state that is stored in the given save data object.
This only works correctly if the system was reset using the Reset() method before.
Declaration
public void InitializeFromSaveState(SimulationStateSaveData data, bool updateVisuals = true)
Parameters
Type | Name | Description |
---|---|---|
SimulationStateSaveData | data | The object containing the saved simulation state. |
bool | updateVisuals | If |
InitializeJMTest(int)
Declaration
public void InitializeJMTest(int mode)
Parameters
Type | Name | Description |
---|---|---|
int | mode |
InitializeLeaderElection(int, float)
Declaration
public void InitializeLeaderElection(int numParticles, float holeProb)
Parameters
Type | Name | Description |
---|---|---|
int | numParticles | |
float | holeProb |
InitializeLineFormation(int, float)
Initializes the system with connected LineFormationParticles for testing purposes. This should be removed after a proper initialization method has been created.
Declaration
public void InitializeLineFormation(int numParticles, float holeProb)
Parameters
Type | Name | Description |
---|---|---|
int | numParticles | The number of particles to create. |
float | holeProb | The probability of a position not being occupied by a particle and being left empty instead. |
IsAnchor(ParticleObject)
Checks if the given object is the anchor of the system.
Declaration
public bool IsAnchor(ParticleObject obj)
Parameters
Type | Name | Description |
---|---|---|
ParticleObject | obj | The object that should be checked. |
Returns
Type | Description |
---|---|
bool |
|
IsAnchor(IParticleState)
Checks if the given particle is the anchor of the system.
Declaration
public bool IsAnchor(IParticleState p)
Parameters
Type | Name | Description |
---|---|---|
IParticleState | p | The particle that should be checked. |
Returns
Type | Description |
---|---|
bool |
|
IsHeadAt(Particle, Direction, bool)
System-side implementation of IsHeadAt(Direction, bool).
Declaration
public bool IsHeadAt(Particle p, Direction locDir, bool fromHead = true)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle checking for a neighbor's head. |
Direction | locDir | The local direction of the particle in which to check. |
bool | fromHead | If |
Returns
Type | Description |
---|---|
bool |
|
IsInLatestRound()
Checks whether the simulation state is currently in the latest recorded round.
Declaration
public bool IsInLatestRound()
Returns
Type | Description |
---|---|
bool |
|
IsInitSystemConnected()
Checks whether the initialization system is connected such that the particles form a connected component and all objects are either directly or indirectly connected to a particle.
Declaration
private bool IsInitSystemConnected()
Returns
Type | Description |
---|---|
bool |
|
IsTailAt(Particle, Direction, bool)
System-side implementation of IsTailAt(Direction, bool).
Declaration
public bool IsTailAt(Particle p, Direction locDir, bool fromHead = true)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle checking for a neighbor's tail. |
Direction | locDir | The local direction of the particle in which to check. |
bool | fromHead | If |
Returns
Type | Description |
---|---|
bool |
|
IsTracking()
Checks whether the object is currently tracking the latest recorded state.
If the object is not tracking, it may not be usable in the regular way until the tracking is continued.
Declaration
public bool IsTracking()
Returns
Type | Description |
---|---|
bool | Whether the marker currently tracks the latest recorded state. |
IterateNeighborObjects(Particle, Direction, bool, bool, int, int)
Iterates through the neighbor nodes of a given particle and returns the encountered objects. See IterateNeighbors<T>(Particle, Direction, bool, bool, int, int).
Declaration
private IEnumerable<Neighbor<IParticleObject>> IterateNeighborObjects(Particle p, Direction localStartDir, bool startAtHead, bool withChirality, int maxSearch, int maxReturn)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for neighbor objects. |
Direction | localStartDir | The local direction of |
bool | startAtHead | If |
bool | withChirality | If |
int | maxSearch | The maximum number of nodes to search. |
int | maxReturn | The maximum number of neighbors to return. |
Returns
Type | Description |
---|---|
IEnumerable<Neighbor<IParticleObject>> | Every neighbor object encountered during the search, each wrapped in a Neighbor<T> instance. |
IterateNeighbors<T>(Particle, Direction, bool, bool, int, int)
Iterates through the neighbor nodes of a given particle and returns the encountered particles.
Declaration
private IEnumerable<Neighbor<T>> IterateNeighbors<T>(Particle p, Direction localStartDir, bool startAtHead, bool withChirality, int maxSearch, int maxReturn) where T : ParticleAlgorithm
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle searching for neighbors. |
Direction | localStartDir | The local direction of |
bool | startAtHead | If |
bool | withChirality | If |
int | maxSearch | The maximum number of nodes to search. |
int | maxReturn | The maximum number of neighbors to return. |
Returns
Type | Description |
---|---|
IEnumerable<Neighbor<T>> | Every neighbor ParticleAlgorithm encountered during the search, each wrapped in a Neighbor<T> instance. |
Type Parameters
Name | Description |
---|---|
T | The type of particles to search for, must be ParticleAlgorithm subclass. |
JointMovementContractedExpanded(Particle, Particle, Direction, Direction, int, int, int, int, bool, bool, bool)
Helper method for handling the joint movement of a contracted particle that is bonded to an expanded particle.
Declaration
private Vector2Int JointMovementContractedExpanded(Particle c, Particle e, Direction bondDir, Direction secondBondDir, int cLabel1, int cLabel2, int eLabel1, int eLabel2, bool eHead1, bool eHead2, bool bondForContracted = true)
Parameters
Type | Name | Description |
---|---|---|
Particle | c | The contracted particle. |
Particle | e | The expanded particle. |
Direction | bondDir | The global direction of the primary bond from the contracted to the expanded particle. The primary bond is simply the first one we encounter while processing the movements. |
Direction | secondBondDir | The global direction of the second bond from the contracted to the expanded particle. Must be NONE if there is no second bond. |
int | cLabel1 | The global label of the contracted particle identifying the primary bond. |
int | cLabel2 | The global label of the contracted particle identifying the second bond.
Must be |
int | eLabel1 | The global label of the expanded particle identifying the primary bond. |
int | eLabel2 | The global label of the expanded particle identifying the second bond.
Must be |
bool | eHead1 | Flag indicating whether the first bond is incident to the head of the expanded particle. |
bool | eHead2 | Flag indicating whether the second bond is incident to the head of the
expanded particle. Must be |
bool | bondForContracted | Flag indicating whether the bond info should be associated with the contracted particle. |
Returns
Type | Description |
---|---|
Vector2Int | The global offset vector of the expanded particle's origin relative to the contracted particle's origin. |
JointMovementExpandedTwoBonds(Particle, Particle, bool, bool, bool, bool, bool)
Helper method for handling the joint movements of two neighboring expanded particles that from a triangle with two bonds.
Declaration
private Vector2Int JointMovementExpandedTwoBonds(Particle pCorner, Particle pEdge, bool cornerAtHead, bool cornerMarked1, bool cornerMarked2, bool edgeMarkedHead, bool edgeMarkedTail)
Parameters
Type | Name | Description |
---|---|---|
Particle | pCorner | The particle owning the part where the two bonds meet. |
Particle | pEdge | The particle having one bond on each of its parts. |
bool | cornerAtHead | Indicates whether the part where the two bonds meet
is the head of the |
bool | cornerMarked1 | Indicates whether the particle owning the corner has marked the first bond. |
bool | cornerMarked2 | Indicates whether the particle owning the corner has marked the second bond. |
bool | edgeMarkedHead | Indicates whether the edge particle has marked the bond at its head. |
bool | edgeMarkedTail | Indicates whether the edge particle has marked the bond at its tail. |
Returns
Type | Description |
---|---|
Vector2Int | The global offset vector of the edge particle's origin relative to the corner particle's origin. |
LoadInitSaveState(InitializationStateSaveData)
Initializes the system to the initialization state that is stored in the given save data object.
Only works correctly in Initialization mode.
Declaration
public InitModeSaveData LoadInitSaveState(InitializationStateSaveData data)
Parameters
Type | Name | Description |
---|---|---|
InitializationStateSaveData | data | The object containing the saved initialization state. |
Returns
Type | Description |
---|---|
InitModeSaveData | The serializable data about the UI state that is
contained in |
LoadMovementGraphicsInfo(bool)
Sets the bond graphics info of all particles and objects to the currently loaded state so that it can be displayed. If animations are required, the joint movement info is also loaded and set up to produce the correct animations. This should be called when stepping or jumping through the history.
Declaration
private void LoadMovementGraphicsInfo(bool withAnimation)
Parameters
Type | Name | Description |
---|---|---|
bool | withAnimation | Flag indicating whether the loaded movement information should include an animation or not. |
MakeObjectAnchor(Particle, Direction, bool)
System-side implementation of MakeObjectAnchor(Direction, bool).
Checks if there is an object at the given neighbor location and turns it into the anchor if it is found.
Declaration
public bool MakeObjectAnchor(Particle p, Direction locDir, bool head)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle trying to turn its neighbor object into the anchor. |
Direction | locDir | The local direction in which the neighbor object should be. |
bool | head | Whether the neighbor object is adjacent to the particle's head. |
Returns
Type | Description |
---|---|
bool |
|
MoveObject(ParticleObject, Vector2Int)
Moves all registered positions of the given object by the given offset. The positions stored internally by the object are not changed by this operation. Only works for objects registered in the system and in Init Mode.
Declaration
public bool MoveObject(ParticleObject o, Vector2Int offset)
Parameters
Type | Name | Description |
---|---|---|
ParticleObject | o | The object that should be moved. |
Vector2Int | offset | The offset by which the object should be moved. |
Returns
Type | Description |
---|---|
bool |
|
MoveParticleToNewContractedPosition(IParticleState, Vector2Int)
Moves the given particle to a new location in which it is contracted, when in initialization mode.
Declaration
public void MoveParticleToNewContractedPosition(IParticleState p, Vector2Int gridPos)
Parameters
Type | Name | Description |
---|---|---|
IParticleState | p | The particle to be moved. |
Vector2Int | gridPos | The new grid position to which |
MoveParticleToNewExpandedPosition(IParticleState, Vector2Int, Vector2Int)
Moves the given particle to a new location in which it is expanded, when in initialization mode.
Declaration
public void MoveParticleToNewExpandedPosition(IParticleState p, Vector2Int gridPosHead, Vector2Int gridPosTail)
Parameters
Type | Name | Description |
---|---|---|
IParticleState | p | The particle to be moved. |
Vector2Int | gridPosHead | The new grid position to which
|
Vector2Int | gridPosTail | The new grid position to which
|
PerformPullHandover(Particle, Direction, bool)
Declaration
private void PerformPullHandover(Particle p, Direction locDir, bool head)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | |
Direction | locDir | |
bool | head |
PerformPullHandoverHead(Particle, Direction)
System-side implementation of PullHandoverHead(Direction).
Schedules a ParticleAction to contract the given particle into its head, pulling a contracted neighbor into its tail position, if the action is applicable. A pull handover action is definitely not applicable if the particle is already contracted or there is no contracted neighbor in the specified direction.
Declaration
public void PerformPullHandoverHead(Particle p, Direction locDir)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle that should contract during the handover. |
Direction | locDir | The local direction relative to |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the particle is already contracted or there is no contracted neighbor in the specified local direction relative to the particle's tail. |
PerformPullHandoverTail(Particle, Direction)
System-side implementation of PullHandoverTail(Direction).
Schedules a ParticleAction to contract the given particle into its tail, pulling a contracted neighbor into its head position, if the action is applicable. A pull handover action is definitely not applicable if the particle is already contracted or there is no contracted neighbor in the specified direction.
Declaration
public void PerformPullHandoverTail(Particle p, Direction locDir)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle that should contract during the handover. |
Direction | locDir | The local direction relative to |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the particle is already contracted or there is no contracted neighbor in the specified local direction relative to the particle's head. |
PerformPushHandover(Particle, Direction)
System-side implementation of PushHandover(Direction).
Schedules a ParticleAction to expand the given particle in the specified direction, pushing away an expanded neighbor, if the action is applicable. A push handover action is definitely not applicable if the particle is already expanded or the node in expansion direction is not occupied by an expanded particle.
Declaration
public void PerformPushHandover(Particle p, Direction locDir)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle that should expand during the handover. |
Direction | locDir | The local direction into which the particle should expand. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the particle is already expanded or the node in expansion direction is not occupied by an expanded particle. |
PropagateObjectOffset(ParticleObject, Particle, bool)
Helper method that propagates joint movement offset in a connected structure of objects and computes the corresponding bonds.
Declaration
private void PropagateObjectOffset(ParticleObject o, Particle sourceParticle, bool collectEdgeMovements = true)
Parameters
Type | Name | Description |
---|---|---|
ParticleObject | o | The object at which to start the propagation. The offset of this object will be applied to all connected objects. |
Particle | sourceParticle | The particle to which the visual bond information should be assigned. |
bool | collectEdgeMovements | Whether edge movements should be collected for the bonds between objects. These edge movements will be used for the collision check. |
RemoveObject(ParticleObject)
Removes the given object from the system. The object must be removed from the render system manually. Only works in Init Mode.
Declaration
public void RemoveObject(ParticleObject o)
Parameters
Type | Name | Description |
---|---|---|
ParticleObject | o | The object to be removed. |
RemoveParticle(IParticleState)
Removes the given particle when in initialization state.
Declaration
public void RemoveParticle(IParticleState p)
Parameters
Type | Name | Description |
---|---|---|
IParticleState | p | The particle to be removed. |
RemovePositionFromObject(ParticleObject, Vector2Int)
Removes the given position from the given object. Should be called whenever a position is removed from a registered object. Works only in Init Mode.
Declaration
public bool RemovePositionFromObject(ParticleObject o, Vector2Int gridPos)
Parameters
Type | Name | Description |
---|---|---|
ParticleObject | o | The registered object that loses a position. |
Vector2Int | gridPos | The global grid position that should be removed from the object. |
Returns
Type | Description |
---|---|
bool |
|
Reset()
Resets the entire system to a state from which it can be initialized again.
Declaration
public void Reset()
ResetAfterException()
Resets the simulation state to the previous round if an exception has occurred during round simulation.
Declaration
private void ResetAfterException()
ResetInit(bool)
Resets the current particle configuration while in initialization mode.
Declaration
public void ResetInit(bool removeObjects = true)
Parameters
Type | Name | Description |
---|---|---|
bool | removeObjects |
SetAnchor(ParticleObject)
Sets the given object to be the new anchor of the system. Only works in the latest round of the simulation or in Initialization Mode.
Declaration
public bool SetAnchor(ParticleObject obj)
Parameters
Type | Name | Description |
---|---|---|
ParticleObject | obj | The object that should become the anchor. |
Returns
Type | Description |
---|---|
bool |
|
SetAnchor(IParticleState)
Sets the given particle to be the new anchor of the system. Only works in the latest round of the simulation or in Initialization Mode.
Declaration
public bool SetAnchor(IParticleState p)
Parameters
Type | Name | Description |
---|---|---|
IParticleState | p | The particle that should become the anchor. |
Returns
Type | Description |
---|---|
bool |
|
SetCollisionCheck(bool)
Enables or disables the collision check.
Declaration
public void SetCollisionCheck(bool enabled)
Parameters
Type | Name | Description |
---|---|---|
bool | enabled | If |
SetInitialParticleBonds()
Sets all global bonds of all particles to active so that their initial bonds can be computed easily.
Declaration
private void SetInitialParticleBonds()
SetMarkerToRound(int)
Sets the tracking marker to the specified round, restores the state recorded for that point in time, and stops the marker from tracking the latest round.
The target round must not be earlier than the round returned by GetFirstRecordedRound().
Declaration
public void SetMarkerToRound(int round)
Parameters
Type | Name | Description |
---|---|---|
int | round | The round to which the tracking marker should be set. |
SetSelectedAlgorithm(string)
Updates the currently selected algorithm in initialization mode.
This will trigger a new system generation if the selected algorithm has changed.
Declaration
public void SetSelectedAlgorithm(string algoName)
Parameters
Type | Name | Description |
---|---|---|
string | algoName | The name of the newly selected algorithm. |
SetSystemAttributeRandom(string)
Sets the given attribute to a random value for each particle in the system.
Declaration
public void SetSystemAttributeRandom(string attributeName)
Parameters
Type | Name | Description |
---|---|---|
string | attributeName | The name of the attribute to randomize. |
SetSystemChirality(Chirality)
Resets the chirality of all particles to the given value when in initialization mode.
Declaration
public bool SetSystemChirality(Initialization.Chirality chirality)
Parameters
Type | Name | Description |
---|---|---|
Initialization.Chirality | chirality | The chirality to assign to each particle. If the value is Random, the particles get a clockwise chirality with a probability of 50%. |
Returns
Type | Description |
---|---|
bool |
|
SetSystemCompassDir(Compass)
Resets the compass direction of all particles to the given value when in initialization mode.
Declaration
public bool SetSystemCompassDir(Initialization.Compass compassDir)
Parameters
Type | Name | Description |
---|---|---|
Initialization.Compass | compassDir | The compass direction to assign to each particle. If the value is Random, each particle gets one of the cardinal directions chosen uniformly and independently. |
Returns
Type | Description |
---|---|
bool |
|
SetupPinGraphicState(bool)
Initializes the ParticlePinGraphicState of all particles and sets the neighbor information. The neighbor caches must have been updated and movement information must have been loaded at this point.
Declaration
private void SetupPinGraphicState(bool reset = false)
Parameters
Type | Name | Description |
---|---|---|
bool | reset | If |
ShiftTimescale(int)
Shifts all records as well as the marker by the specified amount of rounds.
Declaration
public void ShiftTimescale(int amount)
Parameters
Type | Name | Description |
---|---|---|
int | amount | The number of rounds to add to each entry. May be negative. |
SimulateJointMovements()
Computes the joint movements of the particle system after all movement activations were executed. Each particle gets a global offset that is applied in addition to its own local movement.
Performs a breadth-first search on the graph induced by the particles' bonds, starting at the anchor particle (or the particle with index 0 if the anchor is an object). For each visited particle, offsets for all of its unvisited neighbors are computed based on the particle's own offset. The computation fails if two neighboring particles try to perform conflicting movements or any two particles end up at the same final location.
Declaration
private void SimulateJointMovements()
SimulateRound()
Simulates a round in which each particle is activated twice. First, all particles execute their movement activations and the resulting movements are simulated and applied. Afterwards, the particles' beep activations are executed, the resulting circuits are determined and the sent beeps and messages are delivered. The order of activations is the same in both rounds.
If a catchable exception occurs during the simulation, the system state is reset to the previous round.
Only works while in tracking state during simulation mode.
Declaration
public void SimulateRound()
StepBack()
Moves the marker one round back and restores the object's recorded state for that round. Also stops it from tracking the last round if it was still tracking.
Must not be called when the marker is already at the first recorded round.
Declaration
public void StepBack()
StepForward()
Moves the marker one round forward and restores the object's recorded state for that round. Also stops it from tracking the last round if it was still tracking.
May be ineffective if the object has a hard limit on the last recorded round.
Declaration
public void StepForward()
TriggerObjectBondRelease(Particle, Direction, bool)
System-side implementation of TriggerObjectBondRelease(Direction, bool).
Checks if there is an object at the given neighbor location and releases its object bonds if it is found.
Declaration
public void TriggerObjectBondRelease(Particle p, Direction locDir, bool head)
Parameters
Type | Name | Description |
---|---|---|
Particle | p | The particle trying to release the neighbor object's bonds. |
Direction | locDir | The local direction in which the neighbor object should be. |
bool | head | Whether the neighbor object is adjacent to the particle's head. |
TryChangeInitParticleExpansion(InitializationParticle, Direction)
Tries to change a particle's expansion state when in initialization mode. This method should only be called from within the particle itself so that it can update its own state after this check is complete.
Declaration
public bool TryChangeInitParticleExpansion(InitializationParticle ip, Direction newHeadDir)
Parameters
Type | Name | Description |
---|---|---|
InitializationParticle | ip | The initialization particle trying to change its expansion state. |
Direction | newHeadDir | The desired new head direction. |
Returns
Type | Description |
---|---|
bool |
|
TryGetInitParticleAt(Vector2Int, out InitializationParticle)
Tries to get the InitializationParticle at the given position.
Declaration
public bool TryGetInitParticleAt(Vector2Int position, out InitializationParticle particle)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | position | The grid position at which to look for the particle. |
InitializationParticle | particle | The particle at the given position, if it exists,
otherwise |
Returns
Type | Description |
---|---|
bool |
|
TryGetObjectAt(Vector2Int, out IObjectInfo)
Tries to get the object at the given position.
Declaration
public bool TryGetObjectAt(Vector2Int position, out IObjectInfo obj)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | position | The grid position at which to look for the object. |
IObjectInfo | obj | The object at the given position, if it
exists, otherwise |
Returns
Type | Description |
---|---|
bool |
|
TryGetParticleAt(Vector2Int, out Particle)
Tries to get the Particle at the given position. Only works in simulation mode.
Declaration
private bool TryGetParticleAt(Vector2Int position, out Particle particle)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | position | The grid position at which to look for the particle. |
Particle | particle | The particle at the given position, if it exists,
otherwise |
Returns
Type | Description |
---|---|
bool |
|
TryGetParticleAt(Vector2Int, out IParticleState)
Tries to get the IParticleState at the given position.
Declaration
public bool TryGetParticleAt(Vector2Int position, out IParticleState particle)
Parameters
Type | Name | Description |
---|---|---|
Vector2Int | position | The grid position at which to look for the particle. |
IParticleState | particle | The particle at the given position, if it exists,
otherwise |
Returns
Type | Description |
---|---|
bool |
|
UpdateAfterStep(bool, bool, bool)
Helper for updating particles and visualization info after stepping or jumping through the history.
Declaration
private void UpdateAfterStep(bool withAnimation = false, bool pinGraphicStateReset = true, bool resetVisuals = true)
Parameters
Type | Name | Description |
---|---|---|
bool | withAnimation | Passed through to LoadMovementGraphicsInfo(bool), determines whether info for animations should be loaded. |
bool | pinGraphicStateReset | Passed through to SetupPinGraphicState(bool), determines whether pin connections should be animated for a reset. |
bool | resetVisuals | Passed through to UpdateAllParticleVisuals(bool), determines whether the visuals update is a reset without animations. |
UpdateAllParticleVisuals(bool)
Triggers a graphics update for each particle in the system.
Declaration
private void UpdateAllParticleVisuals(bool resetVisuals)
Parameters
Type | Name | Description |
---|---|---|
bool | resetVisuals |
UpdateNeighborCaches()
Updates the neighbor caches of all particles in the system based on their current positions. The current cache will become the old cache.
Declaration
private void UpdateNeighborCaches()