Esempio n. 1
0
int main (int argc, char* argv[]) {
    QApplication app(argc, argv);

    qRegisterMetaType<MoveInfo>("MoveInfo");
    qRegisterMetaType<PassInfo>("PassInfo");

    Dict dict;
    if (!dict.load("resource/dawg.bin") && !dict.load("/usr/local/share/AcaiBerry/resource/dawg.bin")) {
        cout << "Could not find dawg.bin in ./resource/ or /usr/local/share/AcaiBerry/resource.\n";
        return 1;
    }
    GameCore gc(dict);

    string usage(
            "AcaiBerry -- A Scrabble Program.\n"
            "Usage:\n"
            "[no arguments]       Run the game.\n"
            "--help               Display this message.\n"
            "--benchmark [num]    Simulate [num] games between 2 AI players. No GUI display.\n"
            "--me-first           Run the game with you making the first move.\n"
            "--demo               Run a game between 2 AI players and see the result.\n"
            "--text               Run in text mode. (Not fully implemented; only works together with --demo.)\n"
            );
    QStringList args = app.arguments();
    bool meFirst = false;
    bool demo = false;
    bool textMode = false;
    try {
        for (int i=0; i<args.length(); i++) {
            if (args[i] == "--help") {
                cout << usage;
                return 0;
            } else if (args[i] == "--benchmark") {
                i++;
                if (i >= args.length())
                    throw OptionError();
                bool conversionOk;
                int numGames = args[i].toInt(&conversionOk);
                if (!conversionOk)
                    throw OptionError();
                Simulator sim (gc, dict);
                sim.benchmark(numGames);
                return 0;
            } else if (args[i] == "--demo") {
                demo = true;
            } else if (args[i] == "--me-first") {
                meFirst = true;
            } else if (args[i] == "--text") {
                textMode = true;
            }
        }
    } catch(OptionError& e) {
        cout << usage;
        return 0;
    }

    QWidget win;
    setupWindow(win, gc, meFirst ? 0 : 1);
    gc.reset();

    if (demo) {
        Simulator sim (gc, dict);
        sim.benchmark(1);
        if (textMode) {
            cout << txtDisplay(gc.board());
            return 0;
        } else {
            return app.exec();
        }
    }

    Berry berry (gc.pin(meFirst ? 1 : 0), gc.board(), dict);
    if (!meFirst)
        berry.makeTurn();

    return app.exec();
}