Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
oetzit
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
Container 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
commul
oetzit
Commits
9c877ed9
Commit
9c877ed9
authored
2 years ago
by
Paolo.Brasolin
Browse files
Options
Downloads
Patches
Plain Diff
feat: #fe better difficulty ramp function
parent
2adae089
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/js/fight_scene.ts
+24
-14
24 additions, 14 deletions
frontend/src/js/fight_scene.ts
with
24 additions
and
14 deletions
frontend/src/js/fight_scene.ts
+
24
−
14
View file @
9c877ed9
...
@@ -470,22 +470,33 @@ export default class FightScene extends Phaser.Scene {
...
@@ -470,22 +470,33 @@ export default class FightScene extends Phaser.Scene {
return
scale
/
Math
.
pow
(
Math
.
random
(),
1
/
shape
);
return
scale
/
Math
.
pow
(
Math
.
random
(),
1
/
shape
);
}
}
getDifficulty
()
{
sawtoothRamp
(
t
:
number
,
peaksCount
=
10
,
dipsHeight
=
0.1
,
midwayAt
=
0.3
)
{
const
t
=
this
.
getGameTime
();
// https://www.desmos.com/calculator/7zcb6p8qeu
if
(
t
>=
15
*
60000
)
return
1
;
// NOTE: c'mon... 15 minutes?
// NOTE: this always maps [0;1] ↦ [0;1]
// NOTE: this ranges in [0;20]x[0;10]
const
ramp
=
t
*
(
peaksCount
*
dipsHeight
+
1
);
const
progression
=
(
t
)
=>
const
dips
=
(
t
+
Math
.
sin
((
2
*
Math
.
PI
*
t
)
/
4
)
+
Math
.
sin
(
2
*
Math
.
PI
*
t
))
/
2
;
(
-
Math
.
floor
(
t
*
peaksCount
)
*
(
peaksCount
*
dipsHeight
))
/
return
progression
((
t
*
15
)
/
20
/
60000
)
/
10
;
(
peaksCount
-
1
);
const
bend
=
Math
.
log
(
0.5
)
/
Math
.
log
(
midwayAt
);
return
Math
.
pow
(
ramp
+
dips
,
bend
);
}
getDifficulty
(
t
:
number
,
plateausAt
=
15
*
60000
)
{
// NOTE: c'mon... 15 minutes?
// NOTE: this maps [0;∞] ↦ [0;10]
if
(
t
>=
plateausAt
)
return
1
;
return
this
.
sawtoothRamp
(
t
/
plateausAt
)
*
10
;
}
}
async
spawnFoes
()
{
async
spawnFoes
()
{
const
difficulty
=
this
.
getDifficulty
(
this
.
getGameTime
());
const
AVG_WPM
=
40
;
// avg is 41.4, current world record is ~212wpm
const
AVG_WPM
=
40
;
// avg is 41.4, current world record is ~212wpm
const
minDelay
=
60
/
(
5.0
*
AVG_WPM
);
// 0.3s -> world record!
const
minDelay
=
60
/
(
5.0
*
AVG_WPM
);
// 0.3s -> world record!
const
maxDelay
=
60
/
(
0.2
*
AVG_WPM
);
// 7.5s -> utter boredom!
const
maxDelay
=
60
/
(
0.2
*
AVG_WPM
);
// 7.5s -> utter boredom!
// const expDelay = 60 / (1.0 * AVG_WPM); // 1.5s -> average typer
// const expDelay = 60 / (1.0 * AVG_WPM); // 1.5s -> average typer
const
expDelay
=
maxDelay
+
(
minDelay
-
maxDelay
)
*
this
.
getD
ifficulty
()
;
const
expDelay
=
maxDelay
+
(
minDelay
-
maxDelay
)
*
d
ifficulty
;
const
rate
=
1
/
expDelay
;
const
rate
=
1
/
expDelay
;
const
delay
=
const
delay
=
...
@@ -493,13 +504,12 @@ export default class FightScene extends Phaser.Scene {
...
@@ -493,13 +504,12 @@ export default class FightScene extends Phaser.Scene {
const
AVG_CPM
=
200
;
// corresponds to AVG_WPM and AVG_CPW = 5
const
AVG_CPM
=
200
;
// corresponds to AVG_WPM and AVG_CPW = 5
// const minLength = 1;
// const minLength = 1;
const
minLength
=
Math
.
round
(
1
+
(
3
-
1
)
*
this
.
getD
ifficulty
()
);
const
minLength
=
Math
.
round
(
1
+
(
3
-
1
)
*
d
ifficulty
);
// const maxLength = 12;
// const maxLength = 12;
const
maxLength
=
Math
.
round
(
6
+
(
18
-
6
)
*
this
.
getD
ifficulty
()
);
const
maxLength
=
Math
.
round
(
6
+
(
18
-
6
)
*
d
ifficulty
);
// const expLength = AVG_CPM / AVG_WPM; // i.e. 5 char is avg
// const expLength = AVG_CPM / AVG_WPM; // i.e. 5 char is avg
const
expLength
=
const
expLength
=
minLength
+
(
maxLength
-
minLength
)
*
difficulty
;
minLength
+
(
maxLength
-
minLength
)
*
this
.
getDifficulty
();
const
scale
=
minLength
;
const
scale
=
minLength
;
const
shape
=
expLength
/
(
expLength
-
scale
);
const
shape
=
expLength
/
(
expLength
-
scale
);
...
@@ -520,8 +530,8 @@ export default class FightScene extends Phaser.Scene {
...
@@ -520,8 +530,8 @@ export default class FightScene extends Phaser.Scene {
.
reduce
((
a
,
b
)
=>
a
+
b
,
0
);
.
reduce
((
a
,
b
)
=>
a
+
b
,
0
);
const
duration
=
const
duration
=
(
3
+
(
1
-
3
)
*
this
.
getD
ifficulty
()
)
*
(
3
+
(
1
-
3
)
*
d
ifficulty
)
*
(
expLength
+
(
length
-
expLength
)
*
this
.
getD
ifficulty
()
);
(
expLength
+
(
length
-
expLength
)
*
d
ifficulty
);
if
(
currentCount
<
maxCount
&&
currentChars
<
maxChars
)
{
if
(
currentCount
<
maxCount
&&
currentChars
<
maxChars
)
{
await
this
.
spawnFoe
(
length
,
duration
);
await
this
.
spawnFoe
(
length
,
duration
);
...
...
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