X-Git-Url: http://winboard.nl/cgi-bin?p=capablanca.git;a=blobdiff_plain;f=lasker-2.2.3%2Fbots%2Fmamer%2FTourney.cc;h=e37b85c1329f91bcd2d4f9c0fbea9e056a729870;hp=cfc92b7530259a4735ecaa3e4b2e1cdc88332a09;hb=HEAD;hpb=52d710f4137ace4b1210dbcceedced062cd3c30c diff --git a/lasker-2.2.3/bots/mamer/Tourney.cc b/lasker-2.2.3/bots/mamer/Tourney.cc index cfc92b7..e37b85c 100644 --- a/lasker-2.2.3/bots/mamer/Tourney.cc +++ b/lasker-2.2.3/bots/mamer/Tourney.cc @@ -85,6 +85,7 @@ void Tourney::InitTourney(int n, User *u, int t, int i, char m, char s, int r, c lastCshouted = 0; status = NEW; + paused = FALSE; } //- Deconstructor --------------------------------------------------------- @@ -119,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); @@ -127,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); @@ -135,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 @@ -464,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++; @@ -477,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 @@ -811,6 +840,16 @@ void Tourney::EndTourney(void) { status = DONE; }//- End EndTourney +//- IsPaused -------------------------------------------------------- +int Tourney::IsPaused(void) { + return paused; +} + +//- SetPause ----------------------- +void Tourney::SetPause(int x) { + paused = x; +}//- End SetPause + //- Announce ---------------------------------------------------------- void Tourney::Announce(void) { char temp[128];