1 //--------------------------------------------------------------------------
2 // Tourney.cc - Source file for Tourney class
7 // $Date: 2002/07/02 00:02:40 $
12 // $Log: Tourney.cc,v $
13 // Revision 1.12 2002/07/02 00:02:40 tridge
14 // - fixed compile on g++ 2.96
15 // - updated for lasker 'rmatch'
17 // Revision 1.11 1998/09/10 19:57:17 mlong
18 // lots of little bug fixes and a few new features
20 // Revision 1.10 1998/04/29 15:23:19 mlong
21 // prepairing for the move to daimi
22 // new sorting routine.
24 // Revision 1.9 1998/04/18 20:05:14 mlong
27 // Revision 1.8 1998/04/18 18:46:04 mlong
29 // added delete tourney function
31 // Revision 1.4 1997/10/08 21:03:35 chess
32 // preparing for move to oracle machine at eworks.
34 // Revision 1.3 1997/05/15 18:27:53 chess
35 // added pending and TourneyPlayers support
36 // added HandleGetPlayerInfo & HandleGetGameInfo
38 // Revision 1.2 1996/10/01 20:14:43 moses
39 // Added a new method IsTourney
41 // Revision 1.1 1996/09/30 20:52:48 moses
44 //--------------------------------------------------------------------------
46 //static char RCSid[] = "$Id: Tourney.cc,v 1.12 2002/07/02 00:02:40 tridge Exp $";
53 //- Constructor ------------------------------------------------------------
57 Tourney::Tourney(int n,User *u, TourneyParameters *tp) {
58 InitTourney(n, u, tp->time, tp->inc, tp->mode, tp->style, tp->rounds, 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) {
62 InitTourney(n, u, t, i, m, s, r, tp->variant, tp->ratingLow, tp->ratingHigh);
65 Tourney::Tourney(int n, User *u, TourneyParameters *tp, int t, int i, char m, char s, int r, char v) {
66 InitTourney(n, u, t, i, m, s, r, v, tp->ratingLow, tp->ratingHigh);
69 void Tourney::InitTourney(int n, User *u, int t, int i, char m, char s, int r, char v, int rl, int rh) {
71 strncpy(manager, u->name, NAMELEN - 1);
72 managerLevel = u->GetManagerLevel();
81 params.ratingLow = rl;
82 params.ratingHigh = rh;
83 params.currentRound = 0;
84 params.maxPlayers = DEFAULT_MAX_PLAYERS;
94 //- Deconstructor ---------------------------------------------------------
99 //- IsTourney -------------------------------------------------------------
100 int Tourney::IsTourney(int tourn) {
105 } //- End of IsTourney
107 //- IsNotNew-------------------------------------------------------------
108 short Tourney::IsNotNew(void) {
114 //- IsNotClosed-------------------------------------------------------------
115 short Tourney::IsNotClosed(void) {
121 //- AddPlayer ----------------------------------------------------------
122 int Tourney::AddPlayer(char *name, int rating, float score) {
123 TourneyPlayers *newPlayer = NULL, *tp = NULL;
124 Player *newSortPlayer = NULL;
126 if (status != OPEN) return 3; // If we are not open then we can't enter the tourney
128 tp = GetPlayer(name);
130 if(tp != NULL) return(2); // if we are already in the tourney we can't enter it again/
132 if(rating >= params.ratingLow && rating <= params.ratingHigh && status == OPEN) {
134 newPlayer = new TourneyPlayers(name, rating, score);
135 newSortPlayer = new Player(name, 0);
137 playerList.Append(newPlayer);
139 gMamer.XServerCom("%s %i %s %s%i%s %s%i %i %s%s", "tell", gMamer.channelNumber, name, "(", rating, ")",
140 "has joined tourney #", number, GetPlayerCount(), "players now.", "\n");
142 if(GetPlayerCount() >= params.maxPlayers)
144 return(1); // we entered the tourney
146 return(0); // sucks to be us cause our rating doesn't fit the params
149 //- RemovePlayer ----------------------------------------------------------
150 int Tourney::RemovePlayer(char *name) {
151 TourneyPlayers *tp = NULL, *p=NULL;
153 int roundsRemaining=0;
155 tp = GetPlayer(name);
156 printf("forfeiting %s\n", tp->name);
157 if(tp == NULL) return -1; // Player not in THIS tourney
161 roundsRemaining = GetRoundsRemaining();
163 // This code will go through a forfeited players list and give him a loss for current opponent
164 // with a quick modification it will give losses for all games played as well...
165 LinkListIter<Player> opponentIter(tp->opponentList); // List of opponents this player has had
166 opponentIter.Reset();
167 while((opp = opponentIter.Next())) {
168 if(strcmp("_BYE_", opp->name) != 0) { // If I am not _BYE_
169 p = GetPlayer(opp->name);
170 if(opp->floatValue == -1) { // floatValue stores the game result for this player
171 if(opp->value) { // if player leaving was white
172 SetGameResult(tp->name, opp->name, 0);
174 SetGameResult(opp->name, tp->name, 1);
181 LinkListIter<TourneyPlayers> playerIter(playerList);
183 while((p = playerIter.Next())) {
184 if(strcmp(p->name, "_BYE_") == 0) {
185 if(p->activeFlag != 0)
195 return roundsRemaining;
198 //- GetPlayer ----------------------------------------------------------
199 TourneyPlayers *Tourney::GetPlayer(char *name) {
200 LinkListIter<TourneyPlayers> playerIter(playerList);
201 TourneyPlayers *tp = NULL;
204 while((tp = playerIter.Next()))
205 if(!strcasecmp(tp->name, name))
211 //- GetRound ----------------------------------------------------------
212 int Tourney::GetRound() {
213 return params.currentRound;
214 }//- end of GetRound --------------------------------------------------
216 //- GetRoundsRemaining ------------------------------------------------
217 int Tourney::GetRoundsRemaining() {
218 return (params.rounds - params.currentRound);
219 }//- end of GetRoundsRemaining -----------------------------------------
221 //- SortPlayers ----------------------------------
222 void Tourney::SortPlayers() {
223 Player *temp=NULL, *s=NULL;
224 TourneyPlayers *tp = NULL;
227 LinkListIter<TourneyPlayers> playerIter(playerList);
228 LinkListIter<Player> sortIter(sortList);
231 while((s = sortIter.Next())) sortList.Delete(s);
234 while((tp = playerIter.Next())) {
235 (tp->activeFlag) ? tp->sortValue = (tp->score + tp->rating/10000.0) : tp->sortValue = -1.0;
236 // tp->ClearWhites();
237 // tp->ClearBlacks();
238 if((status == OPEN) && (i < (GetPlayerCount()/2)))
239 (i % 2) ? tp->AddWhite() : tp->AddBlack();
244 while((tp = playerIter.Next())) {
247 temp = new Player(tp->name, tp->sortValue);
248 while((s = sortIter.Next())) {
249 if(tp->sortValue > s->floatValue) {
250 sortList.Insert(s, temp);
256 sortList.Append(temp);
261 while((s = sortIter.Next())) {
263 if(gMamer.debugLevel >= 10) printf("%4d %-18s\n", s->value, s->name);
266 }//- end of Sort Players ----------------------
268 //- GetSortValueCount -------------------------------------------------------
269 int Tourney::GetSortValueCount(double value) {
270 LinkListIter<TourneyPlayers> playerIter(playerList);
272 TourneyPlayers *tp=NULL;
275 while((tp = playerIter.Next())) {
276 if(tp->sortValue == value) {
277 s = GetSortPlayer(tp->name);
286 //- GetSortPlayer ----------
287 Player *Tourney::GetSortPlayer(char *name) {
289 LinkListIter<Player> sortIter(sortList);
291 while((p = sortIter.Next())) {
292 if(strcasecmp(p->name, name) == 0) {
298 }//- end of GetSortPlayer -----
300 //- GetSortPlayer ------------------------------
301 Player *Tourney::GetSortPlayer(int place) {
303 LinkListIter<Player> sortIter(sortList);
305 while((p = sortIter.Next())) {
306 if(p->value == place) {
312 }//- end of GetSortPlayer -----
314 //- CalculateAverage --------------------------------------------------
315 void Tourney::CalculateAverage(void) {
316 int total=0, count=0;
318 LinkListIter<TourneyPlayers> playerIter(playerList);
320 while((p = playerIter.Next())) {
327 averageRating = ((float)total/(float)count);
330 }//- end CalculateAverage
332 //- GetAverageRating ----------------------------------------------------------
333 float Tourney::GetAverageRating(void) {
334 return averageRating;
335 }//end GetAverageRating
337 //- GetVariant ----------------------------------------------------------
338 int Tourney::GetVariant(void) {
341 switch(params.variant) {
345 eTime = (float)params.time + (0.6666667 * (float)params.inc);
361 //- Open ----------------------------------------------------------
362 int Tourney::Open(void) {
371 //- GetPlayerCount ----------------------------------------------------------
372 int Tourney::GetPlayerCount() {
375 LinkListIter<TourneyPlayers> playerIter(playerList);
377 while((p = playerIter.Next())) {
378 if(p->activeFlag != 0)
383 }//- end GetPlayerCount ----------------------------------
385 //- SetPersist -------------------------------------------------------------
386 void Tourney::SetPersist(int i) {
390 //- GetPersist -------------------------------------------------------------
391 int Tourney::GetPersist() {
395 //- SetEndDate -------------------------------------------------------------
396 void Tourney::SetEndDate() {
398 } //- end of SetEndDate ----------------------------------------------------
400 //- CloseAndStart ----------------------------------------------------------
401 void Tourney::CloseAndStart(void) {
402 TourneyPlayers *tp = NULL;
404 params.currentRound = 0;
406 LinkListIter<TourneyPlayers> playerIter(playerList);
410 cout << "tourney started at: " << ctime(&startDate) << endl;
412 if(params.rounds == 0) {
413 switch(params.style) {
415 params.rounds = GetPlayerCount() - 1;
418 params.rounds = (int)ceil(log22(GetPlayerCount()));
421 params.rounds = DEFAULT_ROUNDS;
426 // this is to stop a 4 player tourney from having 2 rounds
427 params.rounds = (params.rounds < MINIMUM_ROUNDS) ? MINIMUM_ROUNDS : params.rounds;
429 playerIter.Reset(); // [HGM] this code moved here from SortPlayers
430 while((tp = playerIter.Next())) {
433 tp->ClearTotalWhites();
434 tp->ClearTotalBlacks();
438 TellThemWhoTheyPlay(); // tell them who they play
441 int Tourney::PopLastPairedPlayer() {
442 Storage *p=NULL, *lastPlayer=NULL;
443 LinkListIter<Storage> pairedIter(pairedPlayers);
446 while((p = pairedIter.Next())) {
452 cout << "Popping: " << lastPlayer->name << " from the paired list " << endl;
453 pairedPlayers.Delete(lastPlayer);
455 cout << "Popping: _NOBODY_" << " from the paired list " << endl;
460 void Tourney::ClearPairedPlayers() {
462 LinkListIter<Storage> pairedIter(pairedPlayers);
464 while((p = pairedIter.Next())) pairedPlayers.Delete(p);
467 int Tourney::MakeAssignments(void) {
468 TourneyPlayers *tp = NULL, *opponent = NULL, *bye = NULL;
469 Storage *newPairedPlayer=NULL;
470 Player *p=NULL, *opp=NULL;
471 int everybodyPaired=0, byeFlag=1, playerCount=0, i=1;
472 LinkListIter<TourneyPlayers> playerIter(playerList);
474 params.currentRound++;
475 if(params.currentRound > params.rounds) {
476 cout << "Returning because current round is > rounds" << endl;
477 cerr << "Returning because current round is > rounds" << endl;
480 // Initialize a few things...make sure nobody is paired,
482 while((tp = playerIter.Next())) {
484 if(strcmp(tp->name, "_BYE_") == 0) { byeFlag = 0; } // unset the byeFlag
486 playerCount = GetPlayerCount();
487 if((byeFlag) && (playerCount % 2)){ // we need to add a bye
488 bye = new TourneyPlayers("_BYE_", 0, 0);
489 playerList.Append(bye); // add the bye to the tourney players list
494 // Set up the PairingScores
496 while((tp = playerIter.Next())) { if(!tp->IsPaired()) SetPairingScores(tp); }
499 while((tp = playerIter.Next())) { UnPairPlayer(tp); tp->oppChoice=0; } // unpair all the players
502 ClearPairedPlayers();
503 while(everybodyPaired == 0) {
505 p = GetSortPlayer(i);
506 tp = GetPlayer(p->name);
507 opponent = (TourneyPlayers *)NULL;
508 // PrintPotentialLists();
509 if((tp->IsPaired() == FALSE) && tp->activeFlag) { // If I am not paired and I am active pair me
510 if((opponent = FindBestOpponent(tp))) {
511 newPairedPlayer = new Storage(tp->name, i);
512 pairedPlayers.Append(newPairedPlayer);
513 cerr << "Adding: " << tp->name << " " << i << " " << "to the paired list " << opponent->name << endl;
514 everybodyPaired = PairPlayers(tp, opponent); // Actually Pair me
515 i++; // go to the next player
516 } else { // If there is no opponent for me go back and repair up the tree
517 if(tp->oppChoice > playerCount) { // If I have tried all my opponents
518 tp->oppChoice = 0; // reset me so I can try again later
519 i = PopLastPairedPlayer(); // returns the last player paired & removes him from the paired list
520 cerr << "i=" << i << endl;
521 if(i <= 0) { // this would be really bad means we can't even find
522 cout << "Returning because we can't find pairings" << endl;
523 cerr << "Returning because we can't find pairings" << endl;
524 return 0; // an opponent for the first player. Tourney has to be over now
526 p = GetSortPlayer(i);
527 tp = GetPlayer(p->name);
528 opponent = GetPlayer(tp->oppName);
529 cout << "UnPairing: " << tp->name << " " << opponent->name << " choice: " << tp->oppChoice << endl;
530 tp->RemoveLastOpponent(); // removes the person we were planning on playing
531 opponent->RemoveLastOpponent();
532 UnPairPlayer(tp); // unpair us so we can be re-paired
533 UnPairPlayer(opponent);
534 tp->oppChoice++; // try his next possible opponent
536 tp->oppChoice++; // Try my next opponent
539 } else { // if I am already paired go to the next player and pair him
544 if(everybodyPaired > 0) {
546 while((tp = playerIter.Next())) UnPairPlayer(tp); // unpair all players so we can use that to tell
547 playerIter.Reset(); // if they have been assiged a color
548 while((tp = playerIter.Next())) {
549 if((!tp->IsPaired()) && (tp->activeFlag != 0)) {
550 opponent = GetPlayer(tp->oppName);
551 AssignColors(tp, opponent);
552 tp->NowPaired(TRUE); // mark BOTH players as having a color
553 opponent->NowPaired(TRUE); // this is important for when we hit this player later in the Iter
559 while((tp = playerIter.Next())) {
560 if(0 == strcmp(tp->name, "_BYE_")) { // If I am the bye
561 LinkListIter<Player> opponentIter(tp->opponentList);
562 while((opp = opponentIter.Next())) { // Got through my opponents and find the one I am playing now
563 if(0 == strcasecmp(opp->name, tp->oppName)) { // & Give him a win
565 SetGameResult(tp->name, tp->oppName, 0);
567 SetGameResult(tp->oppName, tp->name, 1);
568 gMamer.XServerCom("tell %s you get a BYE this round.%s", opp->name, "\n");
576 //- PrintPotentialLists
577 void Tourney::PrintPotentialLists() {
578 TourneyPlayers *tp=NULL;
581 LinkListIter<TourneyPlayers> playerIter(playerList);
583 while((tp = playerIter.Next())) {
584 printf("%-10s %i\n", tp->name, tp->oppChoice);
585 LinkListIter<Player> oppIter(tp->potentialOpponentList);
586 while((o = oppIter.Next())) {
587 printf("%d %-10s ", o->value, o->name);
593 //- Start of FindBestOpponent
594 TourneyPlayers *Tourney::FindBestOpponent(TourneyPlayers *tp) {
597 LinkListIter<Player> opponentIter(tp->potentialOpponentList);
598 while((tmp = opponentIter.Next())) {
599 if((tmp->value == tp->oppChoice) && (0 == GetPlayer(tmp->name)->IsPaired())) {
600 return GetPlayer(tmp->name);
607 //- Start of SetPairingSores -------------------------------
608 void Tourney::SetPairingScores(TourneyPlayers *tp) {
610 TourneyPlayers *opponent = NULL;
611 Player *temp=NULL, *newOpp=NULL, *t=NULL, *me=NULL;
612 int offset=2, place=1, i=0, added=0;
614 tp->RemovePotentialOppList();
616 LinkListIter<TourneyPlayers> playerIter(playerList);
620 while((opponent = playerIter.Next())) {
621 if((strcmp(tp->name, opponent->name) != 0) &&
622 (tp->score == opponent->score)) {
624 if(opponent->rating > tp->rating) {
630 if(place > offset) { offset *= -1; }
632 me = GetSortPlayer(tp->name);
634 while((opponent = playerIter.Next())) {
635 if(strcmp(tp->name, opponent->name) && (tp->activeFlag !=0)) { // If this isn't MY name & I am active
636 if((!tp->AlreadyPlayed(opponent->name)) && (!opponent->IsPaired()) && (opponent->activeFlag != 0)) {
637 // and I haven't played this person and this person is active. (not forfeited)
638 t = GetSortPlayer(opponent->name);
639 score = ((abs(t->value - (me->value + offset))) * 1000);
640 if(opponent->score >= tp->score) {
641 score = score + ((opponent->score - tp->score) * 10.0);
643 score = score + ((tp->score - opponent->score) * 10.0);
645 score += abs(opponent->ColorDue() - tp->ColorDue());
646 score += (abs(opponent->rating - tp->rating)) * 0.0001;
648 if(!strcmp(opponent->name, "_BYE_")) { score = 999999; }
651 newOpp = new Player(opponent->name, score);
652 LinkListIter<Player> opponentIter(tp->potentialOpponentList);
653 opponentIter.Reset();
654 while((temp = opponentIter.Next())) {
655 if(score < temp->floatValue) {
656 tp->potentialOpponentList.Insert(temp, newOpp);
662 tp->potentialOpponentList.Append(newOpp);
663 opponentIter.Reset();
665 while((temp = opponentIter.Next())) {
674 //- Start of PairPlayers ----------------------------------
675 int Tourney::PairPlayers(TourneyPlayers *p1, TourneyPlayers *p2) {
679 LinkListIter<TourneyPlayers> playerIter(playerList);
681 temp = new Player(p2->name, -1.0, 0, p2->rating);
682 p1->opponentList.Append(temp);
684 strcpy(p1->oppName, p2->name);
686 temp = new Player(p1->name, -1.0, 0, p1->rating);
687 p2->opponentList.Append(temp);
689 strcpy(p2->oppName, p1->name);
692 while((tp = playerIter.Next())) {
693 if((!tp->IsPaired()) && (tp->activeFlag != 0))
700 //- Start of UnPairPlayer ----------------------------------
701 void Tourney::UnPairPlayer(TourneyPlayers *p1) {
703 p1->NowPaired(FALSE);
704 }//- end of UnPairPlayer
707 int Tourney::intcmp(int a, int b) {
720 //- AssignColors ----------------------------------------------------------
721 void Tourney::AssignColors(TourneyPlayers *p1, TourneyPlayers *p2) {
722 int p1Color=0, rated = 1;
724 Player *opp1 = NULL, *opp2 = NULL;
726 cerr << "P1: " << p1->name << " due=" << p1->ColorDue() << " total=" << p1->GetTotalWhites() << "/" << p1->GetTotalBlacks()
727 << " consecutive=" << p1->GetConsecutiveWhites() << "/" << p1->GetConsecutiveBlacks() << endl;
728 cerr << "P2: " << p2->name << " due=" << p2->ColorDue() << " total=" << p2->GetTotalWhites() << "/" << p2->GetTotalBlacks()
729 << " consecutive=" << p2->GetConsecutiveWhites() << "/" << p2->GetConsecutiveBlacks() << endl;
730 if(params.mode != 'r') { rated = 0; }
731 if(intcmp(p1->ColorDue(), p2->ColorDue()) != 0) {
732 if(p1->ColorDue()) { p1Color = 1; }
734 if(p1->ColorDue()) { // Both are due white; need to find out how due.
735 switch (intcmp(p1->GetConsecutiveBlacks(), p2->GetConsecutiveBlacks())) {
741 switch (intcmp(p1->GetTotalBlacks(), p2->GetTotalBlacks())) {
747 if((p1->score * 10000 + p1->rating) >= (p2->score * 10000 + p2->rating))
754 switch (intcmp(p1->GetConsecutiveWhites(), p2->GetConsecutiveWhites())) {
760 switch (intcmp(p1->GetTotalWhites(), p2->GetTotalWhites())) {
766 if((p1->score * 10000 + p1->rating) >= (p2->score * 10000 + p2->rating))
774 LinkListIter<Player> opponentIter1(p1->opponentList);
775 LinkListIter<Player> opponentIter2(p2->opponentList);
776 while((opp1 = opponentIter1.Next())) {
777 if(!strcasecmp(opp1->name, p2->name)) { break; }
779 while((opp2 = opponentIter2.Next())) {
780 if(!strcasecmp(opp2->name, p1->name)) { break; }
782 cerr << "assigned color = " << p1Color << endl;
784 p1->AddWhite(); p2->AddBlack();
786 g = new Game(p1->name, p2->name, params.time, params.inc, rated, 'r');
788 p1->AddBlack(); p2->AddWhite();
790 g = new Game(p2->name, p1->name, params.time, params.inc, rated, 'r');
795 //- GetStatus --------------------------------------------------------
796 int Tourney::GetStatus(void) {
800 //- EndTourney -----------------------
801 void Tourney::EndTourney(void) {
805 //- Announce ----------------------------------------------------------
806 void Tourney::Announce(void) {
811 announce = new char[MAX_LINE_SIZE];
812 memset(announce, '\0', MAX_LINE_SIZE);
813 sprintf(announce, "*****Tourney Announcement***** %80s Trny #%d %d %d %c ",
814 "", number, params.time, params.inc, params.mode);
815 if(params.style == 's') { strcat(announce, " SWISS"); } else { strcat(announce, " RR"); }
816 switch(params.variant) {
818 strcat(announce, " Wild ");
819 strcat(announce, GetWild(params.wild));
822 strcat(announce, " Bug"); break;
824 strcat(announce, " Suicide"); break;
828 memset(temp, '\0', 128);
829 sprintf(temp, " %i-%i %i plr(s). tell %s join %d. Avg: %5.1f",
830 params.ratingLow, params.ratingHigh, GetPlayerCount(), gMamer.username, number, averageRating);
831 strcat(announce, temp);
833 printf("%s + cha 49\n", announce);
836 gMamer.XServerCom("%s %i %s%s", "tell", gMamer.channelNumber, announce, "\n");
839 if((now - lastCshouted) > (SEC_BETWEEN_CSHOUTS)) {
840 gMamer.XServerCom("%s %s%s", "cshout", announce, "\n");
847 //- SetVariable ---------------------------------------------------------------
848 void Tourney::SetVariable(int why, int newValue) {
852 if((newValue >= 0) && (newValue <= MAX_TIME))
853 params.time = newValue;
856 if((newValue >= 0) && (newValue <= MAX_INCREMENT))
857 params.inc = newValue;
860 params.rounds = newValue;
861 params.rounds = MIN(params.rounds, MAX_ROUNDS);
862 params.rounds = MIN((params.maxPlayers - 1), params.rounds);
865 if(((newValue >= 0) && (newValue <= 5)) ||
866 ((newValue >= 8) || (newValue <= 10)))
867 params.wild = newValue;
870 params.ratingLow = newValue;
871 params.ratingLow = MAX(0, params.ratingLow);
872 if(params.ratingLow >= (params.ratingHigh - 200))
873 params.ratingLow = params.ratingHigh - 200;
876 params.ratingHigh = newValue;
877 if(params.ratingHigh <= (params.ratingLow + 200))
878 params.ratingHigh = params.ratingLow + 200;
881 params.maxPlayers = newValue;
882 params.maxPlayers = MAX(params.maxPlayers, MINIMUM_PLAYERS);
883 params.maxPlayers = MAX(params.maxPlayers, (params.rounds + 1));
890 //- SetVariable ---------------------------------------------------------------
891 void Tourney::SetVariable(int why, char *newValue) {
895 if((newValue[0] == 's') || (newValue[0] == 'r'))
896 params.style = newValue[0];
899 if((newValue[0] == 'r') || (newValue[0] == 'w') || (newValue[0] == 'b') || (newValue[0] == 's'))
900 params.variant = newValue[0];
903 if((newValue[0] == 'r') || (newValue[0] == 'u'))
904 params.mode = newValue[0];
911 //- Begin GetWild - take a int return a string
912 char *Tourney::GetWild(int w) {
937 //- TellThemWhoTheyPlay ------------------------------------------
938 void Tourney::TellThemWhoTheyPlay() {
940 LinkListIter<Game> gameIter(gameList); // List of games in this tourney
941 char *Variant=new char[MAX_LINE_SIZE];
943 memset(Variant, '\0', MAX_LINE_SIZE);
945 if(params.variant == 'w')
946 sprintf(Variant, "wild %2s", GetWild(params.wild));
947 else if(params.variant == 's')
948 sprintf(Variant, "suicide");
949 else if(params.variant == 'b')
950 sprintf(Variant, "bug");
952 while((g = gameIter.Next())) {
953 /* note that we rely on rmatch and on the ; separated commands from lasker */
954 gMamer.XServerCom("rmatch %s %s %i %i %c %s white ; rmatch %s %s %i %i %c %s black\n",
955 g->whiteName, g->blackName, g->time, g->inc, params.mode, Variant,
956 g->blackName, g->whiteName, g->time, g->inc, params.mode, Variant);
959 }//- end TellThemWhoTheyPlay --------------------------------------
961 //- SetGameResult --------------------------------------------
962 int Tourney::SetGameResult(char *white, char *black, int result) {
963 Player *opp1 = NULL, *opp2 = NULL;
964 TourneyPlayers *tp1 = NULL, *tp2 = NULL;
968 tp1 = GetPlayer(white);
969 tp2 = GetPlayer(black);
971 if((NULL == tp1) || (NULL == tp2)) { return 0; }
973 LinkListIter<Player> opponentIter1(tp1->opponentList); // List of opponents this player has had
974 while((opp1 = opponentIter1.Next())) {
975 if(!strcasecmp(opp1->name, black)) { break; }
977 LinkListIter<Player> opponentIter2(tp2->opponentList);
978 while((opp2 = opponentIter2.Next())) {
979 if(!strcasecmp(opp2->name, white)) { break; }
981 if((NULL == opp1) || (NULL == opp2)) { return -1; }
983 switch (result) { // set the result
985 opp1->floatValue = 1.0;
986 opp2->floatValue = 0.0;
989 opp1->floatValue = 0.0;
990 opp2->floatValue = 1.0;
993 opp1->floatValue = 0.5;
994 opp2->floatValue = 0.5;
999 tp1->CalculateScore();
1000 tp2->CalculateScore();
1002 LinkListIter<Game> gameIter(gameList); // List of games in this tourney
1003 while((g = gameIter.Next())) {
1004 if(!(strcasecmp(g->whiteName, white)) && !(strcasecmp(g->blackName, black))) {
1012 if((g = gameIter.Next())) {
1020 } //- End SetGameResult --------------------------------------
1022 //- GetStartDate ---------------------------------------------
1023 long Tourney::GetStartDate() {
1025 } //- end of GetStartDate ------------------------------------
1027 //- GetEndDate ---------------------------------------------
1028 long Tourney::GetEndDate() {
1030 } //- end of GetEndDate ------------------------------------