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;
90 //- Deconstructor ---------------------------------------------------------
95 //- IsTourney -------------------------------------------------------------
96 int Tourney::IsTourney(int tourn) {
101 } //- End of IsTourney
103 //- IsNotNew-------------------------------------------------------------
104 short Tourney::IsNotNew(void) {
110 //- IsNotClosed-------------------------------------------------------------
111 short Tourney::IsNotClosed(void) {
117 //- AddPlayer ----------------------------------------------------------
118 int Tourney::AddPlayer(char *name, int rating, float score) {
119 TourneyPlayers *newPlayer = NULL, *tp = NULL;
120 Player *newSortPlayer = NULL;
122 if (status != OPEN) return 3; // If we are not open then we can't enter the tourney
124 tp = GetPlayer(name);
126 if(tp != NULL) return(2); // if we are already in the tourney we can't enter it again/
128 if(rating >= params.ratingLow && rating <= params.ratingHigh && status == OPEN) {
130 newPlayer = new TourneyPlayers(name, rating, score);
131 newSortPlayer = new Player(name, 0);
133 playerList.Append(newPlayer);
135 gMamer.XServerCom("%s %i %s %s%i%s %s%i %i %s%s", "tell", gMamer.channelNumber, name, "(", rating, ")",
136 "has joined tourney #", number, GetPlayerCount(), "players now.", "\n");
138 if(GetPlayerCount() >= params.maxPlayers)
140 return(1); // we entered the tourney
142 return(0); // sucks to be us cause our rating doesn't fit the params
145 //- RemovePlayer ----------------------------------------------------------
146 int Tourney::RemovePlayer(char *name) {
147 TourneyPlayers *tp = NULL, *p=NULL;
149 int roundsRemaining=0;
151 tp = GetPlayer(name);
152 printf("forfeiting %s\n", tp->name);
153 if(tp == NULL) return -1; // Player not in THIS tourney
157 roundsRemaining = GetRoundsRemaining();
159 // This code will go through a forfeited players list and give him a loss for current opponent
160 // with a quick modification it will give losses for all games played as well...
161 LinkListIter<Player> opponentIter(tp->opponentList); // List of opponents this player has had
162 opponentIter.Reset();
163 while((opp = opponentIter.Next())) {
164 if(strcmp("_BYE_", opp->name) != 0) { // If I am not _BYE_
165 p = GetPlayer(opp->name);
166 if(opp->floatValue == -1) { // floatValue stores the game result for this player
167 if(opp->value) { // if player leaving was white
168 SetGameResult(tp->name, opp->name, 0);
170 SetGameResult(opp->name, tp->name, 1);
177 LinkListIter<TourneyPlayers> playerIter(playerList);
179 while((p = playerIter.Next())) {
180 if(strcmp(p->name, "_BYE_") == 0) {
181 if(p->activeFlag != 0)
191 return roundsRemaining;
194 //- GetPlayer ----------------------------------------------------------
195 TourneyPlayers *Tourney::GetPlayer(char *name) {
196 LinkListIter<TourneyPlayers> playerIter(playerList);
197 TourneyPlayers *tp = NULL;
200 while((tp = playerIter.Next()))
201 if(!strcasecmp(tp->name, name))
207 //- GetRound ----------------------------------------------------------
208 int Tourney::GetRound() {
209 return params.currentRound;
210 }//- end of GetRound --------------------------------------------------
212 //- GetRoundsRemaining ------------------------------------------------
213 int Tourney::GetRoundsRemaining() {
214 return (params.rounds - params.currentRound);
215 }//- end of GetRoundsRemaining -----------------------------------------
217 //- SortPlayers ----------------------------------
218 void Tourney::SortPlayers() {
219 Player *temp=NULL, *s=NULL;
220 TourneyPlayers *tp = NULL;
223 LinkListIter<TourneyPlayers> playerIter(playerList);
224 LinkListIter<Player> sortIter(sortList);
227 while((s = sortIter.Next())) sortList.Delete(s);
230 while((tp = playerIter.Next())) {
231 (tp->activeFlag) ? tp->sortValue = (tp->score + tp->rating/10000.0) : tp->sortValue = -1.0;
232 // tp->ClearWhites();
233 // tp->ClearBlacks();
234 if((status == OPEN) && (i < (GetPlayerCount()/2)))
235 (i % 2) ? tp->AddWhite() : tp->AddBlack();
240 while((tp = playerIter.Next())) {
243 temp = new Player(tp->name, tp->sortValue);
244 while((s = sortIter.Next())) {
245 if(tp->sortValue > s->floatValue) {
246 sortList.Insert(s, temp);
252 sortList.Append(temp);
257 while((s = sortIter.Next())) {
259 if(gMamer.debugLevel >= 10) printf("%4d %-18s\n", s->value, s->name);
262 }//- end of Sort Players ----------------------
264 //- GetSortValueCount -------------------------------------------------------
265 int Tourney::GetSortValueCount(double value) {
266 LinkListIter<TourneyPlayers> playerIter(playerList);
268 TourneyPlayers *tp=NULL;
271 while((tp = playerIter.Next())) {
272 if(tp->sortValue == value) {
273 s = GetSortPlayer(tp->name);
282 //- GetSortPlayer ----------
283 Player *Tourney::GetSortPlayer(char *name) {
285 LinkListIter<Player> sortIter(sortList);
287 while((p = sortIter.Next())) {
288 if(strcasecmp(p->name, name) == 0) {
294 }//- end of GetSortPlayer -----
296 //- GetSortPlayer ------------------------------
297 Player *Tourney::GetSortPlayer(int place) {
299 LinkListIter<Player> sortIter(sortList);
301 while((p = sortIter.Next())) {
302 if(p->value == place) {
308 }//- end of GetSortPlayer -----
310 //- CalculateAverage --------------------------------------------------
311 void Tourney::CalculateAverage(void) {
312 int total=0, count=0;
314 LinkListIter<TourneyPlayers> playerIter(playerList);
316 while((p = playerIter.Next())) {
323 averageRating = ((float)total/(float)count);
326 }//- end CalculateAverage
328 //- GetAverageRating ----------------------------------------------------------
329 float Tourney::GetAverageRating(void) {
330 return averageRating;
331 }//end GetAverageRating
333 //- GetVariant ----------------------------------------------------------
334 int Tourney::GetVariant(void) {
337 switch(params.variant) {
341 eTime = (float)params.time + (0.6666667 * (float)params.inc);
357 //- Open ----------------------------------------------------------
358 int Tourney::Open(void) {
367 //- GetPlayerCount ----------------------------------------------------------
368 int Tourney::GetPlayerCount() {
371 LinkListIter<TourneyPlayers> playerIter(playerList);
373 while((p = playerIter.Next())) {
374 if(p->activeFlag != 0)
379 }//- end GetPlayerCount ----------------------------------
381 //- SetPersist -------------------------------------------------------------
382 void Tourney::SetPersist(int i) {
386 //- GetPersist -------------------------------------------------------------
387 int Tourney::GetPersist() {
391 //- SetEndDate -------------------------------------------------------------
392 void Tourney::SetEndDate() {
394 } //- end of SetEndDate ----------------------------------------------------
396 //- CloseAndStart ----------------------------------------------------------
397 void Tourney::CloseAndStart(void) {
398 TourneyPlayers *tp = NULL;
400 params.currentRound = 0;
402 LinkListIter<TourneyPlayers> playerIter(playerList);
406 cout << "tourney started at: " << ctime(&startDate) << endl;
408 if(params.rounds == 0) {
409 switch(params.style) {
411 params.rounds = GetPlayerCount() - 1;
414 params.rounds = (int)ceil(log2(GetPlayerCount()));
417 params.rounds = DEFAULT_ROUNDS;
422 // this is to stop a 4 player tourney from having 2 rounds
423 params.rounds = (params.rounds < MINIMUM_ROUNDS) ? MINIMUM_ROUNDS : params.rounds;
425 playerIter.Reset(); // [HGM] this code moved here from SortPlayers
426 while((tp = playerIter.Next())) {
429 tp->ClearTotalWhites();
430 tp->ClearTotalBlacks();
434 TellThemWhoTheyPlay(); // tell them who they play
437 int Tourney::PopLastPairedPlayer() {
438 Storage *p=NULL, *lastPlayer=NULL;
439 LinkListIter<Storage> pairedIter(pairedPlayers);
442 while((p = pairedIter.Next())) {
448 cout << "Popping: " << lastPlayer->name << " from the paired list " << endl;
449 pairedPlayers.Delete(lastPlayer);
451 cout << "Popping: _NOBODY_" << " from the paired list " << endl;
456 void Tourney::ClearPairedPlayers() {
458 LinkListIter<Storage> pairedIter(pairedPlayers);
460 while((p = pairedIter.Next())) pairedPlayers.Delete(p);
463 int Tourney::MakeAssignments(void) {
464 TourneyPlayers *tp = NULL, *opponent = NULL, *bye = NULL;
465 Storage *newPairedPlayer=NULL;
466 Player *p=NULL, *opp=NULL;
467 int everybodyPaired=0, byeFlag=1, playerCount=0, i=1;
468 LinkListIter<TourneyPlayers> playerIter(playerList);
470 params.currentRound++;
471 if(params.currentRound > params.rounds) {
472 cout << "Returning because current round is > rounds" << endl;
473 cerr << "Returning because current round is > rounds" << endl;
476 // Initialize a few things...make sure nobody is paired,
478 while((tp = playerIter.Next())) {
480 if(strcmp(tp->name, "_BYE_") == 0) { byeFlag = 0; } // unset the byeFlag
482 playerCount = GetPlayerCount();
483 if((byeFlag) && (playerCount % 2)){ // we need to add a bye
484 bye = new TourneyPlayers("_BYE_", 0, 0);
485 playerList.Append(bye); // add the bye to the tourney players list
490 // Set up the PairingScores
492 while((tp = playerIter.Next())) { if(!tp->IsPaired()) SetPairingScores(tp); }
495 while((tp = playerIter.Next())) { UnPairPlayer(tp); tp->oppChoice=0; } // unpair all the players
498 ClearPairedPlayers();
499 while(everybodyPaired == 0) {
501 p = GetSortPlayer(i);
502 tp = GetPlayer(p->name);
503 opponent = (TourneyPlayers *)NULL;
504 // PrintPotentialLists();
505 if((tp->IsPaired() == FALSE) && tp->activeFlag) { // If I am not paired and I am active pair me
506 if((opponent = FindBestOpponent(tp))) {
507 newPairedPlayer = new Storage(tp->name, i);
508 pairedPlayers.Append(newPairedPlayer);
509 cerr << "Adding: " << tp->name << " " << i << " " << "to the paired list " << opponent->name << endl;
510 everybodyPaired = PairPlayers(tp, opponent); // Actually Pair me
511 i++; // go to the next player
512 } else { // If there is no opponent for me go back and repair up the tree
513 if(tp->oppChoice > playerCount) { // If I have tried all my opponents
514 tp->oppChoice = 0; // reset me so I can try again later
515 i = PopLastPairedPlayer(); // returns the last player paired & removes him from the paired list
516 cerr << "i=" << i << endl;
517 if(i <= 0) { // this would be really bad means we can't even find
518 cout << "Returning because we can't find pairings" << endl;
519 cerr << "Returning because we can't find pairings" << endl;
520 return 0; // an opponent for the first player. Tourney has to be over now
522 p = GetSortPlayer(i);
523 tp = GetPlayer(p->name);
524 opponent = GetPlayer(tp->oppName);
525 cout << "UnPairing: " << tp->name << " " << opponent->name << " choice: " << tp->oppChoice << endl;
526 tp->RemoveLastOpponent(); // removes the person we were planning on playing
527 opponent->RemoveLastOpponent();
528 UnPairPlayer(tp); // unpair us so we can be re-paired
529 UnPairPlayer(opponent);
530 tp->oppChoice++; // try his next possible opponent
532 tp->oppChoice++; // Try my next opponent
535 } else { // if I am already paired go to the next player and pair him
540 if(everybodyPaired > 0) {
542 while((tp = playerIter.Next())) UnPairPlayer(tp); // unpair all players so we can use that to tell
543 playerIter.Reset(); // if they have been assiged a color
544 while((tp = playerIter.Next())) {
545 if((!tp->IsPaired()) && (tp->activeFlag != 0)) {
546 opponent = GetPlayer(tp->oppName);
547 AssignColors(tp, opponent);
548 tp->NowPaired(TRUE); // mark BOTH players as having a color
549 opponent->NowPaired(TRUE); // this is important for when we hit this player later in the Iter
555 while((tp = playerIter.Next())) {
556 if(0 == strcmp(tp->name, "_BYE_")) { // If I am the bye
557 LinkListIter<Player> opponentIter(tp->opponentList);
558 while((opp = opponentIter.Next())) { // Got through my opponents and find the one I am playing now
559 if(0 == strcasecmp(opp->name, tp->oppName)) { // & Give him a win
561 SetGameResult(tp->name, tp->oppName, 0);
563 SetGameResult(tp->oppName, tp->name, 1);
564 gMamer.XServerCom("tell %s you get a BYE this round.%s", opp->name, "\n");
572 //- PrintPotentialLists
573 void Tourney::PrintPotentialLists() {
574 TourneyPlayers *tp=NULL;
577 LinkListIter<TourneyPlayers> playerIter(playerList);
579 while((tp = playerIter.Next())) {
580 printf("%-10s %i\n", tp->name, tp->oppChoice);
581 LinkListIter<Player> oppIter(tp->potentialOpponentList);
582 while((o = oppIter.Next())) {
583 printf("%d %-10s ", o->value, o->name);
589 //- Start of FindBestOpponent
590 TourneyPlayers *Tourney::FindBestOpponent(TourneyPlayers *tp) {
593 LinkListIter<Player> opponentIter(tp->potentialOpponentList);
594 while((tmp = opponentIter.Next())) {
595 if((tmp->value == tp->oppChoice) && (0 == GetPlayer(tmp->name)->IsPaired())) {
596 return GetPlayer(tmp->name);
603 //- Start of SetPairingSores -------------------------------
604 void Tourney::SetPairingScores(TourneyPlayers *tp) {
606 TourneyPlayers *opponent = NULL;
607 Player *temp=NULL, *newOpp=NULL, *t=NULL, *me=NULL;
608 int offset=2, place=1, i=0, added=0;
610 tp->RemovePotentialOppList();
612 LinkListIter<TourneyPlayers> playerIter(playerList);
616 while((opponent = playerIter.Next())) {
617 if((strcmp(tp->name, opponent->name) != 0) &&
618 (tp->score == opponent->score)) {
620 if(opponent->rating > tp->rating) {
626 if(place > offset) { offset *= -1; }
628 me = GetSortPlayer(tp->name);
630 while((opponent = playerIter.Next())) {
631 if(strcmp(tp->name, opponent->name) && (tp->activeFlag !=0)) { // If this isn't MY name & I am active
632 if((!tp->AlreadyPlayed(opponent->name)) && (!opponent->IsPaired()) && (opponent->activeFlag != 0)) {
633 // and I haven't played this person and this person is active. (not forfeited)
634 t = GetSortPlayer(opponent->name);
635 score = ((abs(t->value - (me->value + offset))) * 1000);
636 if(opponent->score >= tp->score) {
637 score = score + ((opponent->score - tp->score) * 10.0);
639 score = score + ((tp->score - opponent->score) * 10.0);
641 score += abs(opponent->ColorDue() - tp->ColorDue());
642 score += (abs(opponent->rating - tp->rating)) * 0.0001;
644 if(!strcmp(opponent->name, "_BYE_")) { score = 999999; }
647 newOpp = new Player(opponent->name, score);
648 LinkListIter<Player> opponentIter(tp->potentialOpponentList);
649 opponentIter.Reset();
650 while((temp = opponentIter.Next())) {
651 if(score < temp->floatValue) {
652 tp->potentialOpponentList.Insert(temp, newOpp);
658 tp->potentialOpponentList.Append(newOpp);
659 opponentIter.Reset();
661 while((temp = opponentIter.Next())) {
670 //- Start of PairPlayers ----------------------------------
671 int Tourney::PairPlayers(TourneyPlayers *p1, TourneyPlayers *p2) {
675 LinkListIter<TourneyPlayers> playerIter(playerList);
677 temp = new Player(p2->name, -1.0, 0, p2->rating);
678 p1->opponentList.Append(temp);
680 strcpy(p1->oppName, p2->name);
682 temp = new Player(p1->name, -1.0, 0, p1->rating);
683 p2->opponentList.Append(temp);
685 strcpy(p2->oppName, p1->name);
688 while((tp = playerIter.Next())) {
689 if((!tp->IsPaired()) && (tp->activeFlag != 0))
696 //- Start of UnPairPlayer ----------------------------------
697 void Tourney::UnPairPlayer(TourneyPlayers *p1) {
699 p1->NowPaired(FALSE);
700 }//- end of UnPairPlayer
703 int Tourney::intcmp(int a, int b) {
716 //- AssignColors ----------------------------------------------------------
717 void Tourney::AssignColors(TourneyPlayers *p1, TourneyPlayers *p2) {
718 int p1Color=0, rated = 1;
720 Player *opp1 = NULL, *opp2 = NULL;
722 cerr << "P1: " << p1->name << " due=" << p1->ColorDue() << " total=" << p1->GetTotalWhites() << "/" << p1->GetTotalBlacks()
723 << " consecutive=" << p1->GetConsecutiveWhites() << "/" << p1->GetConsecutiveBlacks() << endl;
724 cerr << "P2: " << p2->name << " due=" << p2->ColorDue() << " total=" << p2->GetTotalWhites() << "/" << p2->GetTotalBlacks()
725 << " consecutive=" << p2->GetConsecutiveWhites() << "/" << p2->GetConsecutiveBlacks() << endl;
726 if(params.mode != 'r') { rated = 0; }
727 if(intcmp(p1->ColorDue(), p2->ColorDue()) != 0) {
728 if(p1->ColorDue()) { p1Color = 1; }
730 if(p1->ColorDue()) { // Both are due white; need to find out how due.
731 switch (intcmp(p1->GetConsecutiveBlacks(), p2->GetConsecutiveBlacks())) {
737 switch (intcmp(p1->GetTotalBlacks(), p2->GetTotalBlacks())) {
743 if((p1->score * 10000 + p1->rating) >= (p2->score * 10000 + p2->rating))
750 switch (intcmp(p1->GetConsecutiveWhites(), p2->GetConsecutiveWhites())) {
756 switch (intcmp(p1->GetTotalWhites(), p2->GetTotalWhites())) {
762 if((p1->score * 10000 + p1->rating) >= (p2->score * 10000 + p2->rating))
770 LinkListIter<Player> opponentIter1(p1->opponentList);
771 LinkListIter<Player> opponentIter2(p2->opponentList);
772 while((opp1 = opponentIter1.Next())) {
773 if(!strcasecmp(opp1->name, p2->name)) { break; }
775 while((opp2 = opponentIter2.Next())) {
776 if(!strcasecmp(opp2->name, p1->name)) { break; }
778 cerr << "assigned color = " << p1Color << endl;
780 p1->AddWhite(); p2->AddBlack();
782 g = new Game(p1->name, p2->name, params.time, params.inc, rated, 'r');
784 p1->AddBlack(); p2->AddWhite();
786 g = new Game(p2->name, p1->name, params.time, params.inc, rated, 'r');
791 //- GetStatus --------------------------------------------------------
792 int Tourney::GetStatus(void) {
796 //- EndTourney -----------------------
797 void Tourney::EndTourney(void) {
801 //- Announce ----------------------------------------------------------
802 void Tourney::Announce(void) {
807 announce = new char[MAX_LINE_SIZE];
808 memset(announce, '\0', MAX_LINE_SIZE);
809 sprintf(announce, "*****Tourney Announcement***** %80s Trny #%d %d %d %c ",
810 "", number, params.time, params.inc, params.mode);
811 if(params.style == 's') { strcat(announce, " SWISS"); } else { strcat(announce, " RR"); }
812 switch(params.variant) {
814 strcat(announce, " Wild ");
815 strcat(announce, GetWild(params.wild));
818 strcat(announce, " Bug"); break;
820 strcat(announce, " Suicide"); break;
824 memset(temp, '\0', 128);
825 sprintf(temp, " %i-%i %i plr(s). tell %s join %d. Avg: %5.1f",
826 params.ratingLow, params.ratingHigh, GetPlayerCount(), gMamer.username, number, averageRating);
827 strcat(announce, temp);
829 printf("%s + cha 49\n", announce);
832 gMamer.XServerCom("%s %i %s%s", "tell", gMamer.channelNumber, announce, "\n");
835 if((now - lastCshouted) > (SEC_BETWEEN_CSHOUTS)) {
836 gMamer.XServerCom("%s %s%s", "cshout", announce, "\n");
843 //- SetVariable ---------------------------------------------------------------
844 void Tourney::SetVariable(int why, int newValue) {
848 if((newValue >= 0) && (newValue <= MAX_TIME))
849 params.time = newValue;
852 if((newValue >= 0) && (newValue <= MAX_INCREMENT))
853 params.inc = newValue;
856 params.rounds = newValue;
857 params.rounds = MIN(params.rounds, MAX_ROUNDS);
858 params.rounds = MIN((params.maxPlayers - 1), params.rounds);
861 if(((newValue >= 0) && (newValue <= 5)) ||
862 ((newValue >= 8) || (newValue <= 10)))
863 params.wild = newValue;
866 params.ratingLow = newValue;
867 params.ratingLow = MAX(0, params.ratingLow);
868 if(params.ratingLow >= (params.ratingHigh - 200))
869 params.ratingLow = params.ratingHigh - 200;
872 params.ratingHigh = newValue;
873 if(params.ratingHigh <= (params.ratingLow + 200))
874 params.ratingHigh = params.ratingLow + 200;
877 params.maxPlayers = newValue;
878 params.maxPlayers = MAX(params.maxPlayers, MINIMUM_PLAYERS);
879 params.maxPlayers = MAX(params.maxPlayers, (params.rounds + 1));
886 //- SetVariable ---------------------------------------------------------------
887 void Tourney::SetVariable(int why, char *newValue) {
891 if((newValue[0] == 's') || (newValue[0] == 'r'))
892 params.style = newValue[0];
895 if((newValue[0] == 'r') || (newValue[0] == 'w') || (newValue[0] == 'b') || (newValue[0] == 's'))
896 params.variant = newValue[0];
899 if((newValue[0] == 'r') || (newValue[0] == 'u'))
900 params.mode = newValue[0];
907 //- Begin GetWild - take a int return a string
908 char *Tourney::GetWild(int w) {
933 //- TellThemWhoTheyPlay ------------------------------------------
934 void Tourney::TellThemWhoTheyPlay() {
936 LinkListIter<Game> gameIter(gameList); // List of games in this tourney
937 char *Variant=new char[MAX_LINE_SIZE];
939 memset(Variant, '\0', MAX_LINE_SIZE);
941 if(params.variant == 'w')
942 sprintf(Variant, "wild %2s", GetWild(params.wild));
943 else if(params.variant == 's')
944 sprintf(Variant, "suicide");
945 else if(params.variant == 'b')
946 sprintf(Variant, "bug");
948 while((g = gameIter.Next())) {
949 /* note that we rely on rmatch and on the ; separated commands from lasker */
950 gMamer.XServerCom("rmatch %s %s %i %i %c %s white ; rmatch %s %s %i %i %c %s black\n",
951 g->whiteName, g->blackName, g->time, g->inc, params.mode, Variant,
952 g->blackName, g->whiteName, g->time, g->inc, params.mode, Variant);
955 }//- end TellThemWhoTheyPlay --------------------------------------
957 //- SetGameResult --------------------------------------------
958 int Tourney::SetGameResult(char *white, char *black, int result) {
959 Player *opp1 = NULL, *opp2 = NULL;
960 TourneyPlayers *tp1 = NULL, *tp2 = NULL;
964 tp1 = GetPlayer(white);
965 tp2 = GetPlayer(black);
967 if((NULL == tp1) || (NULL == tp2)) { return 0; }
969 LinkListIter<Player> opponentIter1(tp1->opponentList); // List of opponents this player has had
970 while((opp1 = opponentIter1.Next())) {
971 if(!strcasecmp(opp1->name, black)) { break; }
973 LinkListIter<Player> opponentIter2(tp2->opponentList);
974 while((opp2 = opponentIter2.Next())) {
975 if(!strcasecmp(opp2->name, white)) { break; }
977 if((NULL == opp1) || (NULL == opp2)) { return -1; }
979 switch (result) { // set the result
981 opp1->floatValue = 1.0;
982 opp2->floatValue = 0.0;
985 opp1->floatValue = 0.0;
986 opp2->floatValue = 1.0;
989 opp1->floatValue = 0.5;
990 opp2->floatValue = 0.5;
995 tp1->CalculateScore();
996 tp2->CalculateScore();
998 LinkListIter<Game> gameIter(gameList); // List of games in this tourney
999 while((g = gameIter.Next())) {
1000 if(!(strcasecmp(g->whiteName, white)) && !(strcasecmp(g->blackName, black))) {
1008 if((g = gameIter.Next())) {
1016 } //- End SetGameResult --------------------------------------
1018 //- GetStartDate ---------------------------------------------
1019 long Tourney::GetStartDate() {
1021 } //- end of GetStartDate ------------------------------------
1023 //- GetEndDate ---------------------------------------------
1024 long Tourney::GetEndDate() {
1026 } //- end of GetEndDate ------------------------------------