Beispiel #1
0
    private static int AwardPoints(StackMeta permutation, StackMeta target)
    {
        int pointCompletelyCorrect = 3;
        int pointCorrectPos        = 1;
        int pointsAwarded          = 0;

        if (permutation.ChipCount() < target.ChipCount())
        {
            return(pointsAwarded);
        }
        for (int i = 0; i < target.ChipCount(); i++)
        {
            ChipMeta targetMeta      = target.GetChipMetaAt(i);
            ChipMeta permutationMeta = permutation.GetChipMetaAt(i);
            if (targetMeta.prefabId == permutationMeta.prefabId)
            {
                if (targetMeta.orientation == permutationMeta.orientation)
                {
                    pointsAwarded += pointCompletelyCorrect;
                }
                else
                {
                    pointsAwarded += pointCorrectPos;
                }
            }
        }
        return(pointsAwarded);
    }
Beispiel #2
0
    //Creates a deep copy
    public ChipMeta Copy()
    {
        ChipMeta copy = new ChipMeta(prefabId, orientation, isOrientationImportant, stackPos, Height, CrushWeight);

        copy.Height = Height;
        return(copy);
    }
Beispiel #3
0
    public bool CanMatch(StackMeta other)
    {
        StackMeta targetStack    = isTargetStack ? this : other;
        StackMeta flippableStack = isTargetStack ? other : this;

        if (targetStack.ChipCount() > flippableStack.ChipCount())
        {
            return(false);
        }

        Dictionary <string, int> target    = targetStack.MapByIdAndCrushWeight();
        Dictionary <string, int> flippable = flippableStack.MapByIdAndCrushWeight();

        if (AnyTargetChipsMissingInFlippable(target, flippable))
        {
            return(false);
        }

        if (flippableStack.ChipCount() > targetStack.ChipCount())
        {
            for (int i = 0; i < flippableStack.ChipCount(); i++)
            {
                ChipMeta chipMeta = flippableStack.GetChipMetaAt(i);
                if (chipMeta.IsCrushable && flippableStack.ChipCount() <= chipMeta.CrushWeight &&
                    !target.ContainsKey(StringifyChipMeta(chipMeta)))
                {
                    return(false);
                }
            }
        }

        return(true);
    }
Beispiel #4
0
    public bool Matches(StackMeta other)
    {
        if (other.chips.Count != chips.Count)
        {
            return(false);
        }

        for (int i = 0; i < chips.Count; i++)
        {
            ChipMeta thisChip  = chips [i];
            ChipMeta otherChip = other.chips [i];
            if (thisChip.prefabId != otherChip.prefabId)
            {
                return(false);
            }
            if (thisChip.isOrientationImportant && thisChip.orientation != otherChip.orientation)
            {
                return(false);
            }
            if (thisChip.CrushWeight != otherChip.CrushWeight)
            {
                return(false);
            }
        }

        return(true);
    }
Beispiel #5
0
 private bool CanBeCrushed(ChipMeta chipMeta, int totalStackWeight)
 {
     if (chipMeta.IsCrushable)
     {
         return(chipMeta.CrushWeight <= (totalStackWeight - chipMeta.Weight));
     }
     return(false);
 }
Beispiel #6
0
 private Chip GetChipForChipMeta(ChipMeta chipMeta)
 {
     for (int i = 0; i < transform.childCount; i++)
     {
         Chip chip = transform.GetChild(i).GetComponent <Chip> ();
         if (chip != null && chip.chipMeta == chipMeta)
         {
             return(chip);
         }
     }
     return(null);
 }
Beispiel #7
0
 private bool CanChipsThatShouldBeCrushedBeCrushedWithTheRemainingStack(StackMeta flippableStack, StackMeta targetStack, Dictionary <string, int> target)
 {
     for (int i = 0; i < flippableStack.ChipCount(); i++)
     {
         ChipMeta chipMeta = flippableStack.GetChipMetaAt(i);
         if (chipMeta.IsCrushable &&
             !CanBeCrushed(chipMeta, flippableStack.ChipCount()) &&
             !target.ContainsKey(StringifyChipMeta(chipMeta)))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #8
0
 public ChipMeta RemoveAt(int position)
 {
     if (0 <= position && position < chips.Count)
     {
         ChipMeta toRemove = chips[position];
         chips.RemoveAt(position);
         for (int i = position; i < chips.Count; i++)
         {
             ChipMeta chip = chips [i];
             chip.stackPos = i;
         }
         return(toRemove);
     }
     return(null);
 }
Beispiel #9
0
    public string ToStringShort()
    {
        string output = "size: " + ChipCount() + ", isTarget: " + isTargetStack + ", chips: [";

        for (int i = 0; i < chips.Count; i++)
        {
            ChipMeta chip = chips [i];
            output += "\n" + chip.ToStringShort();
            if (i != chips.Count - 1)
            {
                output += ", ";
            }
        }
        output += "]";
        return(output);
    }
Beispiel #10
0
    public CrushChipsMeta FlipStackAt(int position)             //Doesn't actually flip the UI stack, only flips the the chips meta
    {
        ReverseOrderAt(position, chips);
        for (int i = position; i < chips.Count; i++)
        {
            ChipMeta chip = chips [i];
            chip.Flip();
            chip.stackPos = i;
        }

        CrushChipsMeta crushingChips = CheckForCrushingChips(position);

        foreach (ChipMeta meta in crushingChips.crushedChips)
        {
            RemoveAt(meta.stackPos);
        }
        return(crushingChips);
    }
    public void TestRemoveChip()
    {
        StackMeta stack = GetStackMetaOf5();

        Debug.Log("stack: " + stack.ToStringShort());
        int      initalCount = 5;
        ChipMeta chip        = stack.GetChipMetaAt(initalCount - 1);

        stack.RemoveAt(stack.ChipCount() - 1);
        TestManager.AssertEquals(stack.ChipCount(), initalCount - 1, "TestRemoveChip");
        chip = stack.GetChipMetaAt(2);
        stack.RemoveAt(2);
        for (int i = 0; i < stack.ChipCount(); i++)
        {
            ChipMeta chipI = stack.GetChipMetaAt(i);
            stack.RemoveAt(i);
            TestManager.AssertEquals(i, chipI.stackPos, "TestRemoveChip stack pos is not the same");
        }
    }
Beispiel #12
0
    public static List <ChipMeta> ReverseOrderAt(int position, List <ChipMeta> list)
    {
        if (position == list.Count - 1)
        {
            return(list);
        }

        int end     = ((list.Count - position) / 2) + position;
        int counter = 0;

        for (int pos1 = position; pos1 < end; pos1++)
        {
            int      pos2  = list.Count - 1 - counter++;
            ChipMeta chip1 = list [pos1];
            ChipMeta chip2 = list [pos2];
            list [pos1] = chip2;
            list [pos2] = chip1;
        }
        return(list);
    }
Beispiel #13
0
    public static GameStacksMeta CreateFromGameGeneratorMeta(GameGeneratorMeta meta, PrefabsManager manager)
    {
        StackMeta startStack = new StackMeta();

        for (int i = 0; i < meta.ChipIDs.Length; i++)
        {
            ChipMeta chipMeta = manager.GetChipMeta(meta.ChipIDs [i]);
            chipMeta.CrushWeight = meta.CrushWeights [i];
            if (meta.InitFlips [i])
            {
                chipMeta.Flip();
            }
            startStack.Add(chipMeta);
        }
        startStack.CleanupStackForCrushedChips(0);

        StackMeta targetStack = startStack.Copy();

        targetStack.Permute(meta.Flips);

        return(new GameStacksMeta(startStack, targetStack, meta.Flips.Length));
    }
Beispiel #14
0
 string StringifyChipMeta(ChipMeta meta)
 {
     return(string.Format("{0}#{1}", meta.prefabId, meta.CrushWeight));
 }
Beispiel #15
0
 public void Add(ChipMeta chipMeta)
 {
     chips.Add(chipMeta);
     chipMeta.stackPos = chips.Count - 1;
 }