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 && (tp->ColorDue() != opponent->ColorDue() // they are due different color, never a problem
634 || tp->ColorDue() ? // both are due white. Check if one of them could accept black without breaking 'absolute' color rules
635 tp->GetConsecutiveBlacks() < 2 &&
636 tp->GetTotalBlacks() - tp->GetTotalWhites() < 2 ||
637 opponent->GetConsecutiveBlacks() < 2 &&
638 opponent->GetTotalBlacks() - opponent->GetTotalWhites() < 2
639 : // both are due black. Check if any of them can accept white
640 tp->GetConsecutiveWhites() < 2 &&
641 tp->GetTotalWhites() - tp->GetTotalBlacks() < 2 ||
642 opponent->GetConsecutiveWhites() < 2 &&
643 opponent->GetTotalWhites() - opponent->GetTotalBlacks() < 2
646 // and I haven't played this person and this person is active. (not forfeited)
647 t = GetSortPlayer(opponent->name);
648 score = ((abs(t->value - (me->value + offset))) * 1000);
649 if(opponent->score >= tp->score) {
650 score = score + ((opponent->score - tp->score) * 10.0);
652 score = score + ((tp->score - opponent->score) * 10.0);
654 score += abs(opponent->ColorDue() - tp->ColorDue());
655 score += (abs(opponent->rating - tp->rating)) * 0.0001;
657 if(!strcmp(opponent->name, "_BYE_")) { score = 999999; }
660 newOpp = new Player(opponent->name, score);
661 LinkListIter<Player> opponentIter(tp->potentialOpponentList);
662 opponentIter.Reset();
663 while((temp = opponentIter.Next())) {
664 if(score < temp->floatValue) {
665 tp->potentialOpponentList.Insert(temp, newOpp);
671 tp->potentialOpponentList.Append(newOpp);
672 opponentIter.Reset();
674 while((temp = opponentIter.Next())) {
683 //- Start of PairPlayers ----------------------------------
684 int Tourney::PairPlayers(TourneyPlayers *p1, TourneyPlayers *p2) {
688 LinkListIter<TourneyPlayers> playerIter(playerList);
690 temp = new Player(p2->name, -1.0, 0, p2->rating);
691 p1->opponentList.Append(temp);
693 strcpy(p1->oppName, p2->name);
695 temp = new Player(p1->name, -1.0, 0, p1->rating);
696 p2->opponentList.Append(temp);
698 strcpy(p2->oppName, p1->name);
701 while((tp = playerIter.Next())) {
702 if((!tp->IsPaired()) && (tp->activeFlag != 0))
709 //- Start of UnPairPlayer ----------------------------------
710 void Tourney::UnPairPlayer(TourneyPlayers *p1) {
712 p1->NowPaired(FALSE);
713 }//- end of UnPairPlayer
716 int Tourney::intcmp(int a, int b) {
729 //- AssignColors ----------------------------------------------------------
730 void Tourney::AssignColors(TourneyPlayers *p1, TourneyPlayers *p2) {
731 int p1Color=0, rated = 1;
733 Player *opp1 = NULL, *opp2 = NULL;
735 cerr << "P1: " << p1->name << " due=" << p1->ColorDue() << " total=" << p1->GetTotalWhites() << "/" << p1->GetTotalBlacks()
736 << " consecutive=" << p1->GetConsecutiveWhites() << "/" << p1->GetConsecutiveBlacks() << endl;
737 cerr << "P2: " << p2->name << " due=" << p2->ColorDue() << " total=" << p2->GetTotalWhites() << "/" << p2->GetTotalBlacks()
738 << " consecutive=" << p2->GetConsecutiveWhites() << "/" << p2->GetConsecutiveBlacks() << endl;
739 if(params.mode != 'r') { rated = 0; }
740 if(intcmp(p1->ColorDue(), p2->ColorDue()) != 0) {
741 if(p1->ColorDue()) { p1Color = 1; }
743 if(p1->ColorDue()) { // Both are due white; need to find out how due.
744 switch (intcmp(p1->GetConsecutiveBlacks(), p2->GetConsecutiveBlacks())) {
750 switch (intcmp(p1->GetTotalBlacks(), p2->GetTotalBlacks())) {
756 if((p1->score * 10000 + p1->rating) >= (p2->score * 10000 + p2->rating))
763 switch (intcmp(p1->GetConsecutiveWhites(), p2->GetConsecutiveWhites())) {
769 switch (intcmp(p1->GetTotalWhites(), p2->GetTotalWhites())) {
775 if((p1->score * 10000 + p1->rating) >= (p2->score * 10000 + p2->rating))
783 LinkListIter<Player> opponentIter1(p1->opponentList);
784 LinkListIter<Player> opponentIter2(p2->opponentList);
785 while((opp1 = opponentIter1.Next())) {
786 if(!strcasecmp(opp1->name, p2->name)) { break; }
788 while((opp2 = opponentIter2.Next())) {
789 if(!strcasecmp(opp2->name, p1->name)) { break; }
791 cerr << "assigned color = " << p1Color << endl;
793 p1->AddWhite(); p2->AddBlack();
795 g = new Game(p1->name, p2->name, params.time, params.inc, rated, 'r');
797 p1->AddBlack(); p2->AddWhite();
799 g = new Game(p2->name, p1->name, params.time, params.inc, rated, 'r');
804 //- GetStatus --------------------------------------------------------
805 int Tourney::GetStatus(void) {
809 //- EndTourney -----------------------
810 void Tourney::EndTourney(void) {
814 //- Announce ----------------------------------------------------------
815 void Tourney::Announce(void) {
820 announce = new char[MAX_LINE_SIZE];
821 memset(announce, '\0', MAX_LINE_SIZE);
822 sprintf(announce, "*****Tourney Announcement***** %80s Trny #%d %d %d %c ",
823 "", number, params.time, params.inc, params.mode);
824 if(params.style == 's') { strcat(announce, " SWISS"); } else { strcat(announce, " RR"); }
825 switch(params.variant) {
827 strcat(announce, " Wild ");
828 strcat(announce, GetWild(params.wild));
831 strcat(announce, " Bug"); break;
833 strcat(announce, " Suicide"); break;
837 memset(temp, '\0', 128);
838 sprintf(temp, " %i-%i %i plr(s). tell %s join %d. Avg: %5.1f",
839 params.ratingLow, params.ratingHigh, GetPlayerCount(), gMamer.username, number, averageRating);
840 strcat(announce, temp);
842 printf("%s + cha 49\n", announce);
845 gMamer.XServerCom("%s %i %s%s", "tell", gMamer.channelNumber, announce, "\n");
848 if((now - lastCshouted) > (SEC_BETWEEN_CSHOUTS)) {
849 gMamer.XServerCom("%s %s%s", "cshout", announce, "\n");
856 //- SetVariable ---------------------------------------------------------------
857 void Tourney::SetVariable(int why, int newValue) {
861 if((newValue >= 0) && (newValue <= MAX_TIME))
862 params.time = newValue;
865 if((newValue >= 0) && (newValue <= MAX_INCREMENT))
866 params.inc = newValue;
869 params.rounds = newValue;
870 params.rounds = MIN(params.rounds, MAX_ROUNDS);
871 params.rounds = MIN((params.maxPlayers - 1), params.rounds);
874 if(((newValue >= 0) && (newValue <= 5)) ||
875 ((newValue >= 8) || (newValue <= 10)))
876 params.wild = newValue;
879 params.ratingLow = newValue;
880 params.ratingLow = MAX(0, params.ratingLow);
881 if(params.ratingLow >= (params.ratingHigh - 200))
882 params.ratingLow = params.ratingHigh - 200;
885 params.ratingHigh = newValue;
886 if(params.ratingHigh <= (params.ratingLow + 200))
887 params.ratingHigh = params.ratingLow + 200;
890 params.maxPlayers = newValue;
891 params.maxPlayers = MAX(params.maxPlayers, MINIMUM_PLAYERS);
892 params.maxPlayers = MAX(params.maxPlayers, (params.rounds + 1));
899 //- SetVariable ---------------------------------------------------------------
900 void Tourney::SetVariable(int why, char *newValue) {
904 if((newValue[0] == 's') || (newValue[0] == 'r'))
905 params.style = newValue[0];
908 if((newValue[0] == 'r') || (newValue[0] == 'w') || (newValue[0] == 'b') || (newValue[0] == 's'))
909 params.variant = newValue[0];
912 if((newValue[0] == 'r') || (newValue[0] == 'u'))
913 params.mode = newValue[0];
920 //- Begin GetWild - take a int return a string
921 char *Tourney::GetWild(int w) {
946 //- TellThemWhoTheyPlay ------------------------------------------
947 void Tourney::TellThemWhoTheyPlay() {
949 LinkListIter<Game> gameIter(gameList); // List of games in this tourney
950 char *Variant=new char[MAX_LINE_SIZE];
952 memset(Variant, '\0', MAX_LINE_SIZE);
954 if(params.variant == 'w')
955 sprintf(Variant, "wild %2s", GetWild(params.wild));
956 else if(params.variant == 's')
957 sprintf(Variant, "suicide");
958 else if(params.variant == 'b')
959 sprintf(Variant, "bug");
961 while((g = gameIter.Next())) {
962 /* note that we rely on rmatch and on the ; separated commands from lasker */
963 gMamer.XServerCom("rmatch %s %s %i %i %c %s white ; rmatch %s %s %i %i %c %s black\n",
964 g->whiteName, g->blackName, g->time, g->inc, params.mode, Variant,
965 g->blackName, g->whiteName, g->time, g->inc, params.mode, Variant);
968 }//- end TellThemWhoTheyPlay --------------------------------------
970 //- SetGameResult --------------------------------------------
971 int Tourney::SetGameResult(char *white, char *black, int result) {
972 Player *opp1 = NULL, *opp2 = NULL;
973 TourneyPlayers *tp1 = NULL, *tp2 = NULL;
977 tp1 = GetPlayer(white);
978 tp2 = GetPlayer(black);
980 if((NULL == tp1) || (NULL == tp2)) { return 0; }
982 LinkListIter<Player> opponentIter1(tp1->opponentList); // List of opponents this player has had
983 while((opp1 = opponentIter1.Next())) {
984 if(!strcasecmp(opp1->name, black)) { break; }
986 LinkListIter<Player> opponentIter2(tp2->opponentList);
987 while((opp2 = opponentIter2.Next())) {
988 if(!strcasecmp(opp2->name, white)) { break; }
990 if((NULL == opp1) || (NULL == opp2)) { return -1; }
992 switch (result) { // set the result
994 opp1->floatValue = 1.0;
995 opp2->floatValue = 0.0;
998 opp1->floatValue = 0.0;
999 opp2->floatValue = 1.0;
1002 opp1->floatValue = 0.5;
1003 opp2->floatValue = 0.5;
1008 tp1->CalculateScore();
1009 tp2->CalculateScore();
1011 LinkListIter<Game> gameIter(gameList); // List of games in this tourney
1012 while((g = gameIter.Next())) {
1013 if(!(strcasecmp(g->whiteName, white)) && !(strcasecmp(g->blackName, black))) {
1021 if((g = gameIter.Next())) {
1029 } //- End SetGameResult --------------------------------------
1031 //- GetStartDate ---------------------------------------------
1032 long Tourney::GetStartDate() {
1034 } //- end of GetStartDate ------------------------------------
1036 //- GetEndDate ---------------------------------------------
1037 long Tourney::GetEndDate() {
1039 } //- end of GetEndDate ------------------------------------