tourn = gMamer.FindTourney(params[0].val.integer);
if(NULL != tourn) {
- newEntry = new Player(user->name, params[0].val.integer);
+ newEntry = new Player(user->name, 0., params[0].val.integer); // [HGM] signal this was from join
printf("entry=%d\n",newEntry);
gMamer.pendingList.Append(newEntry);
gMamer.XServerCom("getpi %s%s", user->name, "\n");
tourn = gMamer.FindTourney(params[1].val.integer);
if(NULL != tourn) {
- newEntry = new Player(params[0].val.word, params[1].val.integer);
+ newEntry = new Player(params[0].val.word, 1., params[1].val.integer); // [HGM] signal this was from att
gMamer.pendingList.Append(newEntry);
gMamer.XServerCom("getpi %s%s", params[0].val.word, "\n");
return(1);
TourneyPlayers *newPlayer = NULL, *tp = NULL;
Player *newSortPlayer = NULL;
- if (status != OPEN) return 3; // If we are not open then we can't enter the tourney
+ if (status != OPEN // If we are not open then we can't enter the tourney
+ && !(score != 0. && status == CLOSED)) return 3; // [HGM] unless the manager adds us as late join!
tp = GetPlayer(name);
if(rating >= params.ratingLow && rating <= params.ratingHigh && status == OPEN) {
- newPlayer = new TourneyPlayers(name, rating, score);
+ if(GetPlayerCount() >= params.maxPlayers) return(0); // [HGM] never exceed max players (or would it be safe to do so?)
+
+ newPlayer = new TourneyPlayers(name, rating, 0.); // [HGM] always set start score = 0.
newSortPlayer = new Player(name, 0);
playerList.Append(newPlayer);
gMamer.XServerCom("%s %i %s %s%i%s %s%i %i %s%s", "tell", gMamer.channelNumber, name, "(", rating, ")",
"has joined tourney #", number, GetPlayerCount(), "players now.", "\n");
CalculateAverage();
+
+ if(status == CLOSED) { // [HGM] late join; do some stuff already done in CloseAndStart for the others
+ newPlayer->ClearWhites();
+ newPlayer->ClearBlacks();
+ newPlayer->ClearTotalWhites();
+ newPlayer->ClearTotalBlacks();
+
+ // give the player a BYE (which we might have to add)
+ LinkListIter<TourneyPlayers> playerIter(playerList);
+ playerIter.Reset();
+ while((tp = playerIter.Next())) {
+ if(strcmp(tp->name, "_BYE_") == 0) break;
+ }
+ if(!tp) {
+ tp = new TourneyPlayers("_BYE_", 0, 0);
+ playerList.Append(tp); // add the bye to the tourney players list
+ SortPlayers();
+ }
+ newPlayer->opponentList.Append(new Player("_BYE_", 0., 0, 0)); // add a BYE for missed round, to prevent it can get a second
+
+ return 1; // in any case never start automatically
+ }
+
if(GetPlayerCount() >= params.maxPlayers)
CloseAndStart();
return(1); // we entered the tourney
TourneyPlayers *tp = NULL, *opponent = NULL, *bye = NULL;
Storage *newPairedPlayer=NULL;
Player *p=NULL, *opp=NULL;
- int everybodyPaired=0, byeFlag=1, playerCount=0, i=1;
+ int everybodyPaired=0, playerCount=0, i=1;
LinkListIter<TourneyPlayers> playerIter(playerList);
params.currentRound++;
playerIter.Reset();
while((tp = playerIter.Next())) {
UnPairPlayer(tp);
- if(strcmp(tp->name, "_BYE_") == 0) { byeFlag = 0; } // unset the byeFlag
+ if(strcmp(tp->name, "_BYE_") == 0) { bye = tp; tp->activeFlag = 0; } // unset the byeFlag [HGM] and remember bye and deactivate
}
playerCount = GetPlayerCount();
- if((byeFlag) && (playerCount % 2)){ // we need to add a bye
+ if(playerCount % 2){ // we need to add a bye
+ if(bye) bye->activeFlag = 1; else { // [HGM] if bye existed, re-activate it
bye = new TourneyPlayers("_BYE_", 0, 0);
playerList.Append(bye); // add the bye to the tourney players list
SortPlayers();
playerCount++;
+ }
}
// Set up the PairingScores