Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
big-brain
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
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
Louis
big-brain
Commits
a76dcbb6
Commit
a76dcbb6
authored
3 years ago
by
Kat Marchán
Browse files
Options
Downloads
Patches
Plain Diff
fix(choice): return &Choice instead of cloning
parent
372c13e2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pickers.rs
+3
-3
3 additions, 3 deletions
src/pickers.rs
src/thinker.rs
+2
-7
2 additions, 7 deletions
src/thinker.rs
with
5 additions
and
10 deletions
src/pickers.rs
+
3
−
3
View file @
a76dcbb6
...
@@ -12,7 +12,7 @@ Required trait for Pickers. A Picker is given a slice of choices and a query tha
...
@@ -12,7 +12,7 @@ Required trait for Pickers. A Picker is given a slice of choices and a query tha
Implementations of `pick` must return `Some(Choice)` for the `Choice` that was picked, or `None`.
Implementations of `pick` must return `Some(Choice)` for the `Choice` that was picked, or `None`.
*/
*/
pub
trait
Picker
:
std
::
fmt
::
Debug
+
Sync
+
Send
{
pub
trait
Picker
:
std
::
fmt
::
Debug
+
Sync
+
Send
{
fn
pick
(
&
self
,
_
choices
:
&
[
Choice
],
_utiliti
es
:
&
Query
<&
Score
>
)
->
Option
<
Choice
>
;
fn
pick
<
'a
>
(
&
self
,
choices
:
&
'a
[
Choice
],
scor
es
:
&
Query
<&
Score
>
)
->
Option
<
&
'a
Choice
>
;
}
}
/**
/**
...
@@ -38,11 +38,11 @@ impl FirstToScore {
...
@@ -38,11 +38,11 @@ impl FirstToScore {
}
}
impl
Picker
for
FirstToScore
{
impl
Picker
for
FirstToScore
{
fn
pick
(
&
self
,
choices
:
&
[
Choice
],
scores
:
&
Query
<&
Score
>
)
->
Option
<
Choice
>
{
fn
pick
<
'a
>
(
&
self
,
choices
:
&
'a
[
Choice
],
scores
:
&
Query
<&
Score
>
)
->
Option
<
&
'a
Choice
>
{
for
choice
in
choices
{
for
choice
in
choices
{
let
value
=
choice
.calculate
(
scores
);
let
value
=
choice
.calculate
(
scores
);
if
value
>=
self
.threshold
{
if
value
>=
self
.threshold
{
return
Some
(
choice
.clone
()
);
return
Some
(
choice
);
}
}
}
}
None
None
...
...
This diff is collapsed.
Click to expand it.
src/thinker.rs
+
2
−
7
View file @
a76dcbb6
...
@@ -241,13 +241,8 @@ pub fn thinker_system(
...
@@ -241,13 +241,8 @@ pub fn thinker_system(
// Think about what action we're supposed to be taking. We do this
// Think about what action we're supposed to be taking. We do this
// every tick, because we might change our mind.
// every tick, because we might change our mind.
// ...and then execute it (details below).
// ...and then execute it (details below).
exec_picked_action
(
let
action
=
choice
.action
.clone
();
&
mut
cmd
,
exec_picked_action
(
&
mut
cmd
,
*
actor
,
&
mut
thinker
,
&
action
,
&
mut
action_states
);
*
actor
,
&
mut
thinker
,
&
choice
.action
,
&
mut
action_states
,
);
}
else
if
let
Some
(
default_action_ent
)
=
&
thinker
.otherwise
{
}
else
if
let
Some
(
default_action_ent
)
=
&
thinker
.otherwise
{
// Otherwise, let's just execute the default one! (if it's there)
// Otherwise, let's just execute the default one! (if it's there)
let
default_action_ent
=
default_action_ent
.clone
();
let
default_action_ent
=
default_action_ent
.clone
();
...
...
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