Skip to content

Commit d016c7f

Browse files
committed
--wip--
1 parent de40a3b commit d016c7f

File tree

4 files changed

+28
-61
lines changed

4 files changed

+28
-61
lines changed

Assets/Scripts/Problems/Common.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace DefaultNamespace.Problems.Common
2+
{
3+
public interface IProblem
4+
{
5+
void Reset();
6+
void RunSimulation();
7+
}
8+
}

Assets/Scripts/Problems/Common/IProblem.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,19 @@
11
using System.Collections;
22
using DefaultNamespace;
3+
using DefaultNamespace.Problems.Common;
34
using DG.Tweening;
45
using Nineva;
56
using UnityEngine;
67
using UnityEngine.Assertions;
78

8-
public class SortStackUsingTwoStacksProblem : MonoBehaviour
9+
public class SortStackUsingTwoStacksProblem : MonoBehaviour, IProblem
910
{
10-
[SerializeField] [Range(0.1f, 2f)]float _speed = 0.5f;
11-
11+
[SerializeField] [Range(0.1f, 2f)] float _speed = 0.5f;
12+
1213
[SerializeField] GameObject tmpLocation;
1314
[SerializeField] VisualStackInt s1;
1415
[SerializeField] VisualStackInt s2;
1516

16-
void Start()
17-
{
18-
// StartCoroutine(Run(s1));
19-
// StartCoroutine(Run(s2));
20-
21-
// Sort(s1);
22-
}
23-
24-
public void OnRunButtonClick()
25-
{
26-
StartCoroutine(Sort());
27-
}
28-
29-
IEnumerator Run(VisualStackInt stack)
30-
{
31-
yield return PushAnimated(1, new WaitForSeconds(0.5f), stack);
32-
yield return PushAnimated(2, new WaitForSeconds(0.5f), stack);
33-
yield return PushAnimated(3, new WaitForSeconds(0.5f), stack);
34-
yield return PushAnimated(4, new WaitForSeconds(0.5f), stack);
35-
yield return PushAnimated(5, new WaitForSeconds(0.5f), stack);
36-
37-
yield return PopAnimated(new WaitForSeconds(0.5f), stack);
38-
yield return PopAnimated(new WaitForSeconds(0.5f), stack);
39-
yield return PopAnimated(new WaitForSeconds(0.5f), stack);
40-
yield return PopAnimated(new WaitForSeconds(0.5f), stack);
41-
yield return PopAnimated(new WaitForSeconds(0.5f), stack);
42-
}
43-
44-
IEnumerator PopAnimated(WaitForSeconds waitForSeconds, VisualStackInt stack)
45-
{
46-
yield return waitForSeconds;
47-
var gameObj = stack.Pop().go;
48-
yield return SmoothLerp(2f, gameObj);
49-
Destroy(gameObj);
50-
}
51-
52-
// just to demo animation
53-
static IEnumerator SmoothLerp(float time, GameObject target)
54-
{
55-
var position = target.transform.position;
56-
var startingPos = position;
57-
var finalPos = position + target.transform.right * 5;
58-
float elapsedTime = 0;
59-
60-
while (elapsedTime < time)
61-
{
62-
target.transform.position = Vector3.Lerp(startingPos, finalPos, elapsedTime / time);
63-
elapsedTime += Time.deltaTime;
64-
yield return null;
65-
}
66-
}
67-
68-
IEnumerator PushAnimated(int item, WaitForSeconds waitFor, VisualStackInt stack)
69-
{
70-
stack.Push(item);
71-
yield return waitFor;
72-
}
73-
7417
IEnumerator Sort()
7518
{
7619
Assert.IsTrue(s2.IsEmpty, "Second stack must be empty");
@@ -92,4 +35,14 @@ IEnumerator Sort()
9235
yield return s2.PopAndPushTo(s1, _speed);
9336
}
9437
}
38+
39+
public void Reset()
40+
{
41+
throw new System.NotImplementedException();
42+
}
43+
44+
public void RunSimulation()
45+
{
46+
StartCoroutine(Sort());
47+
}
9548
}

0 commit comments

Comments
 (0)