Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IGesture
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gawen.ackerman
IGesture
Commits
13e2a6c5
Commit
13e2a6c5
authored
1 month ago
by
gawen.ackerman
Browse files
Options
Downloads
Patches
Plain Diff
REMAKE : V2, collectible spawning generator using probability distribution
parent
4c2c3c33
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
impulse/Assets/Scripts/Road/CollectibleGenerator.cs
+22
-11
22 additions, 11 deletions
impulse/Assets/Scripts/Road/CollectibleGenerator.cs
with
22 additions
and
11 deletions
impulse/Assets/Scripts/Road/CollectibleGenerator.cs
+
22
−
11
View file @
13e2a6c5
...
...
@@ -41,27 +41,38 @@ public class CollectibleGenerator : MonoBehaviour
private
Transform
SelectSlotWithPreference
(
List
<
Transform
>
slots
,
int
preferenceCode
)
{
slots
.
Sort
((
a
,
b
)
=>
a
.
position
.
x
.
CompareTo
(
b
.
position
.
x
));
slots
.
Sort
((
a
,
b
)
=>
a
.
position
.
x
.
CompareTo
(
b
.
position
.
x
));
int
slotCount
=
slots
.
Count
;
int
chosenIndex
=
Random
.
Range
(
0
,
slotCount
);
float
[]
probabilities
;
switch
(
preferenceCode
)
{
case
1
:
chosenIndex
=
Random
.
Range
(
0
,
Mathf
.
Max
(
1
,
slotCount
/
3
));
probabilities
=
new
float
[]
{
0.6f
,
0.25f
,
0.15f
};
// Favor 0 slot
break
;
case
2
:
chosenIndex
=
Random
.
Range
(
0
,
slotCount
);
case
2
:
probabilities
=
new
float
[]
{
0.33f
,
0.33f
,
0.34f
};
// No favor
break
;
case
3
:
chosenIndex
=
Random
.
Range
(
2
*
slotCount
/
3
,
slotCount
);
case
3
:
probabilities
=
new
float
[]
{
0.15f
,
0.25f
,
0.6f
};
// Favor 2 slot
break
;
default
:
chosenIndex
=
Random
.
Range
(
0
,
slotCount
);
default
:
probabilities
=
new
float
[]
{
0.33f
,
0.33f
,
0.34f
};
// Security of all distribution proba
break
;
}
return
slots
[
chosenIndex
];
float
randomValue
=
Random
.
value
;
float
cumulativeProbability
=
0f
;
for
(
int
i
=
0
;
i
<
slots
.
Count
;
i
++)
{
cumulativeProbability
+=
probabilities
[
i
];
if
(
randomValue
<=
cumulativeProbability
)
return
slots
[
i
];
}
return
slots
[
2
];
// Security if random.value == 1
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment