Bataille::Bataille(Joueur *Joueur1, Armee *ArmeeJoueur1, Joueur *Joueur2, Armee *ArmeeJoueur2) { m_ListeParticipants = QList<Participant>(); m_ListeParticipants.append(Participant(Joueur1, ArmeeJoueur1)); m_ListeParticipants.append(Participant(Joueur2, ArmeeJoueur2)); double dif = (m_ListeParticipants[0].m_ListeArmees[0]->m_NbrPixels - m_ListeParticipants[1].m_ListeArmees[0]->m_NbrPixels) / 1000.0; m_ListeParticipants[0].m_Efficacite += dif; m_ListeParticipants[1].m_Efficacite -= dif; }
void Bataille::AjouterParticipant(Joueur *joueur, Armee *armee) { int I = 0; while (I < m_ListeParticipants.count() && m_ListeParticipants[I].m_Proprietaire != joueur) I++; if (I == m_ListeParticipants.count()) { qDebug("Ajout du nouveau participant"); m_ListeParticipants.append(Participant(joueur, armee)); } else { int J = 0; while (J < m_ListeParticipants[I].m_ListeArmees.count() && m_ListeParticipants[I].m_ListeArmees[J] != armee) J++; if (J == m_ListeParticipants[I].m_ListeArmees.count()) { qDebug("Ajout de son armee"); m_ListeParticipants[I].m_ListeArmees.append(armee); } } }
// ---------------------------------------------------------------------------- // void ScenePixelAnimator::initAnimation( AnimationTask* task, DWORD time_ms, BYTE* dmx_packet ) { m_animation_task = task; m_channel_animations.clear(); typedef std::vector<Participant> ParticipantArray; ParticipantArray participants; // Determine which channels will be participating for ( UID actor_uid : populateActors() ) { Fixture* pf = m_animation_task->getActorRepresentative( actor_uid ); if ( pf->getNumPixels() > 0 ) { participants.push_back( Participant( actor_uid, pf->getPixels() ) ); } } if ( participants.size() > 0 ) { PixelEngine engine; if ( m_combine_fixtures ) { for ( Participant& p : participants ) engine.loadPixels( p.m_actor_uid, p.m_pixels ); generateEffect( engine ); } else { for ( Participant& p : participants ) { engine.clear(); engine.loadPixels( p.m_actor_uid, p.m_pixels ); generateEffect( engine ); } } } SceneChannelAnimator::initAnimation( task, time_ms, dmx_packet ); }
void Battle::set_up_participants() { BOOST_LOG_TRIVIAL(trace) << "Setting up battle participants"; UnitStack::pointer attacker = game->level.tiles[attacking_point].stack; for (int dir = 0; dir < 7; dir++) { UnitStack::pointer stack; Point stack_point = get_neighbour(target_point, dir); if (game->level.contains(stack_point)) { stack = game->level.tiles[stack_point].stack; } if (stack && stack->owner == attacker->owner) { stacks[dir] = stack; stack_sides[dir] = Attacker; } else if (stack && stack->owner != attacker->owner) { stacks[dir] = stack; stack_sides[dir] = Defender; } else { stacks[dir] = UnitStack::pointer(); stack_sides[dir] = None; } } for (int dir = 0; dir < 7; dir++) { if (stacks[dir]) { BOOST_LOG_TRIVIAL(trace) << "Stack " << dir << ": " << stacks[dir]->id; for (unsigned int i = 0; i < stacks[dir]->units.size(); i++) { int participant_id = participants.size(); participants.push_back(Participant(participant_id, stack_sides[dir], dir, stacks[dir], i)); BOOST_LOG_TRIVIAL(trace) << "Participant: " << participants[participant_id]; } } } }
void main() { std::srand(std::random_device{}()); // Initialize the participants ParticipantGroup pg; pg.addParticipant(Participant(0, "Alice")); pg.addParticipant(Participant(1, "Aaron")); pg.addParticipant(Participant(2, "Becky")); pg.addParticipant(Participant(3, "Bobby")); pg.addParticipant(Participant(4, "Chloe")); pg.addParticipant(Participant(5, "Chris")); pg.addParticipant(Participant(6, "Diana")); pg.addParticipant(Participant(7, "David")); pg.addImpossibleMutualAssignment(0, 1); pg.addImpossibleMutualAssignment(2, 3); pg.addImpossibleMutualAssignment(4, 5); pg.addImpossibleMutualAssignment(6, 7); // Initialize the successive assignments std::string graph_str = pg.getParticipantGraphString(); unsigned int nyears = 10; // Simulate an assingment by year unsigned int iyear = 0; std::string error_msg; ResultCode rescode; while(iyear<nyears) { // Compute the matching std::vector<unsigned int> matching; std::string updated_graph_str; rescode = findBestPerfectMatching(graph_str, matching, updated_graph_str); if(rescode!=ResCode_Success) { if(rescode==ResCode_KnownException) error_msg = updated_graph_str; break; } // Reverse the matching unsigned int nids = matching.size(); std::vector<unsigned int> matching_inv(nids); for(unsigned int id=0; id<nids; ++id) matching_inv[matching[id]] = id; // Display the matching std::cout << "Year #" << iyear << ":" << std::endl; //std::cout << "Graph: '" << graph_str << "'" << std::endl; for(unsigned int id=0; id<nids; ++id) std::cout << pg.getParticipant(id).getName() << " offers to " << pg.getParticipant(matching[id]).getName() << " and receives from " << pg.getParticipant(matching_inv[id]).getName() << std::endl; std::cout << std::endl; // Prepare next iteration ++iyear; graph_str = updated_graph_str; } // Display feedback in case of failure if(rescode!=ResCode_Success) { switch(rescode) { case ResCode_InvalidGraph: std::cout << "Failed to compute a matching: The graph is invalid!" << std::endl; break; case ResCode_MatchingFailure: std::cout << "Failed to compute a matching: The matching algorithm failed!" << std::endl; break; case ResCode_InvalidMatching: std::cout << "Failed to compute a matching: The resulting matching is invalid!" << std::endl; break; case ResCode_KnownException: std::cout << "Failed to compute a matching: Exception caught: " << error_msg << std::endl; break; case ResCode_UnknownException: std::cout << "Failed to compute a matching: Unknown exception!" << std::endl; break; } } else std::cout << "Successfully computed " << nyears << " successive matchings!" << std::endl; // Wait for an acknowledgement by the user std::cout << "Enter any char to continue..."; getchar(); }