Example #1
0
 public OrganelleTemplate(OrganelleDefinition definition, Hex location, int rotation, int numberOfTimesMoved = 0)
 {
     Definition         = definition;
     Position           = location;
     Orientation        = rotation;
     NumberOfTimesMoved = numberOfTimesMoved;
 }
Example #2
0
 /// <summary>
 ///   Adds a new organelle to a mutation result
 /// </summary>
 private void AddNewOrganelle(OrganelleLayout <OrganelleTemplate> organelles,
                              OrganelleDefinition organelle)
 {
     try
     {
         organelles.Add(GetRealisticPosition(organelle, organelles));
     }
     catch (ArgumentException)
     {
         // Failing to add a mutation is not serious
     }
 }
Example #3
0
    private OrganelleTemplate GetRealisticPosition(OrganelleDefinition organelle,
                                                   OrganelleLayout <OrganelleTemplate> existingOrganelles)
    {
        var result = new OrganelleTemplate(organelle, new Hex(0, 0), 0);

        // Loop through all the organelles and find an open spot to
        // place our new organelle attached to existing organelles
        // This almost always is over at the first iteration, so its
        // not a huge performance hog
        foreach (var otherOrganelle in existingOrganelles.OrderBy(_ => random.Next()))
        {
            // The otherOrganelle is the organelle we wish to be next to
            // Loop its hexes and check positions next to them
            foreach (var hex in otherOrganelle.RotatedHexes)
            {
                // Offset by hexes in organelle we are looking at
                var pos = otherOrganelle.Position + hex;

                for (int side = 1; side <= 6; ++side)
                {
                    for (int radius = 1; radius <= 3; ++radius)
                    {
                        // Offset by hex offset multiplied by a factor to check for greater range
                        var hexOffset = Hex.HexNeighbourOffset[(Hex.HexSide)side];
                        hexOffset      *= radius;
                        result.Position = pos + hexOffset;

                        // Check every possible rotation value.
                        for (int rotation = 0; rotation <= 5; ++rotation)
                        {
                            result.Orientation = rotation;

                            if (existingOrganelles.CanPlace(result))
                            {
                                return(result);
                            }
                        }
                    }
                }
            }
        }

        // We didnt find an open spot, this doesn't make much sense
        throw new ArgumentException("Mutation code could not find a good position " +
                                    "for a new organelle");
    }
Example #4
0
    /// <summary>
    ///   Returns true if organelle can be placed at location
    /// </summary>
    public bool CanPlace(OrganelleDefinition organelleType, Hex position, int orientation,
                         bool allowCytoplasmOverlap = false)
    {
        // Check for overlapping hexes with existing organelles
        foreach (var hex in organelleType.GetRotatedHexes(orientation))
        {
            var overlapping = GetOrganelleAt(hex + position);
            if (overlapping != null && (allowCytoplasmOverlap == false ||
                                        overlapping.Definition.InternalName != "cytoplasm"))
            {
                return(false);
            }
        }

        // Basic placing doesn't have the restriction that the
        // organelle needs to touch an existing one
        return(true);
    }
Example #5
0
 public OrganelleTemplate(OrganelleDefinition definition, Hex location, int rotation)
 {
     Definition  = definition;
     Position    = location;
     Orientation = rotation;
 }
Example #6
0
 public OrganelleEfficiency(OrganelleDefinition organelle)
 {
     Organelle = organelle;
 }
Example #7
0
 public PlacedOrganelle(OrganelleDefinition definition, Hex position, int orientation)
 {
     Definition  = definition;
     Position    = position;
     Orientation = orientation;
 }