Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
714a9480
Unverified
Commit
714a9480
authored
Jun 27, 2023
by
OptimismBot
Committed by
GitHub
Jun 27, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6169 from ethereum-optimism/jg/game_agent
op-challenger: Add basic agent
parents
dc03b1c9
e40b268f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
agent.go
op-challenger/fault/agent.go
+57
-0
No files found.
op-challenger/fault/agent.go
0 → 100644
View file @
714a9480
package
fault
import
(
"context"
"sync"
)
type
Agent
struct
{
mu
sync
.
Mutex
game
Game
solver
*
Solver
trace
TraceProvider
responder
Responder
maxDepth
int
}
func
NewAgent
(
game
Game
,
maxDepth
int
,
trace
TraceProvider
,
responder
Responder
)
Agent
{
return
Agent
{
game
:
game
,
solver
:
NewSolver
(
maxDepth
,
trace
),
trace
:
trace
,
responder
:
responder
,
maxDepth
:
maxDepth
,
}
}
// AddClaim stores a claim in the local state.
// This function shares a lock with PerformActions.
func
(
a
*
Agent
)
AddClaim
(
claim
Claim
)
error
{
a
.
mu
.
Lock
()
defer
a
.
mu
.
Unlock
()
return
a
.
game
.
Put
(
claim
)
}
// PerformActions iterates the game & performs all of the next actions.
// Note: PerformActions & AddClaim share a lock so the responder cannot
// call AddClaim on the same thread.
func
(
a
*
Agent
)
PerformActions
()
{
a
.
mu
.
Lock
()
defer
a
.
mu
.
Unlock
()
for
_
,
pair
:=
range
a
.
game
.
ClaimPairs
()
{
_
=
a
.
move
(
pair
.
claim
,
pair
.
parent
)
}
}
// move determines & executes the next move given a claim pair
func
(
a
*
Agent
)
move
(
claim
,
parent
Claim
)
error
{
move
,
err
:=
a
.
solver
.
NextMove
(
claim
)
if
err
!=
nil
||
move
==
nil
{
return
err
}
// TODO(CLI-4123): Don't send duplicate responses
// if a.game.IsDuplicate(move) {
// return nil
// }
return
a
.
responder
.
Respond
(
context
.
TODO
(),
*
move
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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