void ribi::gtst::ParticipantDialogStateAssignPayoff::RespondToTimedServerPush() { assert(GetDialog()->CanGetParticipant() && "Assume that only existing participants can have their payoffs assigned"); //Do nothing... //Display the Participant RespondToParticipant(); }
//--------------------------------------------------------------------------- void ribi::gtst::ParticipantDialogStateLoggedIn::RespondToTimedServerPush() { const auto participant = GetDialog()->GetParticipant(); if (dynamic_cast<const ParticipantStateLoggedIn*>(participant->GetState())) { const ParticipantStateLoggedIn* const state = dynamic_cast<const ParticipantStateLoggedIn*>(participant->GetState()); ui.m_label_status->setText(state->GetMessage().c_str()); } RespondToParticipant(); }
void ribi::gtst::ParticipantDialogStateGroupReAssign::RespondToTimedServerPush() { assert(GetDialog()->CanGetParticipant() && "Assume that only existing participants can have their payoffs assigned"); //Update label_time_left { const int time_left = m_server->GetStates()->GetCurrentState()->GetTimeLeft(); const std::string text = std::string("Time left: ") + std::to_string(time_left) + std::string(" seconds "); assert(ui.m_label_time_left); ui.m_label_time_left->setText(text.c_str()); } ///Follow the server its tempo RespondToParticipant(); }
//--------------------------------------------------------------------------- void ParticipantDialogStateGroupAssign::RespondToTimedServerPush() { assert(GetDialog()->CanGetParticipant() && "Assume that only existing participants can have their payoffs assigned"); const auto participant = GetDialog()->GetParticipant(); assert(participant); ServerStateGroupAssign * const server_state = dynamic_cast<ServerStateGroupAssign*>(m_server->GetStates()->GetCurrentState()); if (!server_state) { std::clog << __func__ << ": warning: no ServerStateGroupAssign\n"; return; } //Is the Participant waiting to be assigned to a group? if (m_server->GetGroups()->FindMyGroup(participant) == m_server->GetGroups()->GetGroupLoggedIn()) { //Can the server assign the Participant to a group? if (server_state->CanAssignGroup(participant)) { //Assign the Participant to a group server_state->AssignGroup(participant); assert(m_server->GetGroups()->FindMyGroup(participant) != m_server->GetGroups()->GetGroupLoggedIn()); } } //Display the group the Participant is in { const Group * const group = m_server->GetGroups()->FindMyGroup(participant); //Update the status label const std::string message = m_server->GetParameters()->GetGroupAssign()->GetMessageAssigned() + std::to_string(group->GetId()) + (dynamic_cast<const GroupNotLoggedIn *>(group) ? std::string(" (not participating)") : std::string(" (participating)")); assert(ui.m_label_group); ui.m_label_group->setText(message.c_str()); } //const boost::shared_ptr<const Participant> participant = GetDialog()->GetParticipant(); assert(participant); //if (dynamic_cast<const ParticipantStateGroupAssign*>(participant->GetState())) //{ // const ParticipantStateGroupAssign* const state // = dynamic_cast<const ParticipantStateGroupAssign*>(participant->GetState()); // ui.m_label_status->setText(state->GetMessage().c_str()); //} ///Follow the server its tempo RespondToParticipant(); }
void ribi::gtst::ParticipantDialogStateChooseAction::RespondToTimedServerPush() { const int time_left = m_server->GetStates()->GetCurrentState()->GetTimeLeft(); //Update label_time_left { std::string text = std::string("Time left: ") + std::to_string(time_left) + std::string(" seconds"); if (m_server->GetParameters()->GetChooseAction()->GetWait()) { //Infinite time text+=std::string(" (waiting for others)"); } assert(ui.m_label_time_left); ui.m_label_time_left->setText(text.c_str()); } //Check if choice must be sent to the server if (!m_server->GetParameters()->GetChooseAction()->GetWait() && time_left <= 0) { assert(GetDialog()); assert(GetDialog()->CanGetParticipant()); if (ui.m_button_choose_action->isEnabled()) { //Let Participant choose a random action by time const int selected = ui.m_group->selectedButtonIndex(); assert(ui.m_group->count() > 0); const int action_index = (selected == -1 //Did user select something? ? std::rand() % ui.m_group->count() //Take a random action : selected); assert(action_index > -1 && action_index < ui.m_group->count()); ui.m_group->setSelectedButtonIndex(action_index); OnChooseActionClick(); } } if (!ui.m_button_choose_action->isEnabled()) { assert(ui.m_group->selectedButtonIndex() != -1 && "m_button_choose_action should only disable when an action is selected"); const std::vector<boost::shared_ptr<ChooseActionOption> >& options = m_server->GetParameters()->GetChooseAction()->GetOptions(); assert(ui.m_group->selectedButtonIndex() < static_cast<int>(options.size())); const boost::shared_ptr<ChooseActionOption> option = options[ ui.m_group->selectedButtonIndex() ]; const std::string text = option->GetMessageChoice() + std::string("\', waiting for the others..."); ui.m_label_status->setText(text.c_str()); } else { ui.m_label_status->setText("Please choose an action."); } ///Follow the server its tempo RespondToParticipant(); }