Esempio n. 1
0
void MainWindow::InitPlayer()
{
    InitGame *init = new InitGame();
    init->exec();
    if(!init->result())
        exit(1);
    int nbPlayer = init->getNBPlayer();
    for (int i = 0; i < nbPlayer; i ++)
    {
        Player *p = new Player(0,init->getPieces()[i]);
        connect(p,SIGNAL(changePost(int,int)),this,SLOT(playerChangePos(int,int)));
        p->setSpaceName(spaces[0]->getName());
        players.append(p);
    }
    delete init;
    PrintPlayer();
}
Esempio n. 2
0
void
Crosstable::PrintSwiss (DString * dstr, uint playerLimit)
{
    char stemp [1000];
    uint player;

    const char * resultStr [NUM_RESULT_TYPES];
    if (OutputFormat == CROSSTABLE_LaTeX) {
        resultStr[RESULT_White] = "{\\tt +}";
        resultStr[RESULT_Draw]  = "{\\tt =}";
        resultStr[RESULT_Black] = "{\\tt -}";
        resultStr[RESULT_None] = "{\\tt *}";
    } else {
        resultStr[RESULT_White] = "+";
        resultStr[RESULT_Draw]  = "=";
        resultStr[RESULT_Black] = "-";
        resultStr[RESULT_None] = "*";
    }

    dstr->Append (StartTable);
    if (OutputFormat == CROSSTABLE_LaTeX) {
        dstr->Append ("\\begin{tabular}{rl");
        if (PrintRatings) { dstr->Append ("r"); }
        if (PrintTitles) { dstr->Append ("r"); }
        if (PrintAges) { dstr->Append ("r"); }
        if (PrintCountries) { dstr->Append ("l"); }
        dstr->Append ("r@{ / }r");
        if (PrintTiebreaks) { dstr->Append ("r"); }
        for (uint i=0; i < MaxRound; i++) {
            dstr->Append ("r");
            if (i < MaxRound-1) { dstr->Append ("@{ }"); }
        }
        if (PrintRatings) { dstr->Append ("r"); }
        dstr->Append ("r}\n");
    }
    dstr->Append (StartRow);
    if (OutputFormat == CROSSTABLE_Html) {
        dstr->Append ("<th></th> <th>Player</th> ");
    } else if (OutputFormat == CROSSTABLE_LaTeX) {
        dstr->Append ("  & \\bf Player & ");
    } else {
        strPad (stemp, "", LongestNameLen + 2 + PlayerNumWidth, ' ');
        dstr->Append (stemp);
    }
    if (PrintRatings) {
        dstr->Append (StartBoldCol, " Rtng", EndBoldCol);
    }
    if (PrintTitles) {
        dstr->Append (StartBoldCol, "  Ti", EndBoldCol);
    }
    if (PrintAges) {
        dstr->Append (StartBoldCol, " Age", EndBoldCol);
    }
    if (PrintCountries) {
        dstr->Append (StartBoldCol, " Nat", EndBoldCol);
    }
    if (OutputFormat == CROSSTABLE_LaTeX) {
        dstr->Append (" \\multicolumn{2}{c}{\\bf Score} & ");
    } else {
        if (ThreeWin) 
	  dstr->Append ("  ", StartBoldCol, "Score", EndBoldCol, " ");
        else
	  dstr->Append ("   ", StartBoldCol, " Score ", EndBoldCol, "   ");
    }
    if (PrintTiebreaks) {
        dstr->Append (StartBoldCol, "(Tie)", EndBoldCol);
    }

    for (uint round = 1; round <= MaxRound; round++) {
        if (OutputFormat == CROSSTABLE_LaTeX) {
            dstr->Append (" \\multicolumn{1}{c}{\\bf ", round, "} & ");
        } else {
            sprintf (stemp, " %s%*d ", SwissColors ? " " : "",
                     PlayerNumWidth, round);
            dstr->Append (StartBoldCol, stemp, EndBoldCol);
        }
    }
    if (PrintRatings) {
        dstr->Append ("   ", StartBoldCol, "Perf Chg", EndBoldCol);
    }
    if (PrintTallies && OutputFormat == CROSSTABLE_Html) {
        dstr->Append ("   ", StartBoldCol, "+/-/=", EndBoldCol);
    }
    dstr->Append (EndRow, NewLine);

    PrintDashesLine (dstr);

    // Print the rows of players and results:
    uint previousScore = 0;
    for (player = 0; player < playerLimit; player++) {
        uint index = SortedIndex[player];
        playerDataT * pdata = PlayerData[index];

        // Print a blank line if we are at a new score group:
        if (SeparateScoreGroups  &&  SortOption == CROSSTABLE_SortScore) {
            if (player > 0  &&  pdata->score != previousScore) {
                dstr->Append (BlankRowLine);
            }
        }
        previousScore = pdata->score;

        sprintf (stemp, "%*u: ", PlayerNumWidth, player+1);
        dstr->Append (StartRow, StartRightCol, stemp, EndRightCol);

        PrintPlayer (dstr, pdata);

        if (OutputFormat == CROSSTABLE_LaTeX) {
            sprintf (stemp, " %2u%c%c ", pdata->score / 2, DecimalPointChar,
                     (pdata->score & 1 ? '5' : '0'));
            dstr->Append (StartRightCol, stemp, EndRightCol);
            sprintf (stemp, " %2u  ", pdata->gameCount);
            dstr->Append (StartRightCol, stemp, EndRightCol);
        } else {
            if (ThreeWin) {
	      sprintf (stemp, " %2u%c%c  ",
		       pdata->score / 2, DecimalPointChar,
		       (pdata->score & 1 ? '5' : '0'));
            } else {
	      sprintf (stemp, " %2u%c%c / %2u  ",
		       pdata->score / 2, DecimalPointChar,
		       (pdata->score & 1 ? '5' : '0'), pdata->gameCount);
            }
            dstr->Append (StartRightCol, stemp, EndRightCol);
        }
        if (PrintTiebreaks) {
            sprintf (stemp, "%2u%c%c ", pdata->tiebreak / 2,
                     DecimalPointChar, (pdata->tiebreak & 1 ? '5' : '0'));
            dstr->Append (StartRightCol, stemp, EndRightCol);
        }

        uint r_won = 0, r_loss = 0, r_draw = 0;
        for (uint round = 1; round <= MaxRound; round++) {
            clashT * clash = pdata->roundClash[round];
            dstr->AddChar (' ');
            dstr->Append (StartRightCol);
            if (clash == NULL) {
                dstr->Append ("...");
                if (PlayerNumWidth == 3) { dstr->AddChar ('.'); }
                if (SwissColors) { dstr->AddChar ('.'); }
            } else {
                if (OutputFormat == CROSSTABLE_Hypertext) {
                    if (CurrentGame == clash->gameNum)
                      sprintf (stemp, "<green><g_%u>", clash->gameNum);
                    else
                      sprintf (stemp, "<blue><g_%u>", clash->gameNum);
                    dstr->Append (stemp);
                }
                if (SwissColors) {
                    sprintf (stemp, "%*d%c%s", PlayerNumWidth,
                             InvertedIndex[clash->opponent] + 1,
                             clash->color == WHITE ? 'w' : 'b',
                             resultStr[clash->result]);
                } else {
                    sprintf (stemp, "%*d%s", PlayerNumWidth,
                             InvertedIndex[clash->opponent] + 1,
                             resultStr[clash->result]);
                }
                dstr->Append (stemp);
                if (OutputFormat == CROSSTABLE_Hypertext) {
                    if (CurrentGame == clash->gameNum)
                      dstr->Append ("</g></green>");
                    else
                      dstr->Append ("</g></blue>");
                }
                switch (clash->result) {
		  case 1:
		      r_won++; break;
		  case 2:
		      r_loss++; break;
		  case 3:
		      r_draw++; break;
                }
            }
            dstr->Append (EndCol);
        }
        PrintPerformance (dstr, pdata);

        if (PrintTallies) {
	  dstr->Append (StartCol);
	  sprintf (stemp, "  (+%u -%u =%u)", r_won, r_loss, r_draw);
	  dstr->Append (stemp);
	  dstr->Append (EndCol);
        }

        dstr->Append (EndRow, NewLine);
    }

    PrintDashesLine (dstr);
    dstr->Append (EndTable);
}
Esempio n. 3
0
void
Crosstable::PrintAllPlayAll (DString * dstr, uint playerLimit)
{
    char stemp [1000];
    uint player;

    dstr->Append (StartTable);
    if (OutputFormat == CROSSTABLE_LaTeX) {
        dstr->Append ("\\begin{tabular}{rl");
        if (PrintRatings) { dstr->Append ("r"); }
        if (PrintTitles) { dstr->Append ("r"); }
        if (PrintAges) { dstr->Append ("r"); }
        if (PrintCountries) { dstr->Append ("l"); }
        dstr->Append ("r@{ / }r");
        if (PrintTiebreaks) { dstr->Append ("r"); }
        for (uint i=0; i < playerLimit; i++) {
            dstr->Append ("c");
            if (i < playerLimit-1) { dstr->Append ("@{ }"); }
        }
        if (PrintRatings) { dstr->Append ("r"); }
        dstr->Append ("r}\n");
    }
    dstr->Append (StartRow);
    if (OutputFormat == CROSSTABLE_Html) {
        dstr->Append ("<th></th> <th>Player</th> ");
    } else if (OutputFormat == CROSSTABLE_LaTeX) {
        dstr->Append ("  & \\bf Player & ");
    } else {
        strPad (stemp, "", LongestNameLen + 2 + PlayerNumWidth, ' ');
        dstr->Append (stemp);
    }
    if (PrintRatings) {
        dstr->Append (StartBoldCol, " Rtng", EndBoldCol);
    }
    if (PrintTitles) {
        dstr->Append (StartBoldCol, "  Ti", EndBoldCol);
    }
    if (PrintAges) {
        dstr->Append (StartBoldCol, " Age", EndBoldCol);
    }
    if (PrintCountries) {
        dstr->Append (StartBoldCol, " Nat", EndBoldCol);
    }
    if (OutputFormat == CROSSTABLE_LaTeX) {
        // Todo : fix LateX Score column allignment with 3 points for win.
        dstr->Append (" \\multicolumn{2}{c}{\\bf Score} & ");
    } else {
        if (ThreeWin) 
	  dstr->Append ("  ", StartBoldCol, "Score", EndBoldCol, " ");
        else
	  dstr->Append ("   ", StartBoldCol, " Score ", EndBoldCol, "   ");
    }
    if (PrintTiebreaks) {
        dstr->Append (StartBoldCol, " (Tie) ", EndBoldCol);
    }

    for (player = 0; player < playerLimit; player++) {
        strPad (stemp, PlayerData[SortedIndex[player]]->name, MaxClashes, ' ');
        if (APAColumnNums) {
            // Print numbers instead of names over columns:
            strPad (stemp, "", MaxClashes, ' ');
            uint pnum = player + 1;
            stemp[MaxClashes-1] = (pnum % 10) + '0';
            if (MaxClashes >= 2  &&  pnum >= 10) {
                stemp[MaxClashes-2] = ((pnum / 10) % 10) + '0';
            }
            if (MaxClashes >= 3  &&  pnum >= 100) {
                stemp[MaxClashes-3] = ((pnum / 10) % 10) + '0';
            }
        }
        if (playerLimit == 2) {
            // Make two-player crosstable look better:
            player = 1;
            strPad (stemp,
                    "12345678901234567890123456789012345678901234567890",
                    MaxClashes, ' ');
        }
        if (OutputFormat == CROSSTABLE_LaTeX) {
            dstr->Append (" \\tt ", stemp, " &");
        } else {
            dstr->Append (" ", StartBoldCol, stemp, EndBoldCol);
        }
    }
    if (PrintRatings) {
        dstr->Append ("   ", StartBoldCol, "Perf Chg", EndBoldCol);
    }
    if (PrintTallies && OutputFormat == CROSSTABLE_Html) {
        dstr->Append ("   ", StartBoldCol, "+/-/=", EndBoldCol);
    }
    dstr->Append (EndRow, NewLine);

    PrintDashesLine (dstr);

    // Print the rows of players and results:
    uint previousScore = 0;
    for (player = 0; player < playerLimit; player++) {
        uint index = SortedIndex[player];
        playerDataT * pdata = PlayerData[index];

        // Print a blank line if we are at a new score group:
        if (SeparateScoreGroups  &&  SortOption == CROSSTABLE_SortScore) {
            if (player > 0  &&  pdata->score != previousScore) {
                dstr->Append (BlankRowLine);
            }
        }
        previousScore = pdata->score;

        sprintf (stemp, "%*u: ", PlayerNumWidth, player+1);
        dstr->Append (StartRow, StartRightCol, stemp, EndRightCol);

        PrintPlayer (dstr, pdata);

        if (OutputFormat == CROSSTABLE_LaTeX) {
            sprintf (stemp, " %2u%c%c ", pdata->score / 2, DecimalPointChar,
                     (pdata->score & 1 ? '5' : '0'));
            dstr->Append (StartRightCol, stemp, EndRightCol);
            sprintf (stemp, " %2u  ", pdata->gameCount);
            dstr->Append (StartRightCol, stemp, EndRightCol);
        } else {
            if (ThreeWin) {
	      sprintf (stemp, " %2u%c%c  ",
		       pdata->score / 2, DecimalPointChar,
		       (pdata->score & 1 ? '5' : '0'));
            } else {
	      sprintf (stemp, " %2u%c%c / %2u  ",
		       pdata->score / 2, DecimalPointChar,
		       (pdata->score & 1 ? '5' : '0'), pdata->gameCount);
            }
            dstr->Append (StartRightCol, stemp, EndRightCol);
        }
        if (PrintTiebreaks) {
            sprintf (stemp, "%3u%c%02u ", pdata->tiebreak / 4,
                     DecimalPointChar, (pdata->tiebreak % 4) * 25);
            dstr->Append (StartRightCol, stemp, EndRightCol);
        }

        uint r_won = 0, r_loss = 0, r_draw = 0;
        for (uint oppCount = 0; oppCount < playerLimit; oppCount++) {
            if (playerLimit == 2  &&  oppCount == player) { continue; }
            uint opp = SortedIndex[oppCount];
            dstr->AddChar (' ');
            dstr->Append (StartRightCol);
            clashT * clash = pdata->firstClash[opp];

            for (uint count = 0; count < MaxClashes; count++) {
                if (clash != NULL) {
                    if (OutputFormat == CROSSTABLE_Hypertext) {
                      if (CurrentGame == clash->gameNum)
                        sprintf (stemp, "<green><g_%u>%c</g></green>",
                                 clash->gameNum,
                                 RESULT_CHAR[clash->result]);
                      else
                        sprintf (stemp, "<blue><g_%u>%c</g></blue>",
                                 clash->gameNum,
                                 RESULT_CHAR[clash->result]);
                        dstr->Append (stemp);
                    } else {
                        dstr->AddChar (RESULT_CHAR[clash->result]);
                    }
		    switch (clash->result) {
		      case 1:
			  r_won++; break;
		      case 2:
			  r_loss++; break;
		      case 3:
			  r_draw++; break;
		    }
                    clash = clash->next;
                } else {
                    dstr->AddChar (index == opp ? 'X' : '.');
                }
            }
            dstr->Append (EndCol);
        }

        PrintPerformance (dstr, pdata);

        if (PrintTallies) {
	  dstr->Append (StartCol);
	  sprintf (stemp, "  (+%u -%u =%u)", r_won, r_loss, r_draw);
	  dstr->Append (stemp);
	  dstr->Append (EndCol);
        }

        dstr->Append (EndRow, NewLine);
    }
    PrintDashesLine (dstr);
    dstr->Append (EndTable);
}
Esempio n. 4
0
void
Crosstable::PrintKnockout (DString * dstr, uint playerLimit)
{
    char stemp [1000];
    uint player;

    for (uint round = 1; round <= MaxRound; round++) {
        if (OutputFormat == CROSSTABLE_LaTeX) {
            dstr->Append ("\n\n", round, ":\n\n");
        } else {
            dstr->Append (round, ":", NewLine);
        }
        dstr->Append (StartTable);
        if (OutputFormat == CROSSTABLE_LaTeX) {
            dstr->Append ("\\begin{tabular}{l");
            if (PrintRatings) { dstr->Append ("r"); }
            if (PrintTitles) { dstr->Append ("r"); }
            if (PrintAges) { dstr->Append ("r"); }
            if (PrintCountries) { dstr->Append ("l"); }
            dstr->Append ("@{\\hspace{4ex}}lr@{ / }r@{\\hspace{4ex}}l");
            if (PrintRatings) { dstr->Append ("r"); }
            if (PrintTitles) { dstr->Append ("r"); }
            if (PrintAges) { dstr->Append ("r"); }
            if (PrintCountries) { dstr->Append ("l"); }
            dstr->Append ("r}\n");
        }
        PrintDashesLine (dstr);
        for (player = 0; player < playerLimit; player++) {
            PlayerData[player]->printed = false;
        }
        for (player = 0; player < playerLimit; player++) {
            uint index = SortedIndex[player];
            playerDataT * pdata = PlayerData[index];
            clashT * clash = pdata->roundClash[round];
            if (clash == NULL) { continue; }
            if (pdata->printed) { continue; }
            uint opponent = clash->opponent;
            // if black first, skip this game till white is first
            if (pdata->firstClash[opponent]->color == 1) { continue; }
            uint score = 0;
            uint nGames = 0;
            clash = pdata->firstClash[opponent];
            while (clash != 0) {
                if (clash->round == round) {
                    score += RESULT_SCORE[clash->result];
                    nGames++;
                }
                clash = clash->next;
            }
            // Skip this to allow white to be shown first
            // if (score < nGames) { continue; }
            dstr->Append (StartRow);
            PrintPlayer (dstr, pdata);

            dstr->Append (StartCol, "  ");
            if (OutputFormat == CROSSTABLE_LaTeX) { dstr->Append ("{\\tt "); }
            clash = pdata->firstClash[opponent];
            for (uint count = 0; count < MaxClashes; count++) {
                while (clash != NULL  &&  clash->round != round) {
                    clash = clash->next;
                }
                if (clash != NULL) {
                    if (OutputFormat == CROSSTABLE_Hypertext) {
                        if (CurrentGame == clash->gameNum)
                            sprintf (stemp, "<green><g_%u>%c</g></green>",
                                     clash->gameNum,
                                     RESULT_CHAR[clash->result]);
                        else
                            sprintf (stemp, "<blue><g_%u>%c</g></blue>",
                                     clash->gameNum,
                                     RESULT_CHAR[clash->result]);
                        dstr->Append (stemp);
                    } else {
                        dstr->AddChar (RESULT_CHAR[clash->result]);
                    }
                    clash = clash->next;
                } else {
                    dstr->AddChar (' ');
                }
            }
            if (OutputFormat == CROSSTABLE_LaTeX) { dstr->Append ("}"); }
            dstr->Append (" ", EndCol);

            if (OutputFormat == CROSSTABLE_LaTeX) {
                sprintf (stemp, " %2u%c%c ", score / 2, DecimalPointChar,
                         (score & 1 ? '5' : '0'));
                dstr->Append (StartRightCol, stemp, EndRightCol);
                sprintf (stemp, " %2u  ", nGames);
                dstr->Append (StartRightCol, stemp, EndRightCol);
            } else {
                sprintf (stemp, "%2u%c%c / %2u   ",
                         score / 2, DecimalPointChar,
                         (score & 1 ? '5' : '0'), nGames);
                dstr->Append (StartRightCol, stemp, EndRightCol);
            }
            PrintPlayer (dstr, PlayerData[opponent]);
            dstr->Append (EndRow, NewLine);
            pdata->printed = true;
            PlayerData[opponent]->printed = true;
        }
        PrintDashesLine (dstr);
        dstr->Append (EndTable, NewLine);
    }
}