From 2090edea3ec8c89745b568f7ef61d4c332dd29a8 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Fri, 12 Mar 2010 09:59:10 +0100 Subject: [PATCH] Fix color assignment by mamer Mamer was not keeping track of the total number of whites and blacks, and was furthermore clearing these counts and the consecutive whites / blacks before every round. --- lasker-2.2.3/bots/mamer/Tourney.cc | 22 +++++++++++++++++++--- lasker-2.2.3/bots/mamer/Tourney.hh | 2 +- lasker-2.2.3/bots/mamer/TourneyPlayers.cc | 12 ++++++++++++ lasker-2.2.3/bots/mamer/TourneyPlayers.hh | 2 ++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lasker-2.2.3/bots/mamer/Tourney.cc b/lasker-2.2.3/bots/mamer/Tourney.cc index 0532f44..813c938 100644 --- a/lasker-2.2.3/bots/mamer/Tourney.cc +++ b/lasker-2.2.3/bots/mamer/Tourney.cc @@ -233,8 +233,8 @@ void Tourney::SortPlayers() { i=0; while((tp = playerIter.Next())) { (tp->activeFlag) ? tp->sortValue = (tp->score + tp->rating/10000.0) : tp->sortValue = -1.0; - tp->ClearWhites(); - tp->ClearBlacks(); + // tp->ClearWhites(); + // tp->ClearBlacks(); if((status == OPEN) && (i < (GetPlayerCount()/2))) (i % 2) ? tp->AddWhite() : tp->AddBlack(); i++; @@ -399,9 +399,12 @@ void Tourney::SetEndDate() { //- CloseAndStart ---------------------------------------------------------- void Tourney::CloseAndStart(void) { + TourneyPlayers *tp = NULL; status = CLOSED; params.currentRound = 0; + LinkListIter playerIter(playerList); + startDate = time(0); cout << "tourney started at: " << ctime(&startDate) << endl; @@ -412,7 +415,7 @@ void Tourney::CloseAndStart(void) { params.rounds = GetPlayerCount() - 1; break; case 's': - params.rounds = (int)ceil(log2(GetPlayerCount())); + params.rounds = (int)ceil(log22(GetPlayerCount())); break; default: params.rounds = DEFAULT_ROUNDS; @@ -423,6 +426,14 @@ void Tourney::CloseAndStart(void) { // this is to stop a 4 player tourney from having 2 rounds params.rounds = (params.rounds < MINIMUM_ROUNDS) ? MINIMUM_ROUNDS : params.rounds; + playerIter.Reset(); // [HGM] this code moved here from SortPlayers + while((tp = playerIter.Next())) { + tp->ClearWhites(); + tp->ClearBlacks(); + tp->ClearTotalWhites(); + tp->ClearTotalBlacks(); + } + MakeAssignments(); TellThemWhoTheyPlay(); // tell them who they play } @@ -712,6 +723,10 @@ void Tourney::AssignColors(TourneyPlayers *p1, TourneyPlayers *p2) { Game *g = NULL; Player *opp1 = NULL, *opp2 = NULL; + cerr << "P1: " << p1->name << " due=" << p1->ColorDue() << " total=" << p1->GetTotalWhites() << "/" << p1->GetTotalBlacks() + << " consecutive=" << p1->GetConsecutiveWhites() << "/" << p1->GetConsecutiveBlacks() << endl; + cerr << "P2: " << p2->name << " due=" << p2->ColorDue() << " total=" << p2->GetTotalWhites() << "/" << p2->GetTotalBlacks() + << " consecutive=" << p2->GetConsecutiveWhites() << "/" << p2->GetConsecutiveBlacks() << endl; if(params.mode != 'r') { rated = 0; } if(intcmp(p1->ColorDue(), p2->ColorDue()) != 0) { if(p1->ColorDue()) { p1Color = 1; } @@ -764,6 +779,7 @@ void Tourney::AssignColors(TourneyPlayers *p1, TourneyPlayers *p2) { while((opp2 = opponentIter2.Next())) { if(!strcasecmp(opp2->name, p1->name)) { break; } } + cerr << "assigned color = " << p1Color << endl; if(p1Color) { p1->AddWhite(); p2->AddBlack(); opp1->value = 1; diff --git a/lasker-2.2.3/bots/mamer/Tourney.hh b/lasker-2.2.3/bots/mamer/Tourney.hh index 5186d85..b0d2d00 100644 --- a/lasker-2.2.3/bots/mamer/Tourney.hh +++ b/lasker-2.2.3/bots/mamer/Tourney.hh @@ -14,7 +14,7 @@ #ifndef _TOURNEY_ #define _TOURNEY_ -#define log2(x) (log(x)/log(2)) +#define log22(x) (log(x)/log(2)) #include #include diff --git a/lasker-2.2.3/bots/mamer/TourneyPlayers.cc b/lasker-2.2.3/bots/mamer/TourneyPlayers.cc index 2d9ea53..08e1197 100644 --- a/lasker-2.2.3/bots/mamer/TourneyPlayers.cc +++ b/lasker-2.2.3/bots/mamer/TourneyPlayers.cc @@ -180,6 +180,7 @@ void TourneyPlayers::ChangeColorDue(int value) { //- AddWhite --------------------------------- void TourneyPlayers::AddWhite(void) { consecutiveWhites++; + totalWhites++; // [HGM] this variable did not seem to get updated anywhere ChangeColorDue(0); ClearBlacks(); }//- end AddWhite @@ -187,6 +188,7 @@ void TourneyPlayers::AddWhite(void) { //- AddBlack --------------------------------- void TourneyPlayers::AddBlack(void) { consecutiveBlacks++; + totalBlacks++; // [HGM] this variable did not seem to get updated anywhere ChangeColorDue(1); ClearWhites(); }//- end AddBlack @@ -201,6 +203,16 @@ void TourneyPlayers::ClearBlacks(void) { consecutiveBlacks = 0; }//- end ClearBlacks +//- ClearTotalWhites --------------------------------- +void TourneyPlayers::ClearTotalWhites(void) { + totalWhites = 0; +}//- end ClearTotalWhites + +//- ClearTotalBlacks --------------------------------- +void TourneyPlayers::ClearTotalBlacks(void) { + totalBlacks = 0; +}//- end ClearTotalBlacks + //- GetTotalWhites --------------------------------- int TourneyPlayers::GetTotalWhites(void) { return totalWhites; diff --git a/lasker-2.2.3/bots/mamer/TourneyPlayers.hh b/lasker-2.2.3/bots/mamer/TourneyPlayers.hh index 3dc083f..25c3e20 100644 --- a/lasker-2.2.3/bots/mamer/TourneyPlayers.hh +++ b/lasker-2.2.3/bots/mamer/TourneyPlayers.hh @@ -70,6 +70,8 @@ public: void AddBlack(); void ClearWhites(); void ClearBlacks(); + void ClearTotalWhites(); + void ClearTotalBlacks(); int GetConsecutiveWhites(); int GetConsecutiveBlacks(); -- 1.7.0.4