/// <summary> /// Carries the filled block and posts a carry event. /// </summary> /// <returns></returns> public void Carry() { // Allow Carry only if overlapping HollowBlock IsSolved() if (this.GetLiftAbility().GetOverlappingPiece() != null && this.GetLiftAbility().GetOverlappingPiece().IsSolved() /*&& * !this.GetLiftAbility().GetOverlappingPiece().IsPurelyKinematic()*/) { // If not set to "CantCarry" if (!this.GetLiftAbility().GetOverlappingPiece().CantCarry()) { SoundManager.Instance.Play(AudibleNames.Room.PICKUP_FRAGMENT, false); this.player.CarryLiftItem(); this.carriedPiece = this.GetLiftAbility().GetOverlappingPiece(); Vector3 liftedOffset = new Vector3(0f, player.GetLiftedPiecePosition().localPosition.y, 0f); this.carriedPiece.Carry(gameObject, liftedOffset); this.PostCarryEvent(this.carriedPiece); } else { this.player.SayCantCarry(); } } }
/// <summary> /// Function that handles the posting of a carry event. /// </summary> /// <param name="carriedPiece"></param> /// <returns></returns> public void PostCarryEvent(HollowBlock carriedPiece) { Parameters parameters = new Parameters(); parameters.PutObjectExtra(SkyFragmentPieceUI.HOLLOW_BLOCK, carriedPiece); EventBroadcaster.Instance.PostEvent(EventNames.ON_PLAYER_LIFT_CARRY, parameters); }
public void DropLift() { this.hollowBlock = null; this.SetSize(0f, 0f); this.GetFractionLabel().Hide(); }
// Must be Ground // [SerializeField] private Collider2D collider2D; // [SerializeField] private PlayerYuni player; // void Awake() { // this.collider2D = GetComponent<Collider2D> (); // } void OnCollisionStay2D(Collision2D other) { // Debug.Log ("<color=white>LOCK COLLISION</color> "+other.collider.gameObject.name); if (other.collider.gameObject.GetComponent <SkyFragmentPiece> () != null) { SkyFragmentPiece skyPiece = other.gameObject.GetComponent <SkyFragmentPiece> (); if (!skyPiece.IsCarried() && !skyPiece.IsAssigned()) { skyPiece.LockPiece(this); } if (skyPiece.IsCarried()) { skyPiece.UnlockPiece(this); } } if (other.collider.gameObject.GetComponent <HollowBlock> () != null) { HollowBlock hollowBlock = other.gameObject.GetComponent <HollowBlock> (); if (!hollowBlock.IsCarried() && hollowBlock.gameObject.transform.parent.GetComponent <PlayerYuni>() == null && hollowBlock.GetRigidBody2D().velocity == Vector2.zero) { hollowBlock.LockPiece(this); } else { hollowBlock.UnlockPiece(this); } } }
public void SetOverlappingPiece(HollowBlock hollowBlock) { if (this.overlappingPiece != null) { this.overlappingPiece.Unobserve(); } // If lift piece distance is less than sky piece distance if (hollowBlock != null && Physics2D.Distance(this.GetComponent <Collider2D> (), hollowBlock.GetComponent <Collider2D> ()).distance < this.GetPlayer().GetGemOverlapDistance()) { this.GetPlayer().UnobserveGem(); this.overlappingPiece = hollowBlock; // if (this.overlappingPiece != null) { this.overlappingPiece.Observe(); EventBroadcaster.Instance.PostEvent(EventNames.SHOW_PLAYER_CARRY); // } } else { if (hollowBlock != null) { hollowBlock.Unobserve(); } this.overlappingPiece = null; // EventBroadcaster.Instance.PostEvent (EventNames.HIDE_PLAYER_CARRY); } // this.GetPlayer ().CheckOverlap (); this.BroadcastOverlappingPiece(); }
/// <summary> /// Gets the hollow block. /// </summary> /// <returns>The hollow block.</returns> public HollowBlock GetHollowBlock() { if (this.hollowBlock == null) { this.hollowBlock = GameObject.FindObjectOfType <HollowBlock> (); } return(this.hollowBlock); }
public HighlightObject(float newNumerator, float newDenominator, Color newColor, bool newIsAdd, HollowBlock block) { this.numerator = newNumerator; this.denominator = newDenominator; this.color = newColor; this.isAdd = newIsAdd; this.hollowBlock = block; }
/// <summary> /// Returns the ghost block behaviour. /// </summary> /// <returns>Hollow Block Behaviour</returns> public HollowBlock GetHollowBlock() { if (this.hollowBlock == null) { this.hollowBlock = GetComponentInChildren <HollowBlock> (); } return(this.hollowBlock); }
/// <summary> /// Used to release the carried filled blocks upon player death. /// </summary> /// <returns></returns> public void DropDead() { if (this.carriedPiece != null) { HollowBlock piece = this.carriedPiece; this.Release(); piece.Respawn(); } }
/// <summary> /// Gets the sky hollow block. /// </summary> /// <returns>The sky hollow block.</returns> public HollowBlock GetSkyHollowBlock() { // Must not enter this. if (this.holllowBlock == null) { this.holllowBlock = GameObject.FindObjectOfType <HollowBlock> (); } return(this.holllowBlock); }
public void FillDrop(HollowBlock hollowBlock) { this.WearDefaultSkin(); this.SetCarried(false); this.GetRigidBody2D().bodyType = RigidbodyType2D.Dynamic; gameObject.transform.SetParent(detachedManagerParent.gameObject.transform); this.boxCollider.isTrigger = false; this.Unobserve(); hollowBlock.Absorb(this); }
/// <summary> /// Update the stability. /// </summary> /// <param name="parameters">Parameter containing the ghost block which will affect the stability.</param> public void HollowUpdate(Parameters parameters) { float numerator = parameters.GetFloatExtra(NUMERATOR, 0f); float denominator = parameters.GetFloatExtra(DENOMINATOR, 1f); Color color = (Color)parameters.GetObjectExtra(COLOR); bool isAdd = parameters.GetBoolExtra(IS_ADD, true); HollowBlock block = (HollowBlock)parameters.GetObjectExtra(HOLLOW_BLOCK); this.ManipulateStability(numerator, denominator, color, isAdd, block); // StabilityCheck (); }
/// <summary> /// Update the stability. /// </summary> /// <param name="parameters">Parameter containing the ghost block which will affect the stability.</param> public void HollowUpdateInstant(Parameters parameters) { Debug.LogError("Entered instant"); float numerator = parameters.GetFloatExtra(NUMERATOR, 0f); float denominator = parameters.GetFloatExtra(DENOMINATOR, 1f); Color color = (Color)parameters.GetObjectExtra(COLOR); bool isAdd = parameters.GetBoolExtra(IS_ADD, true); HollowBlock block = (HollowBlock)parameters.GetObjectExtra(HOLLOW_BLOCK); StartCoroutine(this.ManipulateStability(numerator, denominator, color, isAdd, block, true)); // StabilityCheck (); }
/// <summary> /// Performs a nll check and releases the currently lifted filled block. /// </summary> /// <returns></returns> public void Release() { if (this.carriedPiece != null) { Debug.Log("ENTERED RELEASE"); this.player.DropLiftItem(); this.carriedPiece.gameObject.transform.position = this.player.GetDropPiecePosition().position; this.carriedPiece.Drop(); this.carriedPiece = null; SoundManager.Instance.Play(AudibleNames.Room.PICKUP_FRAGMENT, false); EventBroadcaster.Instance.PostEvent(EventNames.ON_PLAYER_LIFT_DROP); } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.CompareTag("HollowBlock") && this.blocks.Count < ravineWidth) { HollowBlock block = other.gameObject.GetComponent <HollowBlock> (); if (!this.blocks.Contains(block)) { this.blocks.Add(block); } Debug.Log("Hit"); } }
public void LiftOverlapUpdate(Parameters parameters) { HollowBlock overlappingPiece = parameters.GetObjectExtra(OVERLAPPING_PIECE) as HollowBlock; if (overlappingPiece != null) { this.UpdateLabel((int)overlappingPiece.GetNumerator(), (int)overlappingPiece.GetDenominator()); this.ShowHint(); } else { this.HideHint(); } }
void OnCollisionExit2D(Collision2D other) { // Debug.Log ("<color=white>LOCK COLLISION EXIT</color>"); if (other.collider.gameObject.GetComponent <SkyFragmentPiece> () != null) { SkyFragmentPiece skyPiece = other.gameObject.GetComponent <SkyFragmentPiece> (); skyPiece.UnlockPiece(this); } if (other.gameObject.GetComponent <HollowBlock> () != null) { HollowBlock hollowBlock = other.gameObject.GetComponent <HollowBlock> (); hollowBlock.UnlockPiece(this); } }
/// <summary> /// Registers a new ghost block into the recorder. /// Registering a new block will prompt an update for the session. /// </summary> /// <param name="data"></param> private void RegisterBlock(Parameters data) { HollowBlock block = data.GetHollowBlockExtra("hollowBlock"); if (!this.hollowBlocks.Contains(block)) { this.hollowBlocks.Add(block); if (block.IsSolved()) { fractionSet.fractions.Add(block.GetFraction()); Debug.Log("Fraction added: " + block.GetFraction().numerator + "/" + block.GetFraction().denominator); } UpdateSession(); } }
// TODO public void UpdateCarriedLift(Parameters parameters) { HollowBlock piece = parameters.GetObjectExtra(HOLLOW_BLOCK) as HollowBlock; // this.skyPiece = piece; this.hollowBlock = piece; // Safety measure. Should never enter this. if (this.hollowBlock == null) { DropLift(); } else { this.SetSize(this.hollowBlock.GetWidthPiece(), this.hollowBlock.GetHeight()); this.ChangeColor(this.hollowBlock.GetTangibleColor(), this.hollowBlock.GetOutlineStartColor()); this.spriteRenderer.material = hollowBlock.GetSpriteRenderer().material; this.GetFractionLabel().Show(); this.SetFractionLabel((int)this.hollowBlock.GetNumerator(), (int)this.hollowBlock.GetDenominator()); } }
private void CheckFallingBlocks() { RaycastHit2D hit; Vector3 pos2 = new Vector3(this.transform.position.x + ravineWidth, this.transform.position.y); hit = Physics2D.Raycast(this.transform.position, pos2); Debug.DrawLine(this.transform.position, pos2); Debug.Log("BLock Count: " + this.blocks.Count); if (hit.collider.gameObject.CompareTag("HollowBlock") && this.blocks.Count < ravineWidth) { HollowBlock block = hit.collider.gameObject.GetComponent <HollowBlock> (); this.blocks.Add(block); Debug.Log("Hit"); } }
IEnumerator DropRoutine() { Debug.Log("<color=magenta>DROP ROUTINE ENTER</color>"); // this.isDropping = true; Collider2D[] colliders; Vector3 prevPosition = Vector3.zero; bool hasAbsorbed = false; // While falling while (!hasAbsorbed && //&& gameObject.transform.position != prevPosition !this.boxCollider.IsTouchingLayers(LayerMask.NameToLayer("Ground"))) { // this.GetRigidBody2D().velocity.y > 0f) { // ContactFilter2D contactFilter = new ContactFilter2D (); // Physics2D.OverlapBox (this.boxCollider.transform.position, this.boxCollider.size, this.boxCollider.transform.eulerAngles.z, contactFilter, colliders); colliders = Physics2D.OverlapBoxAll(this.boxCollider.transform.position, this.boxCollider.size, this.boxCollider.transform.eulerAngles.z); foreach (Collider2D collider in colliders) { if (!hasAbsorbed && !isCarried && collider.gameObject.GetComponent <HollowBlock> () != null) { // Absorb hasAbsorbed = true; Debug.Log("<color=blue>HOLLOW BLOCK COLLISION</color>"); HollowBlock hollowBlock = collider.gameObject.GetComponent <HollowBlock> (); hollowBlock.Absorb(this); } yield return(null); } yield return(null); prevPosition = gameObject.transform.position; } // this.isDropping = false; Debug.Log("<color=magenta>DROP ROUTINE EXIT</color>"); }
/// <summary> /// Unregister a ghost block from this record. /// Unregistering will prompt an update for the session. /// </summary> /// <param name="data"></param> private void UnregisterBlock(Parameters data) { HollowBlock block = data.GetHollowBlockExtra("hollowBlock"); if (this.hollowBlocks.Contains(block)) { this.hollowBlocks.Remove(block); // if (filledFractions.Contains (filledFractions.Find (x => x.numerator == block.GetFraction ().numerator // && x.denominator == block.GetFraction ().denominator))) // filledFractions.Remove (filledFractions.Find (x => x.numerator == block.GetFraction ().numerator && x.denominator == block.GetFraction ().denominator)); if (fractionSet.fractions.Remove(fractionSet.fractions.Find(x => x.numerator == block.GetFraction().numerator&& x.denominator == block.GetFraction().denominator))) { Debug.Log("Removed Fraction: " + block.GetFraction().numerator + "/" + block.GetFraction().denominator); } else { Debug.Log("Failed to Remove: " + block.GetFraction().numerator + "/" + block.GetFraction().denominator); } UpdateSession(); } }
public void PutExtra(string paramName, HollowBlock hollowBlock) { this.hollowBlockData.Add(paramName, hollowBlock); }
/// <summary> /// This drop is used for the Hollow Block prefilling ONLY (since it disables platform locking if skyblock is hidden). /// </summary> /// <param name="targetBlock">Target Ghost Block</param> public void Drop(HollowBlock targetBlock) { float pieceCount = (float)targetBlock.GetSliceCount(); int fillCount = targetBlock.GetFillCount(); int detachCount = targetBlock.GetDetachCount(); // NOTE: This is for hidden sky blocks only. The Sky Block reference is always forced to 1 // if (targetBlock.IsHiddenSkyBlock ()) { // this.SetBlockValues (1, 1); // } if (this.GetNumerator() > 0) { if (pieceCount > 0 && this.NotTooSmall(pieceCount)) { Debug.Log("Entered DROP"); float newDenominator = this.GetDenominator() * pieceCount; int originalCount = skyFragmentPieces.Count; for (int i = 0; i < pieceCount; i++) { // For pieces that will fill the target block if (i < fillCount) { targetBlock.SolvedFromPrefill(); this.GetSkyFragmentPieces().Add(CreateSkyFragmentPiece(this.GetSkyBlockParent().GetDetachedManager().gameObject, (int)this.GetNumerator(), (int)newDenominator)); if (targetBlock.IsHiddenSkyBlock()) { this.skyFragmentPieces [originalCount + i].DisablePlatformLocking(); // Important for Hidden SkyBlocks } this.skyFragmentPieces [originalCount + i].SetDenominator(pieceCount); this.skyFragmentPieces [originalCount + i].SetNumerator(1f); this.skyFragmentPieces [originalCount + i].transform.localPosition = new Vector3((-GetWidthWhole() / 2) + (this.skyFragmentPieces [i].GetWidth() * i) + (this.skyFragmentPieces [i].GetWidth() / 2), 0f, 0f); this.skyFragmentPieces [originalCount + i].FillDrop(targetBlock); this.skyFragmentPieces [originalCount + i].SetPiecesNeverBreak(this.piecesNeverBreak); } // For detached pieces else if (i < fillCount + detachCount) { this.skyFragmentPieces.Add(CreateSkyFragmentPiece(this.skyBlockParent.GetDetachedManager().gameObject, (int)this.GetNumerator(), (int)newDenominator)); if (targetBlock.IsHiddenSkyBlock()) { this.skyFragmentPieces [originalCount + i].DisablePlatformLocking(); // Important for Hidden SkyBlocks } this.skyFragmentPieces [originalCount + i].SetDenominator(pieceCount); this.skyFragmentPieces [originalCount + i].SetNumerator(1f); this.skyFragmentPieces [originalCount + i].gameObject.transform.position = targetBlock.GetDetachedPosition(); this.skyFragmentPieces [originalCount + i].SetPiecesNeverBreak(this.piecesNeverBreak); } } Debug.Log("<color=green>Piece, Fill, Detach count are = " + pieceCount + " " + fillCount + " " + detachCount + "</color>"); this.SetNumerator(pieceCount - fillCount - detachCount); this.SetDenominator(newDenominator); this.PrefillNumerator(); Debug.Log("<color=green>New NUM DEN = " + this.GetNumerator() + " " + this.GetDenominator() + "</color>"); } else { // Too small. Yuni prompt. // TODO: Yuni Hints } } }
/// <summary> /// Updates the stability number line's target value given the instantiated ghost blocks in the room. /// /// Target value is kept if the stability number line is set to arbitrary. /// </summary> /// <param name="blocks">All instantiated ghost blocks in the room.</param> /// <returns>Fraction Target Value</returns> public FractionData UpdateStabilityNumberLine(List <HollowBlock> blocks) { FractionData frac = new FractionData(); if (this.GetNumberLine() != null) { frac.numerator = numberLine.GetTargetNumerator(); frac.denominator = numberLine.GetTargetDenominator(); if (!this.numberLineIsArbitrary) { blocks.Shuffle <HollowBlock> (); int inclusionCount = Random.Range(1, blocks.Count + 1); FractionData fractionSum = new FractionData(); fractionSum.numerator = 0; fractionSum.denominator = 1; float sum = 0f; if (blocks.Count == 1) { if (!blocks [0].IsSolved()) { int denom = General.LCD(fractionSum.denominator, (int)blocks [0].GetDenominator()); FractionData temp = new FractionData(); temp.denominator = denom; temp.numerator = (denom / fractionSum.denominator) * fractionSum.numerator; Debug.Log("Temp Frac 1: " + temp.numerator + "/" + temp.denominator); FractionData temp2 = new FractionData(); temp2.denominator = denom; temp2.numerator = (denom / (int)blocks [0].GetDenominator()) * (int)blocks [0].GetNumerator(); Debug.Log("Temp Frac 2: " + temp2.numerator + "/" + temp2.denominator); fractionSum.numerator = temp.numerator + temp2.numerator; fractionSum.denominator = denom; Debug.Log("Fraction Sum: " + fractionSum.numerator + "/" + fractionSum.denominator); // sum += (blocks [0].GetNumerator () / blocks [0].GetDenominator ()); } } else if (blocks.Count == 2) { int count = Random.Range(1, 3); if (count == 1 || blocks[0].IsSolved()) { int index = Random.Range(0, 2); if (PedagogicalComponent_v2.Instance.CurrentDenominator() != (int)blocks [index].GetDenominator() && !blocks [index].IsSolved()) { index = Mathf.Abs(index - 1); } else if (blocks [index].IsSolved() && PedagogicalComponent_v2.Instance.CurrentDenominator() == (int)blocks [index].GetDenominator()) { index = Mathf.Abs(index - 1); } int denom = General.LCD(fractionSum.denominator, (int)blocks [index].GetDenominator()); FractionData temp = new FractionData(); temp.denominator = denom; temp.numerator = (denom / fractionSum.denominator) * fractionSum.numerator; Debug.Log("Temp Frac 1: " + temp.numerator + "/" + temp.denominator); FractionData temp2 = new FractionData(); temp2.denominator = denom; temp2.numerator = (denom / (int)blocks [index].GetDenominator()) * (int)blocks [index].GetNumerator(); Debug.Log("Temp Frac 2: " + temp2.numerator + "/" + temp.denominator); fractionSum.numerator = temp.numerator + temp2.numerator; fractionSum.denominator = denom; Debug.Log("Fraction Sum: " + fractionSum.numerator + "/" + fractionSum.denominator); } else { for (int i = 0; i < count; i++) { int denom = General.LCD(fractionSum.denominator, (int)blocks [i].GetDenominator()); FractionData temp = new FractionData(); temp.denominator = denom; temp.numerator = (denom / fractionSum.denominator) * fractionSum.numerator; Debug.Log("Temp Frac 1: " + temp.numerator + "/" + temp.denominator); FractionData temp2 = new FractionData(); temp2.denominator = denom; temp2.numerator = (denom / (int)blocks [i].GetDenominator()) * (int)blocks [i].GetNumerator(); Debug.Log("Temp Frac 2: " + temp2.numerator + "/" + temp.denominator); fractionSum.numerator = temp.numerator + temp2.numerator; fractionSum.denominator = denom; Debug.Log("Fraction Sum: " + fractionSum.numerator + "/" + fractionSum.denominator); } } // sum += blocks [index].GetNumerator () / blocks [index].GetDenominator (); } else if (blocks.Count > 2) { if (inclusionCount == blocks.Count) { inclusionCount = blocks.Count - 1; } int index1 = blocks.FindIndex(x => x.GetDenominator() == PedagogicalComponent_v2.Instance.CurrentDenominator()); HollowBlock blockTemp = blocks [0]; blocks [0] = blocks [index1]; blocks [index1] = blockTemp; for (int i = 0; i < inclusionCount; i++) { int denom = General.LCD(fractionSum.denominator, (int)blocks [i].GetDenominator()); FractionData temp = new FractionData(); temp.denominator = denom; temp.numerator = (denom / fractionSum.denominator) * fractionSum.numerator; Debug.Log("Temp Frac 1: " + temp.numerator + "/" + temp.denominator); FractionData temp2 = new FractionData(); temp2.denominator = denom; temp2.numerator = (denom / (int)blocks [i].GetDenominator()) * (int)blocks [i].GetNumerator(); Debug.Log("Temp Frac 2: " + temp2.numerator + "/" + temp.denominator); fractionSum.numerator = temp.numerator + temp2.numerator; fractionSum.denominator = denom; Debug.Log("Fraction Sum: " + fractionSum.numerator + "/" + fractionSum.denominator); // sum += (blocks [i].GetNumerator () / blocks [i].GetDenominator ()); } } else { Debug.LogError("No Blocks given."); } frac.numerator = fractionSum.numerator; frac.denominator = fractionSum.denominator; float[] simpFrac = new float[2]; simpFrac = General.SimplifyFraction(frac.numerator, frac.denominator); frac.numerator = (int)simpFrac [0]; frac.denominator = (int)simpFrac [1]; // float[] fraction = General.SimplifyFraction (sum * 100f, 100f); // frac.numerator = (int)fraction [0]; // frac.denominator = (int)fraction [1]; float maxPoint = 0; foreach (HollowBlock block in blocks) { Debug.LogError("STAB MAX CALC " + block.GetNumerator() + " / " + block.GetDenominator()); maxPoint += (block.GetNumerator() / block.GetDenominator()); } //Debug.LogError("RAW MAX IS " + maxPoint); // TODO change last parameter (maxPoint) to the closest greater integer to the summation of all hollowblock values //numberLine.ChangeValue(frac.denominator, frac.numerator, frac.denominator, Mathf.CeilToInt(maxPoint)); //numberLine.ChangeValueNoPrompt(frac.denominator, frac.numerator, frac.denominator, Mathf.CeilToInt(maxPoint)); //Debug.LogError("STAB CONTROLLER GAVE Max pt of "+(Mathf.CeilToInt(maxPoint))); numberLine.ChangeValueNoPrompt(frac.denominator, frac.numerator, frac.denominator); //numberLine.ChangeValueNoPrompt(frac.denominator, frac.numerator, frac.denominator, Mathf.CeilToInt(maxPoint)); } } else { frac.numerator = 0; frac.denominator = 1; } return(frac); }
public void SetHollowBlock(HollowBlock block) { this.hollowBlock = block; }
//This is called every Prefill so make sure Sky Block is whole //everytime it is called. /// <summary> /// Drops pieces directly to a ghost block to fill it. Used when ghost blocks need to be prefilled for a subtractino puzzle. /// </summary> /// <param name="targetBlock"></param> public void Drop(HollowBlock targetBlock) { this.attachedManager.Drop(targetBlock); }
/// <summary> /// Drop the block as fragments into a target ghost block for prefilling. /// </summary> /// <param name="targetBlock"></param> public void Drop(HollowBlock targetBlock) { this.GetAttachedFragmentBlock().Drop(targetBlock); }
public void SetHollowBlock(HollowBlock newHollowBlock) { this.hollowBlock = newHollowBlock; }
/// <summary> /// Record the data of the player's attempt. /// Evaluates if the attempt is right or wrong by comparing the set of fllled blocks with all the instances of the subset sum set. /// The comparision looks if the set of attempts are closer or farther from any subset sum. /// </summary> /// <param name="data"></param> private void RecordData(Parameters data) { HollowBlock block = data.GetHollowBlockExtra("hollowBlock"); bool solved = data.GetBoolExtra("solved", true); FractionSet oldFracSet = new FractionSet(); oldFracSet.fractions.AddRange(fractionSet.fractions); FractionData blockFraction = block.GetFraction(); if (solved) { fractionSet.fractions.Add(block.GetFraction()); } else { fractionSet.fractions.Remove(fractionSet.fractions.Find(x => x.numerator == block.GetFraction().numerator && x.denominator == block.GetFraction().denominator)); } Debug.Log("Old size: " + oldFracSet.fractions.Count); FractionSet newFracSet = new FractionSet(); newFracSet.fractions.AddRange(fractionSet.fractions); Debug.Log("New size: " + newFracSet.fractions.Count); bool found = false; bool improve = false; int oldCounter = 0; int newCounter = 0; foreach (FractionSet s in additionRight) { FractionSet oldTemp = oldFracSet; FractionSet newTemp = newFracSet; oldCounter = 0; newCounter = 0; for (int i = 0; i < s.fractions.Count; i++) { if (oldTemp.fractions.Remove(oldTemp.fractions.Find(x => x.numerator == s.fractions [i].numerator && x.denominator == s.fractions [i].denominator))) { oldCounter++; } else { oldCounter--; } if (newTemp.fractions.Remove(newTemp.fractions.Find(x => x.numerator == s.fractions [i].numerator && x.denominator == s.fractions [i].denominator))) { newCounter++; } else { newCounter--; } } oldCounter -= oldFracSet.fractions.Count; newCounter -= newFracSet.fractions.Count; Debug.Log("New: " + newCounter + " VS Old: " + oldCounter); if (newCounter > oldCounter) { improve = true; break; } } if (solved) //This means it is Addition { if (improve) { this.currentSession.Tally(blockFraction.denominator, true, Operation.ADDITION); } else { this.currentSession.Tally(blockFraction.denominator, false, Operation.ADDITION); } } else //Else, its Subtraction { if (improve) { this.currentSession.Tally(blockFraction.denominator, true, Operation.SUBTRACTION); } else { this.currentSession.Tally(blockFraction.denominator, false, Operation.SUBTRACTION); } } }