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
fa4d695a
Commit
fa4d695a
authored
3 years ago
by
Paolo.Brasolin
Browse files
Options
Downloads
Patches
Plain Diff
reafactor: #fe reintroduce Foe as coordinator
parent
642b40ad
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/js/fight_scene.ts
+33
-43
33 additions, 43 deletions
frontend/src/js/fight_scene.ts
frontend/src/js/foe.ts
+29
-0
29 additions, 0 deletions
frontend/src/js/foe.ts
with
62 additions
and
43 deletions
frontend/src/js/fight_scene.ts
+
33
−
43
View file @
fa4d695a
import
"
phaser
"
;
import
"
phaser
"
;
import
Critter
from
"
./critter
"
;
import
Spear
from
"
./spear
"
;
import
Spear
from
"
./spear
"
;
import
backend
from
"
./backend
"
;
import
backend
from
"
./backend
"
;
// TODO: write interfaces
// TODO: write interfaces
import
levenshtein
from
"
damerau-levenshtein
"
;
import
levenshtein
from
"
damerau-levenshtein
"
;
import
Clue
from
"
./clue
"
;
import
*
as
Types
from
"
../../../backend/src/types
"
;
import
*
as
Types
from
"
../../../backend/src/types
"
;
import
Foe
from
"
./foe
"
;
export
default
class
FightScene
extends
Phaser
.
Scene
{
export
default
class
FightScene
extends
Phaser
.
Scene
{
foes
:
Array
<
Critter
>
;
foes
:
Array
<
Foe
>
;
ground
:
Phaser
.
Types
.
Physics
.
Arcade
.
ImageWithStaticBody
;
ground
:
Phaser
.
Types
.
Physics
.
Arcade
.
ImageWithStaticBody
;
player
:
Phaser
.
Types
.
Physics
.
Arcade
.
SpriteWithDynamicBody
;
player
:
Phaser
.
Types
.
Physics
.
Arcade
.
SpriteWithDynamicBody
;
cluesGroup
:
Phaser
.
Physics
.
Arcade
.
Group
;
cluesGroup
:
Phaser
.
Physics
.
Arcade
.
Group
;
...
@@ -197,18 +196,18 @@ export default class FightScene extends Phaser.Scene {
...
@@ -197,18 +196,18 @@ export default class FightScene extends Phaser.Scene {
});
});
}
}
shootSpear
(
enemy
:
Critter
,
hit
:
boolean
)
{
shootSpear
(
foe
:
Foe
|
null
,
hit
:
boolean
)
{
const
scene
=
this
;
const
scene
=
this
;
if
(
!
hit
)
{
if
(
foe
===
null
||
!
hit
)
{
this
.
showMissMessage
();
this
.
showMissMessage
();
new
Spear
(
this
,
this
.
player
,
undefined
);
}
else
{
}
else
{
this
.
showHitMessage
();
this
.
showHitMessage
();
// TODO: ew.
// TODO: ew.
enemy
.
clue
.
delete
();
foe
.
clue
.
delete
();
scene
.
foes
.
splice
(
scene
.
foes
.
indexOf
(
enemy
),
1
);
// FIXME
// scene.foes.splice(scene.foes.indexOf(foe), 1); // FIXME
new
Spear
(
this
,
this
.
player
,
foe
.
critter
);
}
}
new
Spear
(
this
,
this
.
player
,
hit
?
enemy
:
undefined
);
}
}
initCluesGroup
()
{
initCluesGroup
()
{
...
@@ -226,6 +225,25 @@ export default class FightScene extends Phaser.Scene {
...
@@ -226,6 +225,25 @@ export default class FightScene extends Phaser.Scene {
});
});
this
.
physics
.
add
.
collider
(
this
.
cluesGroup
,
this
.
cluesGroup
);
this
.
physics
.
add
.
collider
(
this
.
cluesGroup
,
this
.
cluesGroup
);
}
}
findMatchingFoe
(
transcription
:
string
)
{
let
result
:
{
score
:
number
;
match
:
Foe
|
null
}
=
{
score
:
-
1
,
match
:
null
,
};
if
(
this
.
foes
.
length
<
1
)
return
result
;
this
.
foes
.
forEach
((
foe
)
=>
{
const
similarity
=
levenshtein
(
transcription
.
toLowerCase
(),
foe
.
beWord
.
ocr_transcript
.
toLowerCase
(),
).
similarity
;
if
(
similarity
<
result
.
score
)
return
;
result
=
{
score
:
similarity
,
match
:
foe
};
});
// match ??= scene.foes[0]; // TODO: remove this
// console.log(similarity, match.beWord.ocr_transcript);
return
result
;
}
}
}
// TODO: remove any
// TODO: remove any
...
@@ -307,50 +325,22 @@ function initAndBindGuessPreview(scene: FightScene) {
...
@@ -307,50 +325,22 @@ function initAndBindGuessPreview(scene: FightScene) {
}
}
function
submitTranscription
(
transcription
:
string
,
scene
:
FightScene
)
{
function
submitTranscription
(
transcription
:
string
,
scene
:
FightScene
)
{
if
(
scene
.
foes
.
length
<
1
)
return
;
const
{
score
,
match
}
=
scene
.
findMatchingFoe
(
transcription
);
scene
.
shootSpear
(
match
,
score
>=
0.9
);
let
similarity
=
0
;
let
match
=
null
;
scene
.
foes
.
forEach
((
critter
)
=>
{
const
s
=
levenshtein
(
transcription
.
toLowerCase
(),
critter
.
clue
.
word
.
ocr_transcript
.
toLowerCase
(),
).
similarity
;
if
(
s
<
similarity
)
return
;
similarity
=
s
;
match
=
critter
;
});
match
??=
scene
.
foes
[
0
];
// TODO: remove this
console
.
log
(
similarity
,
match
.
clue
.
word
.
ocr_transcript
);
// TODO: we can have near misses depending on similarity!
const
hit
=
similarity
>=
0.9
;
const
enemy
=
match
;
scene
.
shootSpear
(
enemy
,
hit
);
}
}
function
gameStart
(
scene
:
any
)
{
function
gameStart
(
scene
:
any
)
{
spawn
(
scene
);
spawn
(
scene
);
// dispatchEnemy(scene);
}
}
function
spawn
(
scene
:
any
)
{
async
function
spawn
(
scene
:
any
)
{
dispatchEnemy
(
scene
);
await
dispatchEnemy
(
scene
);
scene
.
time
.
now
;
scene
.
time
.
now
;
const
delay
=
const
delay
=
(
8
*
1000
*
(
60
*
1000
-
scene
.
time
.
now
))
/
60
/
1000
+
2
*
1000
;
(
8
*
1000
*
(
60
*
1000
-
scene
.
time
.
now
))
/
60
/
1000
+
2
*
1000
;
setTimeout
(()
=>
spawn
(
scene
),
Math
.
max
(
delay
,
2000
));
setTimeout
(()
=>
spawn
(
scene
),
Math
.
max
(
delay
,
2000
));
}
}
function
dispatchEnemy
(
scene
:
any
)
{
async
function
dispatchEnemy
(
scene
:
any
)
{
backend
.
getWord
().
then
(
function
(
response
)
{
await
new
Foe
(
scene
).
initialize
();
const
clue
=
new
Clue
(
scene
,
response
.
data
);
const
critter
=
new
Critter
(
scene
,
clue
);
// TODO: clue
scene
.
foes
.
push
(
critter
);
});
}
}
This diff is collapsed.
Click to expand it.
frontend/src/js/foe.ts
0 → 100644
+
29
−
0
View file @
fa4d695a
import
"
phaser
"
;
import
Clue
from
"
./clue
"
;
import
Critter
from
"
./critter
"
;
import
FightScene
from
"
./fight_scene
"
;
import
backend
from
"
./backend
"
;
import
*
as
Types
from
"
../../../backend/src/types
"
;
class
Foe
{
beWord
:
Types
.
Word
;
beClue
:
Types
.
Clue
;
scene
:
FightScene
;
critter
:
Critter
;
clue
:
Clue
;
constructor
(
scene
:
FightScene
)
{
this
.
scene
=
scene
;
}
async
initialize
()
{
this
.
beWord
=
(
await
backend
.
getWord
()).
data
;
this
.
clue
=
new
Clue
(
this
.
scene
,
this
.
beWord
);
this
.
critter
=
new
Critter
(
this
.
scene
,
this
.
clue
);
this
.
scene
.
foes
.
push
(
this
);
}
}
export
default
Foe
;
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