}
}
+/* Find the first player with the fewest songs played and part of this machine. */
+const Player *GroupScreen::get_next_player(const Group &group)
+{
+ unsigned min_played_songs = 9999;
+ const Player *next_player = NULL;
+ unsigned m = 0;
+ for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
+ unsigned this_played = 0;
+ for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j) {
+ if (j->score != -1)
+ ++this_played;
+ }
+
+ if ((m++ % num_machines == machine) && this_played < min_played_songs) {
+ min_played_songs = this_played;
+ next_player = &(*i);
+ }
+ }
+
+ return next_player;
+}
+
/*
* At the bottom, for a single player, is "who's playing, what will he/she be
* playing, and optionally, how much to lead/win and how much to secure
{
unsigned num_scores = group.players[0].scores.size();
- /* Find the first player with the fewest songs played and part of this machine. */
- unsigned min_played_songs = 9999, num_random_songs = 0;
- const Player *next_player = NULL;
- unsigned m = 0;
- for (std::vector<Player>::const_iterator i = group.players.begin(); i != group.players.end(); ++i) {
- unsigned this_played = 0, this_random_songs = 0;
- for (std::vector<Score>::const_iterator j = i->scores.begin(); j != i->scores.end(); ++j) {
- if (j->score != -1)
- ++this_played;
- if (!j->chosen)
- ++this_random_songs;
- }
-
- if ((m++ % num_machines == machine) && this_played < min_played_songs) {
- min_played_songs = this_played;
- next_player = &(*i);
- num_random_songs = this_random_songs; // should be equal for all
- }
+ // Find out how many random songs there are (equal for all players).
+ unsigned num_random_songs = 0;
+ for (std::vector<Score>::const_iterator i = group.players[0].scores.begin(); i != group.players[0].scores.end(); ++i) {
+ if (!i->chosen)
+ ++num_random_songs;
}
- /* Find out what song this player is supposed to play next; try random songs first */
+ /*
+ * Find out which player is next, and what song he she is supposed to play. First
+ * try random songs.
+ */
+ const Player *next_player = get_next_player(group);
const Score *next_song = NULL;
+ unsigned num_played = 0; // will not always be completely accurate, but always as accurate as we need it :-)
for (unsigned i = 0; i < num_random_songs; ++i) {
unsigned j = (i + next_player->position - 1) % num_random_songs;
if (next_player->scores[j].score == -1) {
next_song = &(next_player->scores[j]);
break;
+ } else {
+ ++num_played;
}
}
if (next_player->scores[j].score == -1) {
next_song = &(next_player->scores[j]);
break;
+ } else {
+ ++num_played;
}
}
}
}
// only show lead/win/qualify for the last song
- if (min_played_songs == num_scores - 1) {
+ if (num_played == num_scores - 1) {
/*
* Find out how much we need to lead, how much we need to be guaranteed
* to win the group, and how much we need to secure qualification. (FIXME: