Class SysPinConfiguration
System-side implementation of the abstract base class PinConfiguration, which declares the API for the developer.
Can generate a compressed representation to enable saving and loading pin configurations, see PinConfigurationSaveData.
Namespace: AS2.Sim
Assembly: .dll
Syntax
public class SysPinConfiguration : PinConfiguration
Constructors
| Edit this page View SourceSysPinConfiguration(PinConfigurationSaveData, Particle)
Recovers a pin configuration from its serializable representation. It is expected that the given particle already has an algorithm attached to it and that it matches the given pin configuration save data.
Declaration
public SysPinConfiguration(PinConfigurationSaveData data, Particle p)
Parameters
Type | Name | Description |
---|---|---|
PinConfigurationSaveData | data | The serializable representation of the pin configuration. |
Particle | p | The particle to which the pin configuration should belong. |
SysPinConfiguration(Particle, int, Direction)
Declaration
public SysPinConfiguration(Particle particle, int pinsPerEdge, Direction headDirection = Direction.NONE)
Parameters
Type | Name | Description |
---|---|---|
Particle | particle | |
int | pinsPerEdge | |
Direction | headDirection |
Fields
| Edit this page View SourceheadDirection
The local head direction if this pin configuration is expanded.
Declaration
private Direction headDirection
Field Value
Type | Description |
---|---|
Direction |
isCurr
Whether this is the current pin configuration. This is the case for the duration of one round unless a movement is performed, in which case a singleton replaces this configuration.
Declaration
public bool isCurr
Field Value
Type | Description |
---|---|
bool |
isNext
Whether this is the next pin configuration. This is the case during one beep activation.
Declaration
public bool isNext
Field Value
Type | Description |
---|---|
bool |
lineRotationHead
The global angle of the line along which partition sets are placed in the particle's head.
Declaration
public float lineRotationHead
Field Value
Type | Description |
---|---|
float |
lineRotationTail
The global angle of the line along which partition sets are placed in the particle's tail.
Declaration
public float lineRotationTail
Field Value
Type | Description |
---|---|
float |
numPins
The total number of pins.
Declaration
private int numPins
Field Value
Type | Description |
---|---|
int |
particle
The particle to which this pin configuration belongs.
Declaration
public Particle particle
Field Value
Type | Description |
---|---|
Particle |
partitionSets
The partition sets defining this pin configuration.
Declaration
public SysPartitionSet[] partitionSets
Field Value
Type | Description |
---|---|
SysPartitionSet[] |
pins
The pins contained in this pin configuration.
Declaration
public SysPin[] pins
Field Value
Type | Description |
---|---|
SysPin[] |
pinsGlobal
Pins sorted by global IDs. These are the same pins as the ones stored in pins.
Declaration
public SysPin[] pinsGlobal
Field Value
Type | Description |
---|---|
SysPin[] |
pinsPerEdge
The number of pins on each edge.
Declaration
private int pinsPerEdge
Field Value
Type | Description |
---|---|
int |
placementModeHead
The selected partition set placement mode in the particle's head.
Declaration
public PSPlacementMode placementModeHead
Field Value
Type | Description |
---|---|
PSPlacementMode |
placementModeTail
The selected partition set placement mode in the particle's tail.
Declaration
public PSPlacementMode placementModeTail
Field Value
Type | Description |
---|---|
PSPlacementMode |
Properties
| Edit this page View SourceHeadDirection
The local head direction which encodes the expansion state of this pin configuration. If the state is contracted, this value is NONE.
A pin configuration can only be applied if its expansion state matches the particle's expansion state at the end of the round.
Declaration
public override Direction HeadDirection { get; }
Property Value
Type | Description |
---|---|
Direction |
Overrides
| Edit this page View SourceNumPins
The total number of pins in the pin configuration.
For contracted particles, this number equals
6 * PinsPerEdge
, and for expanded
particles, it is 10 * PinsPerEdge
.
Declaration
public override int NumPins { get; }
Property Value
Type | Description |
---|---|
int |
Overrides
| Edit this page View SourcePinsPerEdge
The number of pins per edge. This number is defined as a constant by the particle algorithm.
Declaration
public override int PinsPerEdge { get; }
Property Value
Type | Description |
---|---|
int |
Overrides
Methods
| Edit this page View SourceCopy()
Creates a full copy of this pin configuration.
All SysPins and SysPartitionSets contained in this pin configuration are copied as well. It is not a deep copy because the reference to the containing Particle stays the same.
Declaration
public SysPinConfiguration Copy()
Returns
Type | Description |
---|---|
SysPinConfiguration | A copy of this pin configuration. |
Equals(object)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
bool | true if the specified object is equal to the current object; otherwise, false. |
Overrides
GenerateSaveData()
Creates a serializable object containing all data needed to restore the pin configuration.
Declaration
public PinConfigurationSaveData GenerateSaveData()
Returns
Type | Description |
---|---|
PinConfigurationSaveData | A serializable representation of this pin configuration. |
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current object. |
Overrides
GetNonEmptyPartitionSets()
Returns all partition sets in the pin configuration that contain at least one pin.
See also GetPartitionSets().
Declaration
public override PartitionSet[] GetNonEmptyPartitionSets()
Returns
Type | Description |
---|---|
PartitionSet[] | An array containing the non-empty partition sets, ordered by their
IDs. The number of returned partition sets is between |
Overrides
| Edit this page View SourceGetPartitionSet(int)
Returns the partition set with the given ID.
Note that the ID of a partition set does not provide any information on the partition set's content. It is merely used to identify and refer to the partition set and to provide more control over which partition sets contain which pins.
Declaration
public override PartitionSet GetPartitionSet(int index)
Parameters
Type | Name | Description |
---|---|---|
int | index | The index of the partition set to get. Must be
in the range |
Returns
Type | Description |
---|---|
PartitionSet | The partition set with the given ID |
Overrides
| Edit this page View SourceGetPartitionSetWithId(int)
Returns the partition set with the given ID.
This is the system-side version of GetPartitionSet(int), which is part of the algorithm developer API.
Declaration
public SysPartitionSet GetPartitionSetWithId(int partitionSetId)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetId | The ID of the partition set to return. |
Returns
Type | Description |
---|---|
SysPartitionSet | The partition set with ID |
GetPartitionSets()
Returns all partition sets in the pin configuration.
Note that the number of partition sets is always equal to NumPins since this is the maximum number of non-empty partition sets. Use GetNonEmptyPartitionSets() to get only the partition sets that contain at least one pin.
Declaration
public override PartitionSet[] GetPartitionSets()
Returns
Type | Description |
---|---|
PartitionSet[] | An array of size NumPins containing all partition sets in this pin configuration. The index of a partition set in this array is its ID. Some of the partition sets may be empty. |
Overrides
| Edit this page View SourceGetPin(int)
Returns the pin with the given ID.
Declaration
public SysPin GetPin(int pinId)
Parameters
Type | Name | Description |
---|---|---|
int | pinId | The ID of the pin to return. |
Returns
Type | Description |
---|---|
SysPin | The pin with ID |
GetPinAt(Direction, int, bool)
Returns the pin with the given offset at the given edge.
Declaration
public override Pin GetPinAt(Direction direction, int offset, bool head = true)
Parameters
Type | Name | Description |
---|---|---|
Direction | direction | The direction of the edge containing the pin. |
int | offset | The pin offset on the specified edge. Must be in
the range |
bool | head | If the expansion state of the pin configuration is expanded, use this flag to indicate whether the edge belongs to the particle's head or not. |
Returns
Type | Description |
---|---|
Pin | The pin in the specified location. |
Overrides
| Edit this page View SourceGetPinId(Direction, int, bool)
Computes the ID of the pin on the specified edge with the given offset.
The formula for the pin ID is label * pinsPerEdge +
, where offset
label
is computed
using direction
and head
.
Declaration
public int GetPinId(Direction direction, int offset, bool head = true)
Parameters
Type | Name | Description |
---|---|---|
Direction | direction | The local direction of the edge. |
int | offset | The edge offset of the pin. |
bool | head | If the pin configuration represents the expanded state, this flag indicates whether the edge belongs to the particle's head or not. |
Returns
Type | Description |
---|---|
int | The ID of the pin in the location specified by an edge and an edge offset. |
GetPinsAtEdge(Direction, bool)
Returns all pins at the given edge.
Declaration
public override Pin[] GetPinsAtEdge(Direction direction, bool head = true)
Parameters
Type | Name | Description |
---|---|---|
Direction | direction | The direction of the edge containing the pins. |
bool | head | If the expansion state of the pin configuration is expanded, use this flag to indicate whether the edge belongs to the particle's head or not. |
Returns
Type | Description |
---|---|
Pin[] | An array of size PinsPerEdge containing the pins at the specified edge, ordered by their edge offsets. |
Overrides
| Edit this page View SourceGetReceivedMessageOfPSet(int)
Returns the message received by the specified partition set, if it has received a message and this pin configuration is the current one.
Declaration
public Message GetReceivedMessageOfPSet(int partitionSetID)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetID | The ID of the partition set to get the message from. |
Returns
Type | Description |
---|---|
Message | A Message instance received by the partition set
with ID |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this pin configuration is not the current one. |
MakePartitionSet(Pin[], PartitionSet)
Same as MakePartitionSet(int[], int), but the pins and the partition set are specified directly and not by their IDs. The array of pins will not be sorted.
Declaration
public override void MakePartitionSet(Pin[] pins, PartitionSet partitionSet)
Parameters
Type | Name | Description |
---|---|---|
Pin[] | pins | The pins to be put into the given partition set. |
PartitionSet | partitionSet |
Overrides
| Edit this page View SourceMakePartitionSet(Pin[], int)
Same as MakePartitionSet(int[], int), but the pins are specified directly and not by their IDs. The array will not be sorted.
Declaration
public override void MakePartitionSet(Pin[] pins, int partitionSetIndex)
Parameters
Type | Name | Description |
---|---|---|
Pin[] | pins | The pins to be put into the specified partition set. |
int | partitionSetIndex | The ID of the partition set that should hold the given set of pins. |
Overrides
| Edit this page View SourceMakePartitionSet(int[], PartitionSet)
Same as MakePartitionSet(int[], int), but the partition set is specified directly instead of by its ID.
Declaration
public override void MakePartitionSet(int[] pinIds, PartitionSet partitionSet)
Parameters
Type | Name | Description |
---|---|---|
int[] | pinIds | The IDs of the pins to be put into the given partition set. |
PartitionSet | partitionSet | The partition set that should hold the specified set of pins. |
Overrides
| Edit this page View SourceMakePartitionSet(int[], int)
Sets the specified partition set to contain exactly the given pins.
If the partition set already contains any pins that are not part of
the given set, they are removed and put into their own singleton
sets. If pinIds
is empty, it may be impossible
to put every removed pin into a singleton set, in which case an
exception is thrown.
The pinIds
array will be sorted in ascending
order.
Declaration
public override void MakePartitionSet(int[] pinIds, int partitionSetIndex)
Parameters
Type | Name | Description |
---|---|---|
int[] | pinIds | The IDs of the pins to be put into the specified partition set. |
int | partitionSetIndex | The ID of the partition set that should hold the specified set of pins. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if |
Print()
Declaration
public void Print()
ReceivedBeepOnPSet(int)
Checks whether the particle has received a beep on the given partition set. Only works if this pin configuration is the current one.
Declaration
public bool ReceivedBeepOnPSet(int partitionSetID)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetID | The ID of the partition set to check. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this is not the current pin configuration. |
ReceivedMessageOnPSet(int)
Checks whether the particle has received a message on the given partition set. Only works if this pin configuration is the current one.
Declaration
public bool ReceivedMessageOnPSet(int partitionSetID)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetID | The ID of the partition set to check. |
Returns
Type | Description |
---|---|
bool |
|
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this is not the current pin configuration. |
ResetAllPartitionSetColors()
Resets the color overrides of all partition sets.
Declaration
public override void ResetAllPartitionSetColors()
Overrides
| Edit this page View SourceResetPartitionSetColor(int)
Resets the specified partition set's color override.
Declaration
public override void ResetPartitionSetColor(int partitionSetIndex)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetIndex | The ID of the partition set whose color override to reset. |
Overrides
| Edit this page View SourceResetPartitionSetDrawHandle(bool)
Resets the handle draw flags of all partition sets in the given
part of the particle to false
.
Declaration
public override void ResetPartitionSetDrawHandle(bool head = true)
Parameters
Type | Name | Description |
---|---|---|
bool | head | Whether the flag should be reset in the particle's head or tail. |
Overrides
| Edit this page View SourceResetPartitionSetPlacement(bool)
Resets the positions of the partition sets and sets the placement mode to NONE in the particle's head or tail.
Declaration
public override void ResetPartitionSetPlacement(bool head = true)
Parameters
Type | Name | Description |
---|---|---|
bool | head | Indicates whether the partition sets should be reset in the particle's head or tail. |
Overrides
| Edit this page View SourceSendBeepOnPSet(int)
Sends a beep on the specified partition set, if this is the next pin configuration.
Declaration
public void SendBeepOnPSet(int partitionSetID)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetID | The ID of the partition set on which to send the beep. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this pin configuration is not the next one. |
SendBeepOnPin(int)
Sends a beep on the specified pin, if this is the next pin configuration.
Declaration
public void SendBeepOnPin(int pinID)
Parameters
Type | Name | Description |
---|---|---|
int | pinID | The ID of the pin on which to send the beep. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this pin configuration is not the next one. |
SendMessageOnPSet(int, Message)
Sends the given message on the specified partition set, if this pin configuration is the next one.
Note that a copy of the given Message instance
msg
is sent. Altering the instance after calling
this method has no effect on the sent message.
Declaration
public void SendMessageOnPSet(int partitionSetID, Message msg)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetID | The ID of the partition set on which to send the message. |
Message | msg | The message to be sent. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this pin configuration is not the next one. |
SendMessageOnPin(int, Message)
Sends the given message on the specified pin, if this pin configuration is the next one.
Note that a copy of the given Message instance
msg
is sent. Altering the instance after calling
this method has no effect on the sent message.
Declaration
public void SendMessageOnPin(int pinID, Message msg)
Parameters
Type | Name | Description |
---|---|---|
int | pinID | The ID of the pin on which to send the message. |
Message | msg | The message to be sent. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this pin configuration is not the next one. |
SetLineRotation(float, bool)
Sets the rotation of the line on which the partition sets are arranged in LINE mode. Multiples of 30 or 60 degrees will usually look best. The placement mode is changed automatically.
Declaration
public override void SetLineRotation(float angle, bool head = true)
Parameters
Type | Name | Description |
---|---|---|
float | angle | The new angle of the line in degrees.
|
bool | head | Indicates whether the rotation for the
particle's head or tail part should be set. Must be
|
Overrides
| Edit this page View SourceSetPSPlacementMode(PSPlacementMode, bool)
Sets the partition set placement mode to the given value.
Declaration
public override void SetPSPlacementMode(PSPlacementMode mode, bool head = true)
Parameters
Type | Name | Description |
---|---|---|
PSPlacementMode | mode | The new partition set placement mode. |
bool | head | Indicates whether the placement mode for the particle's head or tail will be set. |
Overrides
| Edit this page View SourceSetPartitionSetColor(int, Color)
Overrides the specified partition set's color. The circuit to which the partition set belongs will be displayed in this color unless it has been overridden by another partition set already.
See also ResetPartitionSetColor(int).
Declaration
public override void SetPartitionSetColor(int partitionSetIndex, Color color)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetIndex | The ID of the partition set whose color to override. |
Color | color | The color to set for the partition set. |
Overrides
| Edit this page View SourceSetPartitionSetDrawHandle(int, bool)
Specifies whether the given partition set should always be drawn with a handle, even if it is a singleton set (but not if it is empty).
Declaration
public override void SetPartitionSetDrawHandle(int partitionSetIndex, bool drawHandle)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetIndex | The ID of the partition set whose handle draw setting to override. |
bool | drawHandle | Whether the handle should always be drawn. |
Overrides
| Edit this page View SourceSetPartitionSetPosition(int, Vector2, bool)
Sets the specified partition set's position in polar coordinates and sets the positioning mode of the pin configuration to MANUAL.
Declaration
public override void SetPartitionSetPosition(int partitionSetIndex, Vector2 polarCoords, bool head = true)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetIndex | The ID of the partition set whose position to set. |
Vector2 | polarCoords | The polar coordinates of the partition
set's position inside of the particle as |
bool | head | Indicates whether the position in the
particle's head or tail should be set. For contracted particles,
this should be |
Overrides
| Edit this page View SourceSetStarConfig(int, PartitionSet)
Same as SetStarConfig(int, int), but the partition set is specified directly and not by its ID.
Declaration
public override void SetStarConfig(int offset, PartitionSet partitionSet)
Parameters
Type | Name | Description |
---|---|---|
int | offset | The edge offset of the pins to be collected in the star partition set. |
PartitionSet | partitionSet | The partition set that should hold the star pattern. |
Overrides
| Edit this page View SourceSetStarConfig(int, bool[], PartitionSet)
Same as SetStarConfig(int, bool[], int), but the partition set is specified directly and not by its ID.
Declaration
public override void SetStarConfig(int offset, bool[] inverted, PartitionSet partitionSet)
Parameters
Type | Name | Description |
---|---|---|
int | offset | The edge offset of the pins to be collected in the star partition set. |
bool[] | inverted | Array specifying for which edges the
offset should be inverted. For any edge with a |
PartitionSet | partitionSet | The partition set that should hold the star pattern. |
Overrides
| Edit this page View SourceSetStarConfig(int, bool[], int)
Sets the specified partition set to contain all pins with
the given edge offset offset
, where the
offsets of certain edges are inverted as specified by the
inverted
array.
This is an extension of the basic SetStarConfig(int, int) method.
Declaration
public override void SetStarConfig(int offset, bool[] inverted, int partitionSetIndex)
Parameters
Type | Name | Description |
---|---|---|
int | offset | The edge offset of the pins to be collected in the star partition set. |
bool[] | inverted | Array specifying for which edges the
offset should be inverted. For any edge with a |
int | partitionSetIndex | The ID of the partition set that should hold the star pattern. |
Overrides
| Edit this page View SourceSetStarConfig(int, int)
Sets the specified partition set to contain all pins with
the given edge offset offset
.
The partition set will thus contain exactly one pin for each edge. If it already contains any pins that do not have this offset, they are removed and put into their own singleton sets.
See also SetStarConfig(int, PartitionSet), SetStarConfig(int, bool[], int).
Declaration
public override void SetStarConfig(int offset, int partitionSetIndex)
Parameters
Type | Name | Description |
---|---|---|
int | offset | The edge offset of the pins to be collected in the star partition set. |
int | partitionSetIndex | The ID of the partition set that should hold the star pattern. |
Overrides
| Edit this page View SourceSetToGlobal(PartitionSet)
Same as SetToGlobal(int), but the partition set to hold the pins is specified directly instead of by its ID.
Declaration
public override void SetToGlobal(PartitionSet partitionSet)
Parameters
Type | Name | Description |
---|---|---|
PartitionSet | partitionSet | The partition set that should hold all pins. |
Overrides
| Edit this page View SourceSetToGlobal(int)
Sets the pin configuration to the global pattern.
In the global pattern, all pins are contained in a single partition set. If all particles in a connected system have this pin configuration, they form a global circuit on all pins simultaneously.
Declaration
public override void SetToGlobal(int partitionSetId = 0)
Parameters
Type | Name | Description |
---|---|---|
int | partitionSetId | The ID of the partition set that should hold the pins. |
Overrides
| Edit this page View SourceSetToSingleton()
Sets the pin configuration to the singleton pattern.
In the singleton pattern, every pin constitutes its own
partition set of size 1
, i.e., there are no connections
between any pins.
Additionally, in this implementation, the pins are assigned to the partition sets such that their IDs match.
Declaration
public override void SetToSingleton()
Overrides
| Edit this page View SourceTryRemovePin(int)
Tries to remove the specified pin from its partition set and insert it into an empty partition set.
Throws a System.InvalidOperationException if no empty partition set can be found.
Declaration
public void TryRemovePin(int pinId)
Parameters
Type | Name | Description |
---|---|---|
int | pinId | The ID of the pin to be removed from its partition set. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the pin is the only one in this partition set and no other partition set is empty. |
TryRemovePins(int[])
Tries to remove the specified pins from their partition set and insert them into empty partition sets.
It is assumed that the pins should all be removed from the same partition set.
Throws a System.InvalidOperationException if at any point, no empty partition set can be found.
Declaration
public void TryRemovePins(int[] pinIds)
Parameters
Type | Name | Description |
---|---|---|
int[] | pinIds | The IDs of the pins to be removed from their partition set. Must all be from the same partition set. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if one of the pins is the last one in the partition set and no other partition set is empty. |
UpdateFlagsAfterChange()
Resets curr flag to false
because the pin configuration was altered.
Declaration
private void UpdateFlagsAfterChange()
Operators
| Edit this page View Sourceoperator ==(SysPinConfiguration, SysPinConfiguration)
Declaration
public static bool operator ==(SysPinConfiguration pc1, SysPinConfiguration pc2)
Parameters
Type | Name | Description |
---|---|---|
SysPinConfiguration | pc1 | |
SysPinConfiguration | pc2 |
Returns
Type | Description |
---|---|
bool |
operator !=(SysPinConfiguration, SysPinConfiguration)
Declaration
public static bool operator !=(SysPinConfiguration pc1, SysPinConfiguration pc2)
Parameters
Type | Name | Description |
---|---|---|
SysPinConfiguration | pc1 | |
SysPinConfiguration | pc2 |
Returns
Type | Description |
---|---|
bool |