1 //--------------------------------------------------------------------------
2 // Tourney.cc - Source file for Tourney class
7 // $Date: 1998/09/10 19:57:17 $
12 // $Log: Tourney.cc,v $
13 // Revision 1.11 1998/09/10 19:57:17 mlong
14 // lots of little bug fixes and a few new features
16 // Revision 1.10 1998/04/29 15:23:19 mlong
17 // prepairing for the move to daimi
18 // new sorting routine.
20 // Revision 1.9 1998/04/18 20:05:14 mlong
23 // Revision 1.8 1998/04/18 18:46:04 mlong
25 // added delete tourney function
27 // Revision 1.4 1997/10/08 21:03:35 chess
28 // preparing for move to oracle machine at eworks.
30 // Revision 1.3 1997/05/15 18:27:53 chess
31 // added pending and TourneyPlayers support
32 // added HandleGetPlayerInfo & HandleGetGameInfo
34 // Revision 1.2 1996/10/01 20:14:43 moses
35 // Added a new method IsTourney
37 // Revision 1.1 1996/09/30 20:52:48 moses
40 //--------------------------------------------------------------------------
42 //static char RCSid[] = "$Id: Tourney.cc,v 1.11 1998/09/10 19:57:17 mlong Exp $";
49 //- Constructor ------------------------------------------------------------
53 Tourney::Tourney(int n,User *u, TourneyParameters *tp) {
54 InitTourney(n, u, tp->time, tp->inc, tp->mode, tp->style, tp->rounds, tp->variant, tp->ratingLow, tp->ratingHigh);
57 Tourney::Tourney(int n, User *u, TourneyParameters *tp, int t, int i, char m, char s, int r) {
58 InitTourney(n, u, t, i, m, s, r, tp->variant, tp->ratingLow, tp->ratingHigh);
61 Tourney::Tourney(int n, User *u, TourneyParameters *tp, int t, int i, char m, char s, int r, char v) {
62 InitTourney(n, u, t, i, m, s, r, v, tp->ratingLow, tp->ratingHigh);
65 void Tourney::InitTourney(int n, User *u, int t, int i, char m, char s, int r, char v, int rl, int rh) {
67 strncpy(manager, u->name, NAMELEN - 1);
68 managerLevel = u->GetManagerLevel();
77 params.ratingLow = rl;
78 params.ratingHigh = rh;
79 params.currentRound = 0;
80 params.maxPlayers = DEFAULT_MAX_PLAYERS;
91 //- Deconstructor ---------------------------------------------------------
96 //- IsTourney -------------------------------------------------------------
97 int Tourney::IsTourney(int tourn) {
102 } //- End of IsTourney
104 //- IsNotNew-------------------------------------------------------------
105 short Tourney::IsNotNew(void) {
111 //- IsNotClosed-------------------------------------------------------------
112 short Tourney::IsNotClosed(void) {
118 //- AddPlayer ----------------------------------------------------------
119 int Tourney::AddPlayer(char *name, int rating, float score) {
120 TourneyPlayers *newPlayer = NULL, *tp = NULL;
121 Player *newSortPlayer = NULL;
123 if (status != OPEN) return 3; // If we are not open then we can't enter the tourney
125 tp = GetPlayer(name);
127 if(tp != NULL) return(2); // if we are already in the tourney we can't enter it again/
129 if(rating >= params.ratingLow && rating <= params.ratingHigh && status == OPEN) {
131 newPlayer = new TourneyPlayers(name, rating, score);
132 newSortPlayer = new Player(name, 0);
134 playerList.Append(newPlayer);
136 gMamer.XServerCom("%s %i %s %s%i%s %s%i %i %s%s", "tell", gMamer.channelNumber, name, "(", rating, ")",
137 "has joined tourney #", number, GetPlayerCount(), "players now.", "\n");
139 if(GetPlayerCount() >= params.maxPlayers)
141 return(1); // we entered the tourney
143 return(0); // sucks to be us cause our rating doesn't fit the params
146 //- RemovePlayer ----------------------------------------------------------
147 int Tourney::RemovePlayer(char *name) {
148 TourneyPlayers *tp = NULL, *p=NULL;
150 int roundsRemaining=0;
152 tp = GetPlayer(name);
153 printf("forfeiting %s\n", tp->name);
154 if(tp == NULL) return -1; // Player not in THIS tourney
158 roundsRemaining = GetRoundsRemaining();
160 // This code will go through a forfeited players list and give him a loss for current opponent
161 // with a quick modification it will give losses for all games played as well...
162 LinkListIter<Player> opponentIter(tp->opponentList); // List of opponents this player has had
163 opponentIter.Reset();
164 while((opp = opponentIter.Next())) {
165 if(strcmp("_BYE_", opp->name) != 0) { // If I am not _BYE_
166 p = GetPlayer(opp->name);
167 if(opp->floatValue == -1) { // floatValue stores the game result for this player
168 if(opp->value) { // if player leaving was white
169 SetGameResult(tp->name, opp->name, 0);
171 SetGameResult(opp->name, tp->name, 1);
178 LinkListIter<TourneyPlayers> playerIter(playerList);
180 while((p = playerIter.Next())) {
181 if(strcmp(p->name, "_BYE_") == 0) {
182 if(p->activeFlag != 0)
192 return roundsRemaining;
195 //- GetPlayer ----------------------------------------------------------
196 TourneyPlayers *Tourney::GetPlayer(char *name) {
197 LinkListIter<TourneyPlayers> playerIter(playerList);
198 TourneyPlayers *tp = NULL;
201 while((tp = playerIter.Next()))
202 if(!strcasecmp(tp->name, name))
208 //- GetRound ----------------------------------------------------------
209 int Tourney::GetRound() {
210 return params.currentRound;
211 }//- end of GetRound --------------------------------------------------
213 //- GetRoundsRemaining ------------------------------------------------
214 int Tourney::GetRoundsRemaining() {
215 return (params.rounds - params.currentRound);
216 }//- end of GetRoundsRemaining -----------------------------------------
218 //- SortPlayers ----------------------------------
219 void Tourney::SortPlayers() {
220 Player *temp=NULL, *s=NULL;
221 TourneyPlayers *tp = NULL;
224 LinkListIter<TourneyPlayers> playerIter(playerList);
225 LinkListIter<Player> sortIter(sortList);
228 while((s = sortIter.Next())) sortList.Delete(s);
231 while((tp = playerIter.Next())) {
232 (tp->activeFlag) ? tp->sortValue = (tp->score + tp->rating/10000.0) : tp->sortValue = -1.0;
233 // tp->ClearWhites();
234 // tp->ClearBlacks();
235 if((status == OPEN) && (i < (GetPlayerCount()/2)))
236 (i % 2) ? tp->AddWhite() : tp->AddBlack();
241 while((tp = playerIter.Next())) {
244 temp = new Player(tp->name, tp->sortValue);
245 while((s = sortIter.Next())) {
246 if(tp->sortValue > s->floatValue) {
247 sortList.Insert(s, temp);
253 sortList.Append(temp);
258 while((s = sortIter.Next())) {
260 if(gMamer.debugLevel >= 10) printf("%4d %-18s\n", s->value, s->name);
263 }//- end of Sort Players ----------------------
265 //- GetSortValueCount -------------------------------------------------------
266 int Tourney::GetSortValueCount(double value) {
267 LinkListIter<TourneyPlayers> playerIter(playerList);
269 TourneyPlayers *tp=NULL;
272 while((tp = playerIter.Next())) {
273 if(tp->sortValue == value) {
274 s = GetSortPlayer(tp->name);
283 //- GetSortPlayer ----------
284 Player *Tourney::GetSortPlayer(char *name) {
286 LinkListIter<Player> sortIter(sortList);
288 while((p = sortIter.Next())) {
289 if(strcasecmp(p->name, name) == 0) {
295 }//- end of GetSortPlayer -----
297 //- GetSortPlayer ------------------------------
298 Player *Tourney::GetSortPlayer(int place) {
300 LinkListIter<Player> sortIter(sortList);
302 while((p = sortIter.Next())) {
303 if(p->value == place) {
309 }//- end of GetSortPlayer -----
311 //- CalculateAverage --------------------------------------------------
312 void Tourney::CalculateAverage(void) {
313 int total=0, count=0;
315 LinkListIter<TourneyPlayers> playerIter(playerList);
317 while((p = playerIter.Next())) {
324 averageRating = ((float)total/(float)count);
327 }//- end CalculateAverage
329 //- GetAverageRating ----------------------------------------------------------
330 float Tourney::GetAverageRating(void) {
331 return averageRating;
332 }//end GetAverageRating
334 //- GetVariant ----------------------------------------------------------
335 int Tourney::GetVariant(void) {
338 switch(params.variant) {
342 eTime = (float)params.time + (0.6666667 * (float)params.inc);
358 //- Open ----------------------------------------------------------
359 int Tourney::Open(void) {
368 //- GetPlayerCount ----------------------------------------------------------
369 int Tourney::GetPlayerCount() {
372 LinkListIter<TourneyPlayers> playerIter(playerList);
374 while((p = playerIter.Next())) {
375 if(p->activeFlag != 0)
380 }//- end GetPlayerCount ----------------------------------
382 //- SetPersist -------------------------------------------------------------
383 void Tourney::SetPersist(int i) {
387 //- GetPersist -------------------------------------------------------------
388 int Tourney::GetPersist() {
392 //- SetEndDate -------------------------------------------------------------
393 void Tourney::SetEndDate() {
395 } //- end of SetEndDate ----------------------------------------------------
397 //- CloseAndStart ----------------------------------------------------------
398 void Tourney::CloseAndStart(void) {
399 TourneyPlayers *tp = NULL;
401 params.currentRound = 0;
403 LinkListIter<TourneyPlayers> playerIter(playerList);
407 cout << "tourney started at: " << ctime(&startDate) << endl;
409 if(params.rounds == 0) {
410 switch(params.style) {
412 params.rounds = GetPlayerCount() - 1;
415 params.rounds = (int)ceil(log2(GetPlayerCount()));
418 params.rounds = DEFAULT_ROUNDS;
423 // this is to stop a 4 player tourney from having 2 rounds
424 params.rounds = (params.rounds < MINIMUM_ROUNDS) ? MINIMUM_ROUNDS : params.rounds;
426 playerIter.Reset(); // [HGM] this code moved here from SortPlayers
427 while((tp = playerIter.Next())) {
430 tp->ClearTotalWhites();
431 tp->ClearTotalBlacks();
435 TellThemWhoTheyPlay(); // tell them who they play
438 int Tourney::PopLastPairedPlayer() {
439 Storage *p=NULL, *lastPlayer=NULL;
440 LinkListIter<Storage> pairedIter(pairedPlayers);
443 while((p = pairedIter.Next())) {
449 cout << "Popping: " << lastPlayer->name << " from the paired list " << endl;
450 pairedPlayers.Delete(lastPlayer);
452 cout << "Popping: _NOBODY_" << " from the paired list " << endl;
457 void Tourney::ClearPairedPlayers() {
459 LinkListIter<Storage> pairedIter(pairedPlayers);
461 while((p = pairedIter.Next())) pairedPlayers.Delete(p);
464 int Tourney::MakeAssignments(void) {
465 TourneyPlayers *tp = NULL, *opponent = NULL, *bye = NULL;
466 Storage *newPairedPlayer=NULL;
467 Player *p=NULL, *opp=NULL;
468 int everybodyPaired=0, byeFlag=1, playerCount=0, i=1;
469 LinkListIter<TourneyPlayers> playerIter(playerList);
471 params.currentRound++;
472 if(params.currentRound > params.rounds) {
473 cout << "Returning because current round is > rounds" << endl;
474 cerr << "Returning because current round is > rounds" << endl;
477 // Initialize a few things...make sure nobody is paired,
479 while((tp = playerIter.Next())) {
481 if(strcmp(tp->name, "_BYE_") == 0) { byeFlag = 0; } // unset the byeFlag
483 playerCount = GetPlayerCount();
484 if((byeFlag) && (playerCount % 2)){ // we need to add a bye
485 bye = new TourneyPlayers("_BYE_", 0, 0);
486 playerList.Append(bye); // add the bye to the tourney players list
491 // Set up the PairingScores
493 while((tp = playerIter.Next())) { if(!tp->IsPaired()) SetPairingScores(tp); }
496 while((tp = playerIter.Next())) { UnPairPlayer(tp); tp->oppChoice=0; } // unpair all the players
499 ClearPairedPlayers();
500 while(everybodyPaired == 0) {
502 p = GetSortPlayer(i);
503 tp = GetPlayer(p->name);
504 opponent = (TourneyPlayers *)NULL;
505 // PrintPotentialLists();
506 if((tp->IsPaired() == FALSE) && tp->activeFlag) { // If I am not paired and I am active pair me
507 if((opponent = FindBestOpponent(tp))) {
508 newPairedPlayer = new Storage(tp->name, i);
509 pairedPlayers.Append(newPairedPlayer);
510 cerr << "Adding: " << tp->name << " " << i << " " << "to the paired list " << opponent->name << endl;
511 everybodyPaired = PairPlayers(tp, opponent); // Actually Pair me
512 i++; // go to the next player
513 } else { // If there is no opponent for me go back and repair up the tree
514 if(tp->oppChoice > playerCount) { // If I have tried all my opponents
515 tp->oppChoice = 0; // reset me so I can try again later
516 i = PopLastPairedPlayer(); // returns the last player paired & removes him from the paired list
517 cerr << "i=" << i << endl;
518 if(i <= 0) { // this would be really bad means we can't even find
519 cout << "Returning because we can't find pairings" << endl;
520 cerr << "Returning because we can't find pairings" << endl;
521 return 0; // an opponent for the first player. Tourney has to be over now
523 p = GetSortPlayer(i);
524 tp = GetPlayer(p->name);
525 opponent = GetPlayer(tp->oppName);
526 cout << "UnPairing: " << tp->name << " " << opponent->name << " choice: " << tp->oppChoice << endl;
527 tp->RemoveLastOpponent(); // removes the person we were planning on playing
528 opponent->RemoveLastOpponent();
529 UnPairPlayer(tp); // unpair us so we can be re-paired
530 UnPairPlayer(opponent);
531 tp->oppChoice++; // try his next possible opponent
533 tp->oppChoice++; // Try my next opponent
536 } else { // if I am already paired go to the next player and pair him
541 if(everybodyPaired > 0) {
543 while((tp = playerIter.Next())) UnPairPlayer(tp); // unpair all players so we can use that to tell
544 playerIter.Reset(); // if they have been assiged a color
545 while((tp = playerIter.Next())) {
546 if((!tp->IsPaired()) && (tp->activeFlag != 0)) {
547 opponent = GetPlayer(tp->oppName);
548 AssignColors(tp, opponent);
549 tp->NowPaired(TRUE); // mark BOTH players as having a color
550 opponent->NowPaired(TRUE); // this is important for when we hit this player later in the Iter
556 while((tp = playerIter.Next())) {
557 if(0 == strcmp(tp->name, "_BYE_")) { // If I am the bye
558 LinkListIter<Player> opponentIter(tp->opponentList);
559 while((opp = opponentIter.Next())) { // Got through my opponents and find the one I am playing now
560 if(0 == strcasecmp(opp->name, tp->oppName)) { // & Give him a win
562 SetGameResult(tp->name, tp->oppName, 0);
564 SetGameResult(tp->oppName, tp->name, 1);
565 gMamer.XServerCom("tell %s you get a BYE this round.%s", opp->name, "\n");
573 //- PrintPotentialLists
574 void Tourney::PrintPotentialLists() {
575 TourneyPlayers *tp=NULL;
578 LinkListIter<TourneyPlayers> playerIter(playerList);
580 while((tp = playerIter.Next())) {
581 printf("%-10s %i\n", tp->name, tp->oppChoice);
582 LinkListIter<Player> oppIter(tp->potentialOpponentList);
583 while((o = oppIter.Next())) {
584 printf("%d %-10s ", o->value, o->name);
590 //- Start of FindBestOpponent
591 TourneyPlayers *Tourney::FindBestOpponent(TourneyPlayers *tp) {
594 LinkListIter<Player> opponentIter(tp->potentialOpponentList);
595 while((tmp = opponentIter.Next())) {
596 if((tmp->value == tp->oppChoice) && (0 == GetPlayer(tmp->name)->IsPaired())) {
597 return GetPlayer(tmp->name);
604 //- Start of SetPairingSores -------------------------------
605 void Tourney::SetPairingScores(TourneyPlayers *tp) {
607 TourneyPlayers *opponent = NULL;
608 Player *temp=NULL, *newOpp=NULL, *t=NULL, *me=NULL;
609 int offset=2, place=1, i=0, added=0;
611 tp->RemovePotentialOppList();
613 LinkListIter<TourneyPlayers> playerIter(playerList);
617 while((opponent = playerIter.Next())) {
618 if((strcmp(tp->name, opponent->name) != 0) &&
619 (tp->score == opponent->score)) {
621 if(opponent->rating > tp->rating) {
627 if(place > offset) { offset *= -1; }
629 me = GetSortPlayer(tp->name);
631 while((opponent = playerIter.Next())) {
632 if(strcmp(tp->name, opponent->name) && (tp->activeFlag !=0)) { // If this isn't MY name & I am active
633 if((!tp->AlreadyPlayed(opponent->name)) && (!opponent->IsPaired()) && (opponent->activeFlag != 0)
634 && (tp->ColorDue() != opponent->ColorDue() // they are due different color, never a problem
635 || tp->ColorDue() ? // both are due white. Check if one of them could accept black without breaking 'absolute' color rules
636 tp->GetConsecutiveBlacks() < 2 &&
637 tp->GetTotalBlacks() - tp->GetTotalWhites() < 2 ||
638 opponent->GetConsecutiveBlacks() < 2 &&
639 opponent->GetTotalBlacks() - opponent->GetTotalWhites() < 2
640 : // both are due black. Check if any of them can accept white
641 tp->GetConsecutiveWhites() < 2 &&
642 tp->GetTotalWhites() - tp->GetTotalBlacks() < 2 ||
643 opponent->GetConsecutiveWhites() < 2 &&
644 opponent->GetTotalWhites() - opponent->GetTotalBlacks() < 2
647 // and I haven't played this person and this person is active. (not forfeited)
648 t = GetSortPlayer(opponent->name);
649 score = ((abs(t->value - (me->value + offset))) * 1000);
650 if(opponent->score >= tp->score) {
651 score = score + ((opponent->score - tp->score) * 10.0);
653 score = score + ((tp->score - opponent->score) * 10.0);
655 score += abs(opponent->ColorDue() - tp->ColorDue());
656 score += (abs(opponent->rating - tp->rating)) * 0.0001;
658 if(!strcmp(opponent->name, "_BYE_")) { score = 999999; }
661 newOpp = new Player(opponent->name, score);
662 LinkListIter<Player> opponentIter(tp->potentialOpponentList);
663 opponentIter.Reset();
664 while((temp = opponentIter.Next())) {
665 if(score < temp->floatValue) {
666 tp->potentialOpponentList.Insert(temp, newOpp);
672 tp->potentialOpponentList.Append(newOpp);
673 opponentIter.Reset();
675 while((temp = opponentIter.Next())) {
684 //- Start of PairPlayers ----------------------------------
685 int Tourney::PairPlayers(TourneyPlayers *p1, TourneyPlayers *p2) {
689 LinkListIter<TourneyPlayers> playerIter(playerList);
691 temp = new Player(p2->name, -1.0, 0, p2->rating);
692 p1->opponentList.Append(temp);
694 strcpy(p1->oppName, p2->name);
696 temp = new Player(p1->name, -1.0, 0, p1->rating);
697 p2->opponentList.Append(temp);
699 strcpy(p2->oppName, p1->name);
702 while((tp = playerIter.Next())) {
703 if((!tp->IsPaired()) && (tp->activeFlag != 0))
710 //- Start of UnPairPlayer ----------------------------------
711 void Tourney::UnPairPlayer(TourneyPlayers *p1) {
713 p1->NowPaired(FALSE);
714 }//- end of UnPairPlayer
717 int Tourney::intcmp(int a, int b) {
730 //- AssignColors ----------------------------------------------------------
731 void Tourney::AssignColors(TourneyPlayers *p1, TourneyPlayers *p2) {
732 int p1Color=0, rated = 1;
734 Player *opp1 = NULL, *opp2 = NULL;
736 cerr << "P1: " << p1->name << " due=" << p1->ColorDue() << " total=" << p1->GetTotalWhites() << "/" << p1->GetTotalBlacks()
737 << " consecutive=" << p1->GetConsecutiveWhites() << "/" << p1->GetConsecutiveBlacks() << endl;
738 cerr << "P2: " << p2->name << " due=" << p2->ColorDue() << " total=" << p2->GetTotalWhites() << "/" << p2->GetTotalBlacks()
739 << " consecutive=" << p2->GetConsecutiveWhites() << "/" << p2->GetConsecutiveBlacks() << endl;
740 if(params.mode != 'r') { rated = 0; }
741 if(intcmp(p1->ColorDue(), p2->ColorDue()) != 0) {
742 if(p1->ColorDue()) { p1Color = 1; }
744 if(p1->ColorDue()) { // Both are due white; need to find out how due.
745 switch (intcmp(p1->GetConsecutiveBlacks(), p2->GetConsecutiveBlacks())) {
751 switch (intcmp(p1->GetTotalBlacks(), p2->GetTotalBlacks())) {
757 if((p1->score * 10000 + p1->rating) >= (p2->score * 10000 + p2->rating))
764 switch (intcmp(p1->GetConsecutiveWhites(), p2->GetConsecutiveWhites())) {
770 switch (intcmp(p1->GetTotalWhites(), p2->GetTotalWhites())) {
776 if((p1->score * 10000 + p1->rating) >= (p2->score * 10000 + p2->rating))
784 LinkListIter<Player> opponentIter1(p1->opponentList);
785 LinkListIter<Player> opponentIter2(p2->opponentList);
786 while((opp1 = opponentIter1.Next())) {
787 if(!strcasecmp(opp1->name, p2->name)) { break; }
789 while((opp2 = opponentIter2.Next())) {
790 if(!strcasecmp(opp2->name, p1->name)) { break; }
792 cerr << "assigned color = " << p1Color << endl;
794 p1->AddWhite(); p2->AddBlack();
796 g = new Game(p1->name, p2->name, params.time, params.inc, rated, 'r');
798 p1->AddBlack(); p2->AddWhite();
800 g = new Game(p2->name, p1->name, params.time, params.inc, rated, 'r');
805 //- GetStatus --------------------------------------------------------
806 int Tourney::GetStatus(void) {
810 //- EndTourney -----------------------
811 void Tourney::EndTourney(void) {
815 //- IsPaused --------------------------------------------------------
816 int Tourney::IsPaused(void) {
820 //- SetPause -----------------------
821 void Tourney::SetPause(int x) {
825 //- Announce ----------------------------------------------------------
826 void Tourney::Announce(void) {
831 announce = new char[MAX_LINE_SIZE];
832 memset(announce, '\0', MAX_LINE_SIZE);
833 sprintf(announce, "*****Tourney Announcement***** %80s Trny #%d %d %d %c ",
834 "", number, params.time, params.inc, params.mode);
835 if(params.style == 's') { strcat(announce, " SWISS"); } else { strcat(announce, " RR"); }
836 switch(params.variant) {
838 strcat(announce, " Wild ");
839 strcat(announce, GetWild(params.wild));
842 strcat(announce, " Bug"); break;
844 strcat(announce, " Suicide"); break;
848 memset(temp, '\0', 128);
849 sprintf(temp, " %i-%i %i plr(s). tell %s join %d. Avg: %5.1f",
850 params.ratingLow, params.ratingHigh, GetPlayerCount(), gMamer.username, number, averageRating);
851 strcat(announce, temp);
853 printf("%s + cha 49\n", announce);
856 gMamer.XServerCom("%s %i %s%s", "tell", gMamer.channelNumber, announce, "\n");
859 if((now - lastCshouted) > (SEC_BETWEEN_CSHOUTS)) {
860 gMamer.XServerCom("%s %s%s", "cshout", announce, "\n");
867 //- SetVariable ---------------------------------------------------------------
868 void Tourney::SetVariable(int why, int newValue) {
872 if((newValue >= 0) && (newValue <= MAX_TIME))
873 params.time = newValue;
876 if((newValue >= 0) && (newValue <= MAX_INCREMENT))
877 params.inc = newValue;
880 params.rounds = newValue;
881 params.rounds = MIN(params.rounds, MAX_ROUNDS);
882 params.rounds = MIN((params.maxPlayers - 1), params.rounds);
885 if(((newValue >= 0) && (newValue <= 5)) ||
886 ((newValue >= 8) || (newValue <= 10)))
887 params.wild = newValue;
890 params.ratingLow = newValue;
891 params.ratingLow = MAX(0, params.ratingLow);
892 if(params.ratingLow >= (params.ratingHigh - 200))
893 params.ratingLow = params.ratingHigh - 200;
896 params.ratingHigh = newValue;
897 if(params.ratingHigh <= (params.ratingLow + 200))
898 params.ratingHigh = params.ratingLow + 200;
901 params.maxPlayers = newValue;
902 params.maxPlayers = MAX(params.maxPlayers, MINIMUM_PLAYERS);
903 params.maxPlayers = MAX(params.maxPlayers, (params.rounds + 1));
910 //- SetVariable ---------------------------------------------------------------
911 void Tourney::SetVariable(int why, char *newValue) {
915 if((newValue[0] == 's') || (newValue[0] == 'r'))
916 params.style = newValue[0];
919 if((newValue[0] == 'r') || (newValue[0] == 'w') || (newValue[0] == 'b') || (newValue[0] == 's'))
920 params.variant = newValue[0];
923 if((newValue[0] == 'r') || (newValue[0] == 'u'))
924 params.mode = newValue[0];
931 //- Begin GetWild - take a int return a string
932 char *Tourney::GetWild(int w) {
957 //- TellThemWhoTheyPlay ------------------------------------------
958 void Tourney::TellThemWhoTheyPlay() {
960 LinkListIter<Game> gameIter(gameList); // List of games in this tourney
961 char *Variant=new char[MAX_LINE_SIZE];
963 memset(Variant, '\0', MAX_LINE_SIZE);
965 if(params.variant == 'w')
966 sprintf(Variant, "wild %2s", GetWild(params.wild));
967 else if(params.variant == 's')
968 sprintf(Variant, "suicide");
969 else if(params.variant == 'b')
970 sprintf(Variant, "bug");
972 while((g = gameIter.Next())) {
973 /* note that we rely on rmatch and on the ; separated commands from lasker */
975 gMamer.XServerCom("rmatch %s %s %i %i %c %s white ; rmatch %s %s %i %i %c %s black\n",
976 g->whiteName, g->blackName, g->time, g->inc, params.mode, Variant,
977 g->blackName, g->whiteName, g->time, g->inc, params.mode, Variant);
980 }//- end TellThemWhoTheyPlay --------------------------------------
982 //- SetGameResult --------------------------------------------
983 int Tourney::SetGameResult(char *white, char *black, int result) {
984 Player *opp1 = NULL, *opp2 = NULL;
985 TourneyPlayers *tp1 = NULL, *tp2 = NULL;
989 tp1 = GetPlayer(white);
990 tp2 = GetPlayer(black);
992 if((NULL == tp1) || (NULL == tp2)) { return 0; }
994 LinkListIter<Player> opponentIter1(tp1->opponentList); // List of opponents this player has had
995 while((opp1 = opponentIter1.Next())) {
996 if(!strcasecmp(opp1->name, black)) { break; }
998 LinkListIter<Player> opponentIter2(tp2->opponentList);
999 while((opp2 = opponentIter2.Next())) {
1000 if(!strcasecmp(opp2->name, white)) { break; }
1002 if((NULL == opp1) || (NULL == opp2)) { return -1; }
1004 switch (result) { // set the result
1006 opp1->floatValue = 1.0;
1007 opp2->floatValue = 0.0;
1010 opp1->floatValue = 0.0;
1011 opp2->floatValue = 1.0;
1014 opp1->floatValue = 0.5;
1015 opp2->floatValue = 0.5;
1020 tp1->CalculateScore();
1021 tp2->CalculateScore();
1023 LinkListIter<Game> gameIter(gameList); // List of games in this tourney
1024 while((g = gameIter.Next())) {
1025 if(!(strcasecmp(g->whiteName, white)) && !(strcasecmp(g->blackName, black))) {
1033 if((g = gameIter.Next())) {
1041 } //- End SetGameResult --------------------------------------
1043 //- GetStartDate ---------------------------------------------
1044 long Tourney::GetStartDate() {
1046 } //- end of GetStartDate ------------------------------------
1048 //- GetEndDate ---------------------------------------------
1049 long Tourney::GetEndDate() {
1051 } //- end of GetEndDate ------------------------------------