Skip to content

In nonmultithreaded, multi-player game, the call of OnGameEnd() is missing. #325

@monarchBacilluscoli

Description

@monarchBacilluscoli

I guess the problem comes from here
Just see the comments

void CoordinatorImp::StepAgents() {
    auto step_agent = [this](Agent* a) {
        ControlInterface* control = a->Control();

        if (control->GetAppState() != AppState::normal) {
            return;
        }

        if (control->PollLeaveGame()) {
            return;
        }

        if (control->IsFinishedGame()) {
            return;
        }

        control->Step(process_settings_.step_size);
        control->WaitStep();                        //1. from here we know the game has been end.
        if (process_settings_.multi_threaded) {
            CallOnStep(a);                          //2. The first chance to call the CallOnStep() is missing (This function will call OnGameEnd() based on whether the Agent is in game or not) since it is not a multi_threaded game according to my settings.
        }
    };

    if (agents_.size() == 1) {
        step_agent(agents_.front()); 
    }
    else {
        RunParallel(step_agent, agents_);           // 0. Normal opeartion as usual
    }

    if (!process_settings_.multi_threaded) {
        for (auto a : agents_) {
            if (a->Control()->GetAppState() != AppState::normal) {
                continue;
            }

            // It is possible to have a pending leave game request here.
            if (a->Control()->PollLeaveGame()) {    // 3. In PollLeaveGame() it checks if the Agent is in game, is not, return true and continue
                continue;
            }

            CallOnStep(a);                          // 4. Because of step 3, the last precious call of CallOnStep (that is, the call of OnGameEnd() as I have mentioned in step 2) is missing again
        }
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions