/// <summary> /// Inserts a single Chop into a list if it was made in a valid position. Otherwise, it's ignored. /// </summary> /// <param name="position">The X position of the knife at the time when the chop was made.</param> void InsertChop(float position) { Chop currentChop = new Chop { LowerBound = position - ChopWidth, ActualPosition = position, UpperBound = position + ChopWidth }; HitOrMiss status = ValidPosition(currentChop); PrintHitOrMiss(status); // Only add if it was a valid knife chop. if (status == HitOrMiss.Hit) { StartCoroutine(Reference.DoAnimation(1)); AlreadyChopped.Add(currentChop); SpriteController.DrawChop(); TotalChops++; } if (status == HitOrMiss.Collision) { TotalChops++; } }
public void Test_chop_three_elements_element_dont_exists() { Assert.Equal(-1, Chop.chop(0, new int[] { 1, 3, 5 })); Assert.Equal(-1, Chop.chop(2, new int[] { 1, 3, 5 })); Assert.Equal(-1, Chop.chop(4, new int[] { 1, 3, 5 })); Assert.Equal(-1, Chop.chop(6, new int[] { 1, 3, 5 })); }
public override void OnEvent(Chop evnt) { if (evnt.Target && this.ValidateSender(evnt, SenderTypes.Any)) { evnt.Target.GetComponentInChildren <chopEnemy>().triggerChop(); } }
public void Test_chop_four_elements_when_element_exists() { Assert.Equal(0, Chop.chop(1, new int[] { 1, 3, 5, 7 })); Assert.Equal(1, Chop.chop(3, new int[] { 1, 3, 5, 7 })); Assert.Equal(2, Chop.chop(5, new int[] { 1, 3, 5, 7 })); Assert.Equal(3, Chop.chop(7, new int[] { 1, 3, 5, 7 })); }
public override void OnEvent(Chop evnt) { if (evnt.Target) { evnt.Target.GetComponentInChildren <chopEnemy>().triggerChop(); } }
public override void GetAll(IIndicatorValues Ind) { int period = (int)this.IndicatorParameters.List[0]; int smoothingPeriod = (int)this.IndicatorParameters.List[1]; decimal threshold = (decimal)this.IndicatorParameters.List[2]; if (!Ind.Chop(period, smoothingPeriod, threshold).IsPopulated) { int oldCurrentBar = Ind.Bar.CurrentBar; for (int i = 1; i <= Ind.Bar.MaxBar; i++) { Ind.Bar.CurrentBar = i; object prototype = null; if (i == 1) { prototype = new Chop(threshold); } else { prototype = (Chop)Ind.Chop(period, smoothingPeriod, threshold)[1].Clone(); } Get(ref prototype, Ind); Ind.Chop(period, smoothingPeriod, threshold)[0] = (Chop)prototype; Ind.Chop(period, smoothingPeriod, threshold).IsPopulated = true; // set here so instance is guaranteed to exits } Ind.Bar.CurrentBar = oldCurrentBar; } }
/// <summary> /// Draws the chop bounds in the scene for visual debug. /// </summary> /// <param name="current">The chop to be drawn.</param> void DebugDrawChop(Chop current) { float upperY = 10; float lowerY = -10; // Draw Center Line Vector3 centerStart = new Vector3(current.ActualPosition, upperY, 0); Vector3 centerEnd = new Vector3(current.ActualPosition, lowerY, 0); Color centerColor = Color.red; Debug.DrawLine(centerStart, centerEnd, centerColor, Mathf.Infinity, false); // Draw Left line Vector3 leftStart = new Vector3(current.ActualPosition - ChopWidth, upperY, 0); Vector3 leftEnd = new Vector3(current.ActualPosition - ChopWidth, lowerY, 0); Color leftColor = Color.green; Debug.DrawLine(leftStart, leftEnd, leftColor, Mathf.Infinity, false); // Draw Right Line Vector3 rightStart = new Vector3(current.ActualPosition + ChopWidth, upperY, 0); Vector3 rightEnd = new Vector3(current.ActualPosition + ChopWidth, lowerY, 0); Color rightColor = Color.green; Debug.DrawLine(rightStart, rightEnd, rightColor, Mathf.Infinity, false); }
public void Test_chop_four_elements_when_dont_element_exists() { Assert.Equal(-1, Chop.chop(0, new int[] { 1, 3, 5, 7 })); Assert.Equal(-1, Chop.chop(2, new int[] { 1, 3, 5, 7 })); Assert.Equal(-1, Chop.chop(4, new int[] { 1, 3, 5, 7 })); Assert.Equal(-1, Chop.chop(6, new int[] { 1, 3, 5, 7 })); Assert.Equal(-1, Chop.chop(8, new int[] { 1, 3, 5, 7 })); }
void Start() { resourceManager = GetComponent <ResourceManager>(); uiManager = GetComponent <UIManager>(); _globalLastActionTime = Time.time; _chop = new Chop(1, new TargettingArc(70f, 10f)); _interact = new Interact(new TargettingArc(50f, 10f)); }
protected override String GetPresentDetail(IOutputInstant Instant, IIndicatorValues Data, IndicatorParameters IndicatorParameters) { Chop choppiness = Data.Chop(IndicatorParameters)[Instant.ExposureDate]; if (choppiness != null) { return(String.Format("{0}|{1}|{2}|", choppiness.Value, (int)choppiness.Trendiness, choppiness.Trendiness)); } else { return(String.Format("{0}|{1}|{2}", "", "", "")); } }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Weapon") && this.doChop) { if (BoltNetwork.isRunning) { Chop chop = Chop.Raise(GlobalTargets.Everyone); chop.Target = base.GetComponentInParent <BoltEntity>(); chop.Send(); } else { this.triggerChop(); } } }
/// <summary> /// Checks to make sure that the position is valid on the choppable object. A position is defined as /// valid if it 1. is within the bounds of the choppable objece and 2. Is not within the bounds of /// any other valid chop. /// </summary> /// <param name="current">The Chop structure to check.</param> /// <returns>The HitOrMiss status of the current Chop.</returns> HitOrMiss ValidPosition(Chop current) { // TODO: Check if bounds overlap?? // Get all overlaps with Linq query List <Chop> cutWithin = AlreadyChopped.Where(chopValue => current.UpperBound >= chopValue.LowerBound && current.LowerBound <= chopValue.UpperBound) .ToList(); if (cutWithin.Any()) { return(HitOrMiss.Collision); } float lowerBound = Reference.ItemToChop.LeftBound; float upperBound = Reference.ItemToChop.RightBound; return(current.ActualPosition < lowerBound || current.ActualPosition > upperBound ? HitOrMiss.Miss : HitOrMiss.Hit); }
public void OnChop() { Chop?.Invoke(); }
public void Test_chop_empty_haystack() { Assert.Equal(-1, Chop.chop(3, new int[] { })); Assert.Equal(-1, Chop.chop(3, new int[] { 1 })); }
public void OnOperationDone(FoodCharacteristic fc, OperationEventArgs e) { Debug.Log("operation done"); if (recipeDone) { return; } Debug.Log("operation cont'"); switch (e.OperationType) { case Action.ActionType.Boil: if (actions[currentActionIndex].GetActionType() == Action.ActionType.Boil) { if (actions[currentActionIndex].GetInvolvedFood().GetFoodIdentifier() == fc.GetComponent <FoodStatus>().foodIdentifier) { if (foodIndex == currentActionIndex) { foodsInRecipe.Add(fc.transform.GetChild(0).gameObject); foodIndex++; } taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; } } break; // this case will be run for only eggs. Therefore, checking that if broken thing has a "FoodStatus" is needed. case Action.ActionType.Break: if (fc.GetComponent <FoodStatus>() && actions[currentActionIndex].GetInvolvedFood().GetFoodIdentifier() == fc.GetComponent <FoodStatus>().foodIdentifier) { if (foodIndex == currentActionIndex) { foodsInRecipe.Add(fc.transform.parent.gameObject); foodIndex++; } taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; } break; case Action.ActionType.Chop: if (actions[currentActionIndex].GetActionType() == Action.ActionType.Chop) { if ((actions[currentActionIndex].GetInvolvedFood().GetFoodIdentifier() == fc.GetComponent <FoodStatus>().foodIdentifier) && !(choppedObjects.Contains(fc.transform.root.GetInstanceID()))) { if (foodIndex == currentActionIndex) { foodsInRecipe.Add(fc.transform.parent.gameObject); foodIndex++; } //Debug.Log(fc.GetComponent<FoodStatus>().foodIdentifier); //numSlices++; //if (numSlices == 1) //{ // numChoppedPieces = 2; //} //else //{ // numChoppedPieces++; //} numChoppedPieces++; Chop chop = (Chop)actions[currentActionIndex]; // if current food's chopping parameters is satisfied, then set current action as done, i.e. increment index //if (fc.GetComponent<CanBeChopped>().maximumChopCount == 1) //Debug.Log(chop.GetRequiredPieceCount()); if (numChoppedPieces == chop.GetRequiredPieceCount()) { //Debug.Log(numChoppedPieces+ " - " + numSlices); taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; choppedObjects.Add(fc.transform.root.GetInstanceID()); numChoppedPieces = 0; numSlices = 0; } } } break; /* for cook and fry, convenience of process has been determined in relevant script. There is no need to check parameters here again. */ case Action.ActionType.Cook: if (actions[currentActionIndex].GetActionType() == Action.ActionType.Cook) { if (actions[currentActionIndex].GetInvolvedFood().GetFoodIdentifier() == fc.GetComponent <FoodStatus>().foodIdentifier) { if (foodIndex == currentActionIndex) { foodsInRecipe.Add(fc.transform.parent.gameObject); foodIndex++; } if (!cookObjects.Contains(fc.transform.parent.gameObject)) { cookObjects.Add(fc.transform.parent.gameObject); cookCounts.Add(0); } GameObject obj = cookObjects.Find(x => x.GetInstanceID() == fc.transform.parent.gameObject.GetInstanceID()); int index = cookObjects.IndexOf(obj); cookCounts[index]++; if (cookCounts[index] >= fc.transform.parent.childCount - 2) { cookCounts[index] = 0; taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; } } } break; case Action.ActionType.Fry: if (actions[currentActionIndex].GetActionType() == Action.ActionType.Fry) { if (actions[currentActionIndex].GetInvolvedFood().GetFoodIdentifier() == fc.GetComponent <FoodStatus>().foodIdentifier) { if (foodIndex == currentActionIndex) { foodsInRecipe.Add(fc.transform.parent.gameObject); foodIndex++; } if (!fryObjects.Contains(fc.transform.parent.gameObject)) { fryObjects.Add(fc.transform.parent.gameObject); fryCounts.Add(0); } GameObject obj = fryObjects.Find(x => x.GetInstanceID() == fc.transform.parent.gameObject.GetInstanceID()); int index = fryObjects.IndexOf(obj); fryCounts[index]++; if (fryCounts[index] >= fc.transform.parent.childCount - 2) { fryCounts[index] = 0; taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; } } } break; // mix script has not been completed yet. case Action.ActionType.Mix: if (actions[currentActionIndex].GetActionType() == Action.ActionType.Mix) { if (actions[currentActionIndex].GetInvolvedFood().GetFoodIdentifier() == fc.GetComponent <FoodStatus>().foodIdentifier) { if (foodIndex == currentActionIndex) { foodsInRecipe.Add(fc.transform.parent.gameObject); foodIndex++; } taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; } } break; case Action.ActionType.Peel: if (actions[currentActionIndex].GetActionType() == Action.ActionType.Peel) { if (actions[currentActionIndex].GetInvolvedFood().GetFoodIdentifier() == fc.GetComponent <FoodStatus>().foodIdentifier) { if (foodIndex == currentActionIndex) { foodsInRecipe.Add(fc.transform.parent.gameObject); foodIndex++; } taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; } } break; case Action.ActionType.PutTogether: //Debug.Log("I ungrabbed sth"); if (actions[currentActionIndex].GetActionType() == Action.ActionType.PutTogether) { if (actions[currentActionIndex].GetInvolvedFood().GetFoodIdentifier() == fc.GetComponent <FoodStatus>().foodIdentifier) { bool isCloseEnough = true; PutTogether pt = (PutTogether)actions[currentActionIndex]; GameObject destinationGameObject = foodsInRecipe[pt.GetDestinationFoodIndex()]; //Debug.Log(destinationGameObject.name); //Debug.Log(fc.name); for (int i = 0; i < fc.transform.parent.childCount; i++) { float distance = Vector3.Distance(fc.transform.parent.GetChild(i).position, destinationGameObject.transform.position); Debug.Log(distance); if (distance >= .15f) { isCloseEnough = false; break; } } if (isCloseEnough) { taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; } //float distance = Vector3.Distance(fc.gameObject.transform.position, destinationGameObject.transform.position); //Debug.Log(distance); } } break; case Action.ActionType.Smash: Debug.Log("smash started"); if (actions[currentActionIndex].GetActionType() == Action.ActionType.Smash) { if (actions[currentActionIndex].GetInvolvedFood().GetFoodIdentifier() == fc.GetComponent <FoodStatus>().foodIdentifier) { Debug.Log("comin' food: " + fc.name); if (foodIndex == currentActionIndex) { foodsInRecipe.Add(fc.transform.parent.gameObject); foodIndex++; } taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; } } break; case Action.ActionType.Squeeze: if (actions[currentActionIndex].GetActionType() == Action.ActionType.Squeeze) { if (foodIndex == currentActionIndex) { foodsInRecipe.Add(fc.transform.parent.gameObject); foodIndex++; } taskListUI.GetComponent <AddActionsTaskList>().SetStepCompleted(currentActionIndex); currentActionIndex++; } break; } if (currentActionIndex == actions.Count) { recipeDone = true; } }
public void ChopTesterInit() { chop = new Chop(); }
public void Test_chop_single_element_exists() { Assert.Equal(0, Chop.chop(1, new int[] { 1 })); }
public void ChopChopChopChopTest() { Chop chopper = new Chop(); Assert.AreEqual(-1, chopper.ChopChopChopChop(3, new List <int> { })); Assert.AreEqual(-1, chopper.ChopChopChopChop(3, new List <int> { 1 })); Assert.AreEqual(0, chopper.ChopChopChopChop(1, new List <int> { 1 })); Assert.AreEqual(0, chopper.ChopChopChopChop(1, new List <int> { 1, 3, 5 })); Assert.AreEqual(1, chopper.ChopChopChopChop(3, new List <int> { 1, 3, 5 })); Assert.AreEqual(2, chopper.ChopChopChopChop(5, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopChopChopChop(0, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopChopChopChop(2, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopChopChopChop(4, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopChopChopChop(6, new List <int> { 1, 3, 5 })); Assert.AreEqual(0, chopper.ChopChopChopChop(1, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(1, chopper.ChopChopChopChop(3, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(2, chopper.ChopChopChopChop(5, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(3, chopper.ChopChopChopChop(7, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopChopChopChop(0, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopChopChopChop(2, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopChopChopChop(4, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopChopChopChop(6, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopChopChopChop(8, new List <int> { 1, 3, 5, 7 })); }
public void ChopRecursionDifferently() { Chop chopper = new Chop(); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(3, new List <int> { })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(3, new List <int> { 1 })); Assert.AreEqual(0, chopper.ChopRecursionDifferently(1, new List <int> { 1 })); Assert.AreEqual(0, chopper.ChopRecursionDifferently(1, new List <int> { 1, 3, 5 })); Assert.AreEqual(1, chopper.ChopRecursionDifferently(3, new List <int> { 1, 3, 5 })); Assert.AreEqual(2, chopper.ChopRecursionDifferently(5, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(0, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(2, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(4, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(6, new List <int> { 1, 3, 5 })); Assert.AreEqual(0, chopper.ChopRecursionDifferently(1, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(1, chopper.ChopRecursionDifferently(3, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(2, chopper.ChopRecursionDifferently(5, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(3, chopper.ChopRecursionDifferently(7, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(0, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(2, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(4, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(6, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursionDifferently(8, new List <int> { 1, 3, 5, 7 })); }
public void ChopRecursionTest() { Chop chopper = new Chop(); Assert.AreEqual(-1, chopper.ChopRecursion(3, new List <int> { })); Assert.AreEqual(-1, chopper.ChopRecursion(3, new List <int> { 1 })); Assert.AreEqual(0, chopper.ChopRecursion(1, new List <int> { 1 })); Assert.AreEqual(0, chopper.ChopRecursion(1, new List <int> { 1, 3, 5 })); Assert.AreEqual(1, chopper.ChopRecursion(3, new List <int> { 1, 3, 5 })); Assert.AreEqual(2, chopper.ChopRecursion(5, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopRecursion(0, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopRecursion(2, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopRecursion(4, new List <int> { 1, 3, 5 })); Assert.AreEqual(-1, chopper.ChopRecursion(6, new List <int> { 1, 3, 5 })); Assert.AreEqual(0, chopper.ChopRecursion(1, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(1, chopper.ChopRecursion(3, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(2, chopper.ChopRecursion(5, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(3, chopper.ChopRecursion(7, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursion(0, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursion(2, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursion(4, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursion(6, new List <int> { 1, 3, 5, 7 })); Assert.AreEqual(-1, chopper.ChopRecursion(8, new List <int> { 1, 3, 5, 7 })); }