Skip to content

Fix steps counting #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions VSharp.Explorer/AISearcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,28 @@ type internal AISearcher(oracle: Oracle, aiAgentTrainingMode: Option<AIAgentTrai

Application.applicationGraphDelta.Clear()

if aiMode <> Runner && stepsToPlay = stepsPlayed then
let toPredict =
match aiMode with
| TrainingSendEachStep
| TrainingSendModel ->
if stepsPlayed > 0u<step> then
gameStateDelta
else
gameState.Value
| Runner -> gameState.Value

let stateId = oracle.Predict toPredict
afterFirstAIPeek <- true
let state = availableStates |> Seq.tryFind (fun s -> s.internalId = stateId)
lastCollectedStatistics <- statistics
stepsPlayed <- stepsPlayed + 1u<step>

match state with
| Some state -> Some state
| None ->
incorrectPredictedStateId <- true
oracle.Feedback(Feedback.IncorrectPredictedStateId stateId)
None
else
let toPredict =
match aiMode with
| TrainingSendEachStep
| TrainingSendModel ->
if stepsPlayed > 0u<step> then
gameStateDelta
else
gameState.Value
| Runner -> gameState.Value

let stateId = oracle.Predict toPredict

afterFirstAIPeek <- true
let state = availableStates |> Seq.tryFind (fun s -> s.internalId = stateId)
lastCollectedStatistics <- statistics
stepsPlayed <- stepsPlayed + 1u<step>

match state with
| Some state -> Some state
| None ->
incorrectPredictedStateId <- true
oracle.Feedback(Feedback.IncorrectPredictedStateId stateId)
None

static member updateGameState (delta: GameState) (gameState: Option<GameState>) =
match gameState with
Expand Down
1 change: 1 addition & 0 deletions VSharp.ML.GameServer.Runner/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ let ws port outputDirectory (webSocket: WebSocket) (context: HttpContext) =
GameOver(
explorationResult.ActualCoverage,
explorationResult.TestsCount,
explorationResult.StepsCount,
explorationResult.ErrorsCount
)
)
Expand Down
10 changes: 6 additions & 4 deletions VSharp.ML.GameServer/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ type GameOverMessageBody =
interface IRawOutgoingMessageBody
val ActualCoverage: uint<percent>
val TestsCount: uint32<test>
val StepsCount: uint32<step>
val ErrorsCount: uint32<error>

new(actualCoverage, testsCount, errorsCount) =
new(actualCoverage, testsCount, stepsCount, errorsCount) =
{ ActualCoverage = actualCoverage
TestsCount = testsCount
StepsCount = stepsCount
ErrorsCount = errorsCount }

[<Struct>]
Expand Down Expand Up @@ -371,7 +373,7 @@ type IncorrectPredictedStateIdMessageBody =
new(stateId) = { StateId = stateId }

type OutgoingMessage =
| GameOver of uint<percent> * uint32<test> * uint32<error>
| GameOver of uint<percent> * uint32<test> * uint32<step> * uint32<error>
| MoveReward of Reward
| IncorrectPredictedStateId of uint<stateId>
| ReadyForNextStep of GameState
Expand All @@ -397,8 +399,8 @@ let deserializeInputMessage (messageData: byte[]) =

let serializeOutgoingMessage (message: OutgoingMessage) =
match message with
| GameOver(actualCoverage, testsCount, errorsCount) ->
RawOutgoingMessage("GameOver", box (GameOverMessageBody(actualCoverage, testsCount, errorsCount)))
| GameOver(actualCoverage, testsCount, stepsCount, errorsCount) ->
RawOutgoingMessage("GameOver", box (GameOverMessageBody(actualCoverage, testsCount, stepsCount, errorsCount)))
| MoveReward reward -> RawOutgoingMessage("MoveReward", reward)
| IncorrectPredictedStateId stateId ->
RawOutgoingMessage("IncorrectPredictedStateId", IncorrectPredictedStateIdMessageBody stateId)
Expand Down
Loading