Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PublicGroup
QuantumWheelPublic
Commits
ea743dbd
Commit
ea743dbd
authored
Feb 06, 2019
by
Mikko Lainio
🇺🇦
Browse files
Replaced boxes with ragdoll men. Added percentage of well pop visible.
parent
7e98f4bc
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
QuantumWheel/Assets/Plugins/QuantumWheel/Prefabs.meta
0 → 100644
View file @
ea743dbd
fileFormatVersion: 2
guid: bb6569a682674d6429de1b9a9eaf4327
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
QuantumWheel/Assets/Plugins/QuantumWheel/Prefabs/BlockDude.prefab
0 → 100644
View file @
ea743dbd
This diff is collapsed.
Click to expand it.
QuantumWheel/Assets/Plugins/QuantumWheel/Prefabs/BlockDude.prefab.meta
0 → 100644
View file @
ea743dbd
fileFormatVersion: 2
guid: 3653bf778ef537c4cabd156f2f246dfd
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
QuantumWheel/Assets/Plugins/QuantumWheel/Scenes/Demo.unity
View file @
ea743dbd
This diff is collapsed.
Click to expand it.
QuantumWheel/Assets/Plugins/QuantumWheel/Scripts/Demo/
Cube
Controller.cs
→
QuantumWheel/Assets/Plugins/QuantumWheel/Scripts/Demo/
Hanger
Controller.cs
View file @
ea743dbd
...
...
@@ -4,12 +4,14 @@ using System.Collections.Generic;
using
UnityEngine
;
using
UnityEngine.Experimental.UIElements
;
public
class
Cube
Controller
:
MonoBehaviour
public
class
Hanger
Controller
:
MonoBehaviour
{
public
enum
CubePosition
{
None
,
Left
,
Right
Right
,
Mid
}
public
KeyCode
MoveLeft
=
KeyCode
.
A
;
...
...
@@ -18,22 +20,44 @@ public class CubeController : MonoBehaviour
public
CubePosition
cPosition
;
private
Vector3
m_defaultPos
;
private
Rigidbody
m_rb
;
public
TMPro
.
TextMeshProUGUI
textObj
;
private
float
m_heightTarget
;
private
bool
m_noMove
=
false
;
// Start is called before the first frame update
void
Awake
()
{
QuantumDemoManager
.
RegisterController
(
this
,
cPosition
);
m_defaultPos
=
transform
.
position
;
m_rb
=
GetComponent
<
Rigidbody
>();
}
private
void
OnEnable
()
{
transform
.
position
=
m_defaultPos
;
StartCoroutine
(
LerpMove
(
m_defaultPos
,
0.5f
))
;
UpdateTextObject
();
}
private
IEnumerator
LerpMove
(
Vector3
p
,
float
time
)
{
m_noMove
=
true
;
float
t
=
0
;
Vector3
start
=
transform
.
position
;
while
(
t
<
time
)
{
yield
return
new
WaitForEndOfFrame
();
t
+=
Time
.
deltaTime
;
float
pt
=
t
/
time
;
transform
.
position
=
(
Vector3
.
Lerp
(
start
,
p
,
pt
));
}
m_noMove
=
false
;
}
// Update is called once per frame
void
Update
()
{
...
...
@@ -46,10 +70,21 @@ public class CubeController : MonoBehaviour
Move
(
1f
);
}
UpdateTextObject
();
}
private
void
FixedUpdate
()
{
if
(
m_noMove
)
return
;
Vector3
v
=
m_rb
.
position
;
v
.
y
=
m_heightTarget
;
Vector3
deltaMove
=
v
-
m_rb
.
position
;
m_rb
.
MovePosition
(
m_rb
.
position
+
deltaMove
*
Time
.
fixedDeltaTime
);
}
p
rivate
void
UpdateTextObject
()
p
ublic
void
UpdateTextObject
()
{
if
(
textObj
!=
null
)
{
...
...
@@ -57,10 +92,23 @@ public class CubeController : MonoBehaviour
}
}
public
void
UpdateTextObject
(
float
p
)
{
if
(
textObj
!=
null
)
{
textObj
.
text
=
cPosition
+
$"\n
{
MoveLeft
}
<->
{
MoveRight
}
\n"
+
CurrentInputPosition
+
"\n"
+
p
.
ToString
(
"P0"
);
}
}
private
void
Move
(
float
dir
)
{
if
(
m_noMove
)
return
;
transform
.
position
+=
Vector3
.
right
*
dir
*
Time
.
deltaTime
;
//clamp the position
float
x
=
transform
.
position
.
x
-
m_defaultPos
.
x
;
x
=
Mathf
.
Min
(
1f
,
Mathf
.
Max
(
x
,
-
1f
));
Vector3
v
=
transform
.
position
;
...
...
@@ -69,4 +117,11 @@ public class CubeController : MonoBehaviour
}
public
float
CurrentInputPosition
=>
transform
.
position
.
x
-
m_defaultPos
.
x
;
public
void
SetHeight
(
float
h
)
{
m_heightTarget
=
h
;
}
}
QuantumWheel/Assets/Plugins/QuantumWheel/Scripts/Demo/
Cube
Controller.cs.meta
→
QuantumWheel/Assets/Plugins/QuantumWheel/Scripts/Demo/
Hanger
Controller.cs.meta
View file @
ea743dbd
File moved
QuantumWheel/Assets/Plugins/QuantumWheel/Scripts/Demo/MaterialColorChanger.cs
View file @
ea743dbd
...
...
@@ -4,16 +4,37 @@ using UnityEngine;
public
class
MaterialColorChanger
:
MonoBehaviour
{
[
SerializeField
]
private
Renderer
m_renderer
;
[
SerializeField
]
private
GameObject
parentObject
;
private
Renderer
[]
m_renderers
;
private
Renderer
m_singleRenderer
;
public
bool
FindAll
=
false
;
// Start is called before the first frame update
void
Start
()
{
if
(
FindAll
)
{
m_renderers
=
parentObject
.
GetComponentsInChildren
<
Renderer
>();
}
else
{
m_singleRenderer
=
parentObject
.
GetComponentInChildren
<
Renderer
>();
}
}
public
void
SetColor
(
Color
c
)
{
m_renderer
.
material
.
SetColor
(
"_Color"
,
c
);
if
(
m_singleRenderer
!=
null
)
m_singleRenderer
.
material
.
SetColor
(
"_Color"
,
c
);
if
(
m_renderers
.
Length
>
0
)
{
foreach
(
Renderer
r
in
m_renderers
)
{
r
.
material
.
SetColor
(
"_Color"
,
c
);
}
}
}
}
QuantumWheel/Assets/Plugins/QuantumWheel/Scripts/Demo/QuantumDemoManager.cs
View file @
ea743dbd
...
...
@@ -23,9 +23,9 @@ public class QuantumDemoManager : MonoBehaviour
}
}
private
Cube
Controller
m_left
;
private
Cube
Controller
m_right
;
[
SerializeField
]
private
Transform
m_mid
;
private
Hanger
Controller
m_left
;
private
Hanger
Controller
m_right
;
private
HangerController
m_mid
;
private
StirapEnv
m_env
;
...
...
@@ -158,11 +158,13 @@ public class QuantumDemoManager : MonoBehaviour
/// <returns></returns>
private
IEnumerator
GameCoroutine
()
{
float
time
,
delta
;
int
step
=
0
;
ResetGrowthMeasures
();
// Run the stirap env step at intervals determined by UpdateFrequency, until the result states Done.
yield
return
new
WaitForSeconds
(
1f
);
do
{
time
=
Time
.
time
;
...
...
@@ -211,49 +213,31 @@ public class QuantumDemoManager : MonoBehaviour
result
=
m_env
.
Step
(
left
,
right
);
}
Vector3
leftScale
=
m_left
.
transform
.
localScale
;
Vector3
rightScale
=
m_right
.
transform
.
localScale
;
Vector3
midScale
=
m_mid
.
localScale
;
float
lastRightScale
=
rightScale
.
y
;
float
lastMidScale
=
midScale
.
y
;
float
lastLeftScale
=
leftScale
.
y
;
leftScale
.
y
=
result
.
Observation
[
0
]
*
3f
;
rightScale
.
y
=
result
.
Observation
[
1
]
*
3f
;
midScale
.
y
=
3f
-
(
leftScale
.
y
+
rightScale
.
y
);
m_growthRight
.
Update
(
rightScale
.
y
-
lastRightScale
);
m_growthMid
.
Update
(
midScale
.
y
-
lastMidScale
);
m_growthLeft
.
Update
(
leftScale
.
y
-
lastLeftScale
);
// if (m_growthRight.Count > m_growthBuffer)
// m_growthRight.RemoveAt(0);
// m_growthRight.Add(growth);
//
// growth = 0f;
// foreach (float g in m_growthRight)
// {
// growth += g;
// }
//
// growth /= m_growthRight.Count;
m_left
.
transform
.
localScale
=
leftScale
;
m_right
.
transform
.
localScale
=
rightScale
;
m_mid
.
localScale
=
midScale
;
float
leftPop
=
result
.
LeftPopulation
;
float
rightPop
=
result
.
RightPopulation
;
float
midPop
=
1f
-
(
leftPop
+
rightPop
);
float
lPos
=
result
.
Observation
[
2
];
float
rPos
=
result
.
Observation
[
3
];
//m_left.transform.position = new Vector3(lPos * 2, 0f, 0f) + Vector3.left * 2f;
//m_right.transform.position = new Vector3(rPos * 2, 0f, 0f) + Vector3.right * 2f;
UpdateWell
(
m_right
,
rightPop
,
m_growthRight
);
UpdateWell
(
m_left
,
leftPop
,
m_growthLeft
);
UpdateWell
(
m_mid
,
midPop
,
m_growthMid
);
RenderPlot
(
result
);
SetScore
(
result
.
RightPopulation
,
step
);
return
result
.
Done
;
}
private
void
UpdateWell
(
HangerController
t
,
float
value
,
RingBuffer
growthMeasure
)
{
Vector3
p
=
t
.
transform
.
position
;
float
last
=
p
.
y
;
p
.
y
=
value
*
5f
;
growthMeasure
.
Update
(
p
.
y
-
last
);
t
.
SetHeight
(
p
.
y
);
t
.
UpdateTextObject
(
value
);
}
private
void
RenderPlot
(
StirapEnv
.
StepResult
result
)
{
if
(
m_plotRenderer
==
null
)
...
...
@@ -299,7 +283,7 @@ public class QuantumDemoManager : MonoBehaviour
// }
//float v = growth / MaxGradientThreshold;
float
scale
=
1
0000
;
float
scale
=
1
;
float
r
=
Mathf
.
Max
(
0f
,
Mathf
.
Min
(
1f
,
0.5f
+
m_growthRight
.
Average
*
scale
/
MaxGradientThreshold
));
float
l
=
Mathf
.
Max
(
0f
,
Mathf
.
Min
(
1f
,
0.5f
+
m_growthLeft
.
Average
*
scale
/
MaxGradientThreshold
));
float
m
=
Mathf
.
Max
(
0f
,
Mathf
.
Min
(
1f
,
0.5f
+
m_growthMid
.
Average
*
scale
/
2f
/
MaxGradientThreshold
));
...
...
@@ -307,6 +291,7 @@ public class QuantumDemoManager : MonoBehaviour
Color
right
=
m_rewardGradient
.
Evaluate
(
r
);
Color
left
=
m_rewardGradient
.
Evaluate
(
1
-
l
);
Color
mid
=
m_rewardGradient
.
Evaluate
(
m
);
m_leftColor
.
SetColor
(
left
);
m_rightColor
.
SetColor
(
right
);
m_midColor
.
SetColor
(
mid
);
...
...
@@ -314,13 +299,15 @@ public class QuantumDemoManager : MonoBehaviour
}
public
static
void
RegisterController
(
Cube
Controller
ctrl
,
Cube
Controller
.
CubePosition
cPosition
)
public
static
void
RegisterController
(
Hanger
Controller
ctrl
,
Hanger
Controller
.
CubePosition
cPosition
)
{
switch
(
cPosition
)
{
case
CubeController
.
CubePosition
.
Left
:
Instance
.
m_left
=
ctrl
;
case
HangerController
.
CubePosition
.
Left
:
Instance
.
m_left
=
ctrl
;
break
;
case
HangerController
.
CubePosition
.
Right
:
Instance
.
m_right
=
ctrl
;
break
;
case
Cube
Controller
.
CubePosition
.
Right
:
Instance
.
m_
right
=
ctrl
;
case
Hanger
Controller
.
CubePosition
.
Mid
:
Instance
.
m_
mid
=
ctrl
;
break
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment