X-Git-Url: http://winboard.nl/cgi-bin?p=capablanca.git;a=blobdiff_plain;f=lasker-2.2.3%2Fbots%2Fmamer%2FTourney.cc;fp=lasker-2.2.3%2Fbots%2Fmamer%2FTourney.cc;h=e37b85c1329f91bcd2d4f9c0fbea9e056a729870;hp=56a4b141e03784ddeac7430cf320c9c463f8e507;hb=09edd71ef89a37054e33bb2560b74bf8877bcf66;hpb=20c09dc1fcb3868ffc922e1232820dfd4c26f2c9 diff --git a/lasker-2.2.3/bots/mamer/Tourney.cc b/lasker-2.2.3/bots/mamer/Tourney.cc index 56a4b14..e37b85c 100644 --- a/lasker-2.2.3/bots/mamer/Tourney.cc +++ b/lasker-2.2.3/bots/mamer/Tourney.cc @@ -120,7 +120,8 @@ int Tourney::AddPlayer(char *name, int rating, float score) { 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); @@ -128,7 +129,9 @@ int Tourney::AddPlayer(char *name, int rating, float score) { 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); @@ -136,6 +139,29 @@ int Tourney::AddPlayer(char *name, int rating, float score) { 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 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 @@ -465,7 +491,7 @@ int Tourney::MakeAssignments(void) { 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 playerIter(playerList); params.currentRound++; @@ -478,14 +504,16 @@ int Tourney::MakeAssignments(void) { 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