lastCshouted = 0;
status = NEW;
+ paused = FALSE;
}
//- Deconstructor ---------------------------------------------------------
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
playerIter.Reset();
while((opponent = playerIter.Next())) {
if(strcmp(tp->name, opponent->name) && (tp->activeFlag !=0)) { // If this isn't MY name & I am active
- if((!tp->AlreadyPlayed(opponent->name)) && (!opponent->IsPaired()) && (opponent->activeFlag != 0)) {
+ if((!tp->AlreadyPlayed(opponent->name)) && (!opponent->IsPaired()) && (opponent->activeFlag != 0)
+ && (tp->ColorDue() != opponent->ColorDue() // they are due different color, never a problem
+ || tp->ColorDue() ? // both are due white. Check if one of them could accept black without breaking 'absolute' color rules
+ tp->GetConsecutiveBlacks() < 2 &&
+ tp->GetTotalBlacks() - tp->GetTotalWhites() < 2 ||
+ opponent->GetConsecutiveBlacks() < 2 &&
+ opponent->GetTotalBlacks() - opponent->GetTotalWhites() < 2
+ : // both are due black. Check if any of them can accept white
+ tp->GetConsecutiveWhites() < 2 &&
+ tp->GetTotalWhites() - tp->GetTotalBlacks() < 2 ||
+ opponent->GetConsecutiveWhites() < 2 &&
+ opponent->GetTotalWhites() - opponent->GetTotalBlacks() < 2
+ )
+ ) {
// and I haven't played this person and this person is active. (not forfeited)
t = GetSortPlayer(opponent->name);
score = ((abs(t->value - (me->value + offset))) * 1000);
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];
while((g = gameIter.Next())) {
/* note that we rely on rmatch and on the ; separated commands from lasker */
+ sleep(2);
gMamer.XServerCom("rmatch %s %s %i %i %c %s white ; rmatch %s %s %i %i %c %s black\n",
g->whiteName, g->blackName, g->time, g->inc, params.mode, Variant,
g->blackName, g->whiteName, g->time, g->inc, params.mode, Variant);