Skip to content
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

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

Open
monarchBacilluscoli opened this issue Dec 11, 2019 · 0 comments

Comments

@monarchBacilluscoli
Copy link

monarchBacilluscoli commented Dec 11, 2019

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
        }
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant