public void TestFlipMiddle() { Debug.Log("Test flip middle"); StackMeta stack = GetStackMetaOf5(); Debug.Log("Before flip at top: " + stack.ToStringShort()); stack.FlipStackAt(1); Debug.Log("After flip at top: " + stack.ToStringShort()); TestManager.AssertTrue(stack.GetChipMetaAt(0).prefabId == 11, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(0).orientation == ChipOrientation.UP, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(0).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(0).stackPos == 0, "Wrong stackpos"); TestManager.AssertTrue(stack.GetChipMetaAt(1).prefabId == 15, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(1).orientation == ChipOrientation.DOWN, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(1).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(1).stackPos == 1, "Wrong stackpos"); TestManager.AssertTrue(stack.GetChipMetaAt(2).prefabId == 14, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(2).orientation == ChipOrientation.DOWN, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(2).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(2).stackPos == 2, "Wrong stackpos"); TestManager.AssertTrue(stack.GetChipMetaAt(3).prefabId == 13, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(3).orientation == ChipOrientation.DOWN, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(3).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(3).stackPos == 3, "Wrong stackpos"); TestManager.AssertTrue(stack.GetChipMetaAt(4).prefabId == 12, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(4).orientation == ChipOrientation.DOWN, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(4).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(4).stackPos == 4, "Wrong stackpos"); }
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); }
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); }
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); }
public void TestFlipStack() { Debug.Log("Test flip stack start"); StackMeta stack = GetStackMetaOf5(); Debug.Log("Before flip at 0: " + stack.ToStringShort()); stack.FlipStackAt(0); Debug.Log("After flip at 0: " + stack.ToStringShort()); TestManager.AssertEquals(stack.GetChipMetaAt(0).prefabId, 15, ""); TestManager.AssertEquals(stack.GetChipMetaAt(1).prefabId, 14, ""); TestManager.AssertEquals(stack.GetChipMetaAt(2).prefabId, 13, ""); TestManager.AssertEquals(stack.GetChipMetaAt(3).prefabId, 12, ""); TestManager.AssertEquals(stack.GetChipMetaAt(4).prefabId, 11, ""); TestManager.AssertTrue(stack.GetChipMetaAt(0).orientation == ChipOrientation.DOWN, ""); TestManager.AssertTrue(stack.GetChipMetaAt(1).orientation == ChipOrientation.DOWN, ""); TestManager.AssertTrue(stack.GetChipMetaAt(2).orientation == ChipOrientation.DOWN, ""); TestManager.AssertTrue(stack.GetChipMetaAt(3).orientation == ChipOrientation.DOWN, ""); TestManager.AssertTrue(stack.GetChipMetaAt(4).orientation == ChipOrientation.DOWN, ""); TestManager.AssertEquals(stack.GetChipMetaAt(0).stackPos, 0, ""); TestManager.AssertEquals(stack.GetChipMetaAt(1).stackPos, 1, ""); TestManager.AssertEquals(stack.GetChipMetaAt(2).stackPos, 2, ""); TestManager.AssertEquals(stack.GetChipMetaAt(3).stackPos, 3, ""); TestManager.AssertEquals(stack.GetChipMetaAt(4).stackPos, 4, ""); }
public void TestDemoStack() { StackMeta stack = GetStackMetaOf5(); TestManager.AssertTrue(stack.GetChipMetaAt(0).prefabId == 11, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(0).orientation == ChipOrientation.UP, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(0).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(0).stackPos == 0, "Wrong stackpos"); TestManager.AssertTrue(stack.GetChipMetaAt(1).prefabId == 12, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(1).orientation == ChipOrientation.UP, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(1).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(1).stackPos == 1, "Wrong stackpos"); TestManager.AssertTrue(stack.GetChipMetaAt(2).prefabId == 13, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(2).orientation == ChipOrientation.UP, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(2).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(2).stackPos == 2, "Wrong stackpos"); TestManager.AssertTrue(stack.GetChipMetaAt(3).prefabId == 14, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(3).orientation == ChipOrientation.UP, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(3).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(3).stackPos == 3, "Wrong stackpos"); TestManager.AssertTrue(stack.GetChipMetaAt(4).prefabId == 15, "Wrong prefabid"); TestManager.AssertTrue(stack.GetChipMetaAt(4).orientation == ChipOrientation.UP, "Wrong orientation"); TestManager.AssertTrue(stack.GetChipMetaAt(4).isOrientationImportant == false, "Orientation shouldn't be important"); TestManager.AssertTrue(stack.GetChipMetaAt(4).stackPos == 4, "Wrong stackpos"); }
private StackMeta GetStackMetaOf5WithOrientation() { StackMeta stack = new StackMeta(); stack.Add(new ChipMeta(11, ChipOrientation.UP, true, 11, 0.2f)); stack.Add(new ChipMeta(12, ChipOrientation.UP, true, 11, 0.2f)); stack.Add(new ChipMeta(13, ChipOrientation.UP, true, 11, 0.2f)); stack.Add(new ChipMeta(14, ChipOrientation.UP, true, 11, 0.2f)); stack.Add(new ChipMeta(15, ChipOrientation.UP, true, 11, 0.2f)); return(stack); }
public void TestAddChip() { StackMeta stack = new StackMeta(); TestManager.AssertEquals(stack.ChipCount(), 0, "TestAddChip"); stack.Add(new ChipMeta(11, ChipOrientation.UP, false, 12, 0.2f)); TestManager.AssertEquals(stack.ChipCount(), 1, "TestAddChip"); TestManager.AssertEquals(stack.GetChipMetaAt(0).stackPos, 0, "TestAddChip"); stack.Add(new ChipMeta(21, ChipOrientation.UP, false, 122, 0.2f)); TestManager.AssertEquals(stack.GetChipMetaAt(1).stackPos, 1, "TestAddChip"); }
//Create a deep copy public StackMeta Copy() { StackMeta copy = new StackMeta(); copy.isTargetStack = isTargetStack; foreach (ChipMeta chipmeta in chips) { copy.chips.Add(chipmeta.Copy()); } return(copy); }
private static List <PointClass> AwardPoints(List <StackMeta> permutations, StackMeta target) { List <PointClass> points = new List <PointClass> (); for (int i = 0; i < permutations.Count; i++) { StackMeta permutation = permutations [i]; points.Add(new PointClass(i, AwardPoints(permutation, target))); } return(points); }
private static List <StackMeta> PermuteStack(StackMeta stack) { List <StackMeta> permutations = new List <StackMeta> (); for (int i = 0; i < stack.ChipCount(); i++) { StackMeta copy = stack.Copy(); copy.FlipStackAt(i); permutations.Add(copy); } return(permutations); }
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); }
public void TestMatchesOrientationIsImportant() { Debug.Log("Test Matches Orientation Is Important"); StackMeta stack1 = GetStackMetaOf5WithOrientation(); StackMeta stack2 = GetStackMetaOf5WithOrientation(); TestManager.AssertTrue(stack1.Matches(stack2), "Should match"); TestManager.AssertTrue(stack2.Matches(stack1), "Should match"); TestManager.AssertTrue(stack1.Matches(stack1), "Should match"); stack2.GetChipMetaAt(0).Flip(); TestManager.AssertFalse(stack1.Matches(stack2), "Shouldn't match"); TestManager.AssertFalse(stack2.Matches(stack1), "Shouldn't match"); }
public void TestFlipStackJustTop() { Debug.Log("Test flip stack just top"); StackMeta stack = GetStackMetaOf5(); Debug.Log("Before flip at top: " + stack.ToStringShort()); stack.FlipStackAt(stack.ChipCount() - 1); Debug.Log("After flip at top: " + stack.ToStringShort()); TestManager.AssertTrue(stack.GetChipMetaAt(0).orientation == ChipOrientation.UP, "Wrong orientation for chip"); TestManager.AssertTrue(stack.GetChipMetaAt(1).orientation == ChipOrientation.UP, "Wrong orientation for chip"); TestManager.AssertTrue(stack.GetChipMetaAt(2).orientation == ChipOrientation.UP, "Wrong orientation for chip"); TestManager.AssertTrue(stack.GetChipMetaAt(3).orientation == ChipOrientation.UP, "Wrong orientation for chip"); TestManager.AssertTrue(stack.GetChipMetaAt(4).orientation == ChipOrientation.DOWN, "Wrong orientation for chip"); TestManager.AssertEquals(stack.GetChipMetaAt(4).stackPos, 4, "Wrong stackpos for chip"); TestManager.AssertEquals(stack.GetChipMetaAt(4).prefabId, 15, "Wrong prefabid"); }
public void TestMatchesOrientationNotImportant() { Debug.Log("Test Matches Orientation Not Important"); StackMeta stack1 = GetStackMetaOf5(); StackMeta stack2 = GetStackMetaOf5(); TestManager.AssertTrue(stack1.Matches(stack2), "Stack1 and Stack2 should match"); TestManager.AssertTrue(stack1.Matches(stack1), "Stack1 and Stack2 should match"); TestManager.AssertTrue(stack1.Matches(stack1), "Stack1 and Stack2 should match"); stack2.FlipStackAt(3); TestManager.AssertFalse(stack1.Matches(stack2), "Stack1 and stack2 shouldn't match"); TestManager.AssertFalse(stack2.Matches(stack1), "Stack1 and stack2 shouldn't match"); stack2.FlipStackAt(3); TestManager.AssertTrue(stack1.Matches(stack2), "Stack1 and Stack2 should match"); TestManager.AssertTrue(stack1.Matches(stack1), "Stack1 and Stack2 should match"); }
private Stack BuildStackFromStackMeta(StackMeta stackMeta, PrefabsManager prefabsManager) { Stack stack = prefabsManager.CreateStack(); for (int i = 0; i < stackMeta.ChipCount(); i++) { int prefabId = stackMeta.GetChipMetaAt(i).prefabId; Chip chip = prefabsManager.GetChip(prefabId); stack.Add(chip); chip.chipMeta.CrushWeight = stackMeta.GetChipMetaAt(i).CrushWeight; if (chip.chipMeta.orientation != stackMeta.GetChipMetaAt(i).orientation) { chip.chipMeta.Flip(); chip.transform.localRotation = Quaternion.Euler(180f, 0f, 0f); } } return(stack); }
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"); } }
public static int CalculateMinFlips(StackMeta start, StackMeta target, int maxToKeep, int maxFlips) { int permutationCounter = 1; List <StackMeta> toKeep = new List <StackMeta> (); toKeep.Add(start); while (permutationCounter < maxFlips) { List <StackMeta> permuteAll = PermuteStacks(toKeep); List <PointClass> points = AwardPoints(permuteAll, target); toKeep = FilterOut(permuteAll, points, maxToKeep); for (int i = 0; i < toKeep.Count; i++) { if (toKeep [i].Matches(target)) { return(permutationCounter); } } permutationCounter++; } return(permutationCounter); }
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)); }
public GameStacksMeta(StackMeta start, StackMeta target, int nFlips) { this.start = start; this.target = target; this.nFlips = nFlips; }
public static void HandleAchievements(SingleGameStatsMeta statsMeta, StackMeta stackMeta) { if (ApplicationModel.achievements == null) { Debug.Log("<color=blue>The achievements hasn't been retrieved. This indicated that the player hasn't signed in using google play games services</color>"); return; } #if UNITY_ANDROID || UNITY_IOS IAchievement newbie = ApplicationModel.GetAchievement(GPGSIds.achievement_newbie); if (!newbie.completed) { PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_newbie, 1, (bool success) => { if (success) { Debug.Log("Successfully updated the newbie-achievement"); } else { //Store locally } }); } IAchievement fanish = ApplicationModel.GetAchievement(GPGSIds.achievement_fanish); if (!fanish.completed) { PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_fanish, 1, (bool success) => { if (success) { Debug.Log("Successfully updated the fanish-achievement"); } else { //Store locally } }); } IAchievement megaFan = ApplicationModel.GetAchievement(GPGSIds.achievement_mega_fan); if (!megaFan.completed) { PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_mega_fan, 1, (bool success) => { if (success) { Debug.Log("Successfully updated the mega fan-achievement"); } else { //Store locally } }); } IAchievement luckyDuck = ApplicationModel.GetAchievement(GPGSIds.achievement_lucky_duck); if (!luckyDuck.completed && AchievementRules.IsLuckyDuckAccomplished(statsMeta.SuccessfullGame, statsMeta.NFlips)) { Social.ReportProgress(GPGSIds.achievement_lucky_duck, 100.0f, (bool success) => { if (success) { Debug.Log("Successfully set the lucky duck achievement"); } else { //Store locally } }); } IAchievement speedster = ApplicationModel.GetAchievement(GPGSIds.achievement_speedster); if (!speedster.completed && AchievementRules.IsSpeedsterAccomplished(statsMeta.SuccessfullGame, statsMeta.Time)) { Social.ReportProgress(GPGSIds.achievement_speedster, 100.0f, (bool success) => { if (success) { Debug.Log("Successfully set the lucky duck achievement"); } else { //Store locally } }); } IAchievement brainiac = ApplicationModel.GetAchievement(GPGSIds.achievement_brainiac); if (!brainiac.completed && AchievementRules.IsBrainiacAccomplished(statsMeta.SuccessfullGame, stackMeta.ChipCount())) { Social.ReportProgress(GPGSIds.achievement_brainiac, 100.0f, (bool success) => { if (success) { Debug.Log("Successfully set the brainiac achievement"); } else { //Store locally } }); } IAchievement eideticMemory = ApplicationModel.GetAchievement(GPGSIds.achievement_eidetic_memory); if (!eideticMemory.completed && IsEideticMemoryAccomplished(statsMeta.SuccessfullGame, statsMeta.NTargetChecks, stackMeta.ChipCount())) { Social.ReportProgress(GPGSIds.achievement_eidetic_memory, 100.0f, (bool success) => { if (success) { Debug.Log("Successfully sett the eidetic memory achievement"); } else { //Store locally } }); } IAchievement closeCall = ApplicationModel.GetAchievement(GPGSIds.achievement_close_call); if (!closeCall.completed && IsCloseCallAccomplished(statsMeta.SuccessfullGame, statsMeta.MaxFlips - statsMeta.NFlips)) { Social.ReportProgress(GPGSIds.achievement_close_call, 100f, (bool success) => { if (success) { Debug.Log("Successfully set the close call achievement"); } }); } IAchievement completionStreak = ApplicationModel.GetAchievement(GPGSIds.achievement_completion_streak); if (!completionStreak.completed && IsCompletionStreakAccomplished(ApplicationModel.statistics.CurrentStreakCount)) { Social.ReportProgress(GPGSIds.achievement_completion_streak, 100f, (bool success) => { if (success) { Debug.Log("Successfully set the completion streak achievement"); } }); } #endif }
void Awake() { meta = new StackMeta(); explosions = new List <MJParticleExplosion> (); }