double CFormulaParser::calcFormula(std::string formula, std::map<char, double> params)
{
	std::stack<double> stack;
	plus<double> pl;
	minus<double> min;
	multiplies<double> mult;
	divides<double> div;
	power<double> pw;

	for (std::string::iterator it = formula.begin(); it != formula.end(); it++)
	{
		switch (*it)
		{
		case '+':
			stack.push(makeAction(&stack, &pl));
			break;
		case '-':
			stack.push(makeAction(&stack, &min));
			break;
		case '*':
			stack.push(makeAction(&stack, &mult));
			break;
		case '/':
			stack.push(makeAction(&stack, &div));
			break;
		case '^':
			stack.push(makeAction(&stack, &pw));
			break;
		default:
			stack.push(params[*it]);
		}
	}
	double result = stack.top();
	return result;
}
void kmagnetGenerator::makeMorePaths()
{
    int i=0;
    makingmorepaths=true;
    while ( i < movements.size())
    {
        int move=movements.at(i);
        if (m_scene->getCell(move)->getIsFree() && !m_scene->getCell(move)->getIsFinal())
        {
            m_scene->setCurrentPosition(move);
        }
        else
        {   
            i++;
            continue;
        }
        int moveDirection=qrand() % 4;
        Moves::Move m = (Moves::Move)moveDirection;
        makeAction(move,m);
        m=(Moves::Move)((int)(moveDirection+1) %4);
        makeAction(move,m);
        m=(Moves::Move)((int)(moveDirection+2) %4);
        makeAction(move,m);
        m=(Moves::Move)((int)(moveDirection+3) %4);
        makeAction(move,m);
        i++;
    }
}
Exemple #3
0
// some more isLegalAction testing
void test10 (void) {
    action a;
    int disciplines[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    int dice[] = {6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6};
    Game g = newGame(disciplines, dice);
    throwDice(g, 6);
    throwDice(g, 6);
    throwDice(g, 6);
    throwDice(g, 6);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "R", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 4, a.disciplineTo = 3;
    makeAction(g, a);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "RR", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 4, a.disciplineTo = 3;
    makeAction(g, a);
    a.actionCode = BUILD_CAMPUS;
    strncpy(a.destination, "RR", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 4, a.disciplineTo = 3;
    assert(isLegalAction(g, a) == 1);
}
QAction *ModelMenu::makeAction(const QModelIndex &index)
{
    QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
    QAction *action = makeAction(icon, index.data().toString(), this);
    QVariant v;
    v.setValue(index);
    action->setData(v);
    return action;
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    m_stringManager = new StringManager();
    m_mindmapView = new MindMapView(this);// new GraphWidget(m_stringManager,this);
    m_mindtoolbar = new MindToolBar(m_stringManager,this);
    //m_detailpanel = new DetailPanel(this);
    m_browser = new ItemBrowser;
    m_scene = new MindMap(this);
    m_scene->setStringManager(m_stringManager);
    m_mindmapView->setScene(m_scene);

    m_scene->setSceneRect(0,0,1024,768);
    m_mindmapView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    m_mindmapView->setRenderHints(QPainter::Antialiasing |QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform );
   /* m_timeLine = new TimeLineWidget();


    QDockWidget* bottom = new QDockWidget(tr("TimeLine"),this);
    bottom->setWidget(m_timeLine);
    addDockWidget(Qt::BottomDockWidgetArea,bottom);*/


    m_title = tr("%1[*] - MindMap Rolisteam - v0.0.1");
    setObjectName("MainWindow");
    setWindowTitle(m_title.arg(tr("untitled")));

    /*connect(m_mindmapView,SIGNAL(currentEdge(GenericMindMapItem*)),m_detailpanel,SLOT(setCurrentGenericItem(GenericMindMapItem*)));
    connect(m_mindmapView,SIGNAL(currentNode(GenericMindMapItem*)),m_detailpanel,SLOT(setCurrentGenericItem(GenericMindMapItem*)));
    connect(m_mindmapView,SIGNAL(currentPackage(GenericMindMapItem*)),m_detailpanel,SLOT(setCurrentGenericItem(GenericMindMapItem*)));

    connect(m_mindmapView,SIGNAL(currentPackage(GenericMindMapItem*)),m_detailpanel,SLOT(show()));
    connect(m_mindmapView,SIGNAL(currentEdge(GenericMindMapItem*)),m_detailpanel,SLOT(show()));
    connect(m_mindmapView,SIGNAL(currentNode(GenericMindMapItem*)),m_detailpanel,SLOT(show()));
    connect(m_mindmapView,SIGNAL(selectionIsEmpty()),m_detailpanel,SLOT(hide()));
    connect(m_mindmapView,SIGNAL(nodeAsBrush(Node*)),m_mindtoolbar,SLOT(addNodeBrush(Node*)));

    connect(m_mindmapView,SIGNAL(itemHasBeenAdded(GenericMindMapItem*)),m_browser,SLOT(addItem(GenericMindMapItem*)));

    connect(m_mindmapView,SIGNAL(itemHasBeenDeleted(GenericMindMapItem*)),m_browser,SLOT(removeItem(GenericMindMapItem*)));*/


    m_preferences = PreferencesManager::getInstance();

    m_recentFileActions = new QList<QAction*>();

    setupUi();

    readSettings();
    makeAction();
    makeMenu();

}
Exemple #6
0
// test getMostArcs
void test5(void) {
    printf("\n\n\n\n");
    action a;
    int disciplines[] = {4,2,5,4,2,2,3,5,1,3,5,4,4,4,3,5,4,0,5};
    int dice[] = {8,10,8,9,6,4,4,5,12,3,11,6,3,11,2,7,5,6,5};
    Game g = newGame(disciplines, dice);
    throwDice(g, 7);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "L", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 0, a.disciplineTo = 0;
    makeAction(g, a);
    assert(getMostARCs(g) == 1);
}
Exemple #7
0
// test getExchangeRate
void test6(void) {
    printf("\n\n\n\n");
    action a;
    int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
    int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
    Game g = newGame(disciplines, dice);
    throwDice(g, 5);
    a.actionCode = BUILD_CAMPUS;
    strncpy(a.destination, "R", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 1, a.disciplineTo = -1217678112;
    makeAction(g, a);
    assert(getExchangeRate (g, 1, 4, 1) == 2);
}
Exemple #8
0
void CallStackView::setupContextMenu()
{
    mMenuBuilder = new MenuBuilder(this, [](QMenu*)
    {
        return DbgIsDebugging();
    });
    QIcon icon = DIcon(ArchValue("processor32.png", "processor64.png"));
    mMenuBuilder->addAction(makeAction(icon, tr("Follow &Address"), SLOT(followAddress())));
    QAction* mFollowTo = mMenuBuilder->addAction(makeAction(icon, tr("Follow &To"), SLOT(followTo())));
    mFollowTo->setShortcutContext(Qt::WidgetShortcut);
    mFollowTo->setShortcut(QKeySequence("enter"));
    connect(this, SIGNAL(enterPressedSignal()), this, SLOT(followTo()));
    mMenuBuilder->addAction(makeAction(icon, tr("Follow &From"), SLOT(followFrom())), [this](QMenu*)
    {
        return !getCellContent(getInitialSelection(), 2).isEmpty();
    });
    MenuBuilder* mCopyMenu = new MenuBuilder(this);
    setupCopyMenu(mCopyMenu);
    // Column count cannot be zero
    mMenuBuilder->addSeparator();
    mMenuBuilder->addMenu(makeMenu(DIcon("copy.png"), tr("&Copy")), mCopyMenu);
    mMenuBuilder->loadFromConfig();
}
void convertStudents(Game g, int studentFrom, int studentTo, int numToCreate){
	action a;
	a.actionCode = RETRAIN_STUDENTS;
	a.disciplineFrom = studentFrom;
	a.disciplineTo = studentTo;

	int i = 0;
	while (i < numToCreate) {
		if (isLegalAction(g, a)){
			makeAction(g, a);
		}
		i++;
	}
}
Exemple #10
0
void test3(void) {
    printf("\n\n\n\n");
    action a;
    int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
    int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
    Game g = newGame(disciplines, dice);
    throwDice(g, 5);
    a.actionCode = BUILD_CAMPUS;
    strncpy(a.destination, "RL", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = -1077724424, a.disciplineTo = 134527641;
    makeAction(g, a);
    assert(getCampus(g, "RL") == 1);
}
void WBModelMenu::createMenu(const QModelIndex &parent, int max, QMenu *parentMenu, QMenu *menu)
{
    if (!menu)
    {
        QString title = parent.data().toString();
        menu = new QMenu(title, this);
        QIcon icon = qvariant_cast<QIcon>(parent.data(Qt::DecorationRole));
        menu->setIcon(icon);
        parentMenu->addMenu(menu);
        QVariant v;
        v.setValue(parent);
        menu->menuAction()->setData(v);
        connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShow()));
        return;
    }

    int end = m_model->rowCount(parent);
    if (max != -1)
        end = qMin(max, end);

    connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(triggered(QAction*)));
    connect(menu, SIGNAL(hovered(QAction*)), this, SLOT(hovered(QAction*)));

    for (int i = 0; i < end; ++i)
    {
        QModelIndex idx = m_model->index(i, 0, parent);
        if (m_model->hasChildren(idx))
        {
            createMenu(idx, -1, menu);
        } 
        else
        {
            if (m_separatorRole != 0
                && idx.data(m_separatorRole).toBool())
                addSeparator();
            else
                menu->addAction(makeAction(idx));
        }
        if (menu == this && i == m_firstSeparator - 1)
            addSeparator();
    }
}
Exemple #12
0
// test building ARC
void test4(void) {
    printf("\n\n\n\n");
    action a;
    int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
    int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
    Game g = newGame(disciplines, dice);
    throwDice(g, 5);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "L", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 134528624, a.disciplineTo = -1081831912;
    assert(isLegalAction(g, a) == 1);
    makeAction(g, a);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "LR", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 134528624, a.disciplineTo = -1081831912;
    assert(isLegalAction(g, a) == 1);

}
Exemple #13
0
void runGame (void) {
    // create a dummy game
    int disciplines[] = DEFAULT_DISCIPLINES;
    int dice[] = DEFAULT_DICE;
    Game g = newGame (disciplines, dice);
    
    printf ("Running a test game...\n");
    // roll the dice
    int diceScore;
    diceScore = rollDice ();
    // progress the game
    throwDice (g, diceScore);
    
    printf ("Deciding on the action...\n");
    action newAction;
    newAction = decideAction (g);
    while (!getWinner (g)) {
        // if the player PASSES
        if (newAction.actionCode == PASS) {
            diceScore = rollDice ();
            // progress the game
            throwDice (g, diceScore);
        }
        else
        {
            if (isLegalAction (g, newAction)) {
                makeAction (g, newAction);
            } else {
                printf (">>> I'm sorry but you can't do that!\n");
            }
        }
        // get the next turn
        newAction = decideAction (g);
        
    }
    // the game is over
    printf ("\nGame over. Player %d wins\n", getWinner (g));
    disposeGame (g);
}
Exemple #14
0
// test starting spinoffs
void test9 (void) {
    action a;
    int disciplines[] = {2,5,3,5,3,1,4,4,1,4,2,3,2,0,3,5,4,2,1};
    int dice[] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};
    Game g = newGame(disciplines, dice);
    throwDice(g, 8);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "R", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = -1217350860, a.disciplineTo = 7;
    makeAction(g, a);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "RR", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = -1217350860, a.disciplineTo = 7;
    makeAction(g, a);
    a.actionCode = PASS;
    strncpy(a.destination, "", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = -1078711464, a.disciplineTo = 134586891;
    makeAction(g, a);
    throwDice(g, 5);
    a.actionCode = OBTAIN_ARC;
    strncpy(a.destination, "RRLRLL", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = -1217350860, a.disciplineTo = 7;
    makeAction(g, a);
    a.actionCode = PASS;
    strncpy(a.destination, "", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = -1078711464, a.disciplineTo = 134586891;
    makeAction(g, a);
    throwDice(g, 6);
    a.actionCode = OBTAIN_PUBLICATION;
    strncpy(a.destination, "", PATH_LIMIT - 1);
    a.destination[PATH_LIMIT - 1] = 0;
    a.disciplineFrom = 1, a.disciplineTo = 2329;
    printf("%d\n", getStudents(g, 3, 3));
    makeAction(g, a);
    assert(getStudents(g, 3, 3) == 1);
}
Exemple #15
0
// NOTE:  IS MAKEACTION(g, PASS_ACTION) required to end turn?  or just THROWDICE?
// Unsure on this, might ahve to ask a tutor.
void testStudentAllocationAndMakeAction (void) {

    printf ("Now testing updating of students after dice throws and actions.\n");

    // Create game:
    int disciplines[] = DEFAULT_DISCIPLINES;
    int dice[] = DEFAULT_DICE;
    Game g = newGame (disciplines, dice);

    // Throw the dice once, not giving any players students, to move the
    // current turn to '0' rather than '-1':
    throwDice(g, 3);

    // Allocate 300 students to each player through numerous dice throws!
    int throws = 0;
    while (throws < 150) {

        // Trigger each hexagon with an adjoined campus:

        throwDice(g, 11); // 1 MTV to player 1
        throwDice(g, 6);  // 1 MJ to player 1

        throwDice(g, 9); // 1 BQN to player 2
        throwDice(g, 9); // 1 BQN to player 2
        throwDice(g, 9); // 1 BQN to player 2
        throwDice(g, 5); // 1 BPS to player 2
        throwDice(g, 5); // 1 BPS to player 2
        throwDice(g, 5); // 1 BPS to player 2

        throwDice(g, 8); // 1 MJ and 1 MTV to player 3
    }

    /* At this point:
     *  - Turn number is [150 * 9 = ] 1350
     *  - Number of turns mod 3 is 0, therefore player 1's (UNI_A) turn to roll.
     *  - Player 1 has 150 MJs and 150 MTVs
     *  - Player 2 has 450 BQNs and 450 BPSs
     *  - Player 3 has 150 MJs and 150 MTVs
    */

    // Ensure game state has been updated correctly:

    printf ("Ensuring 'getTurnNumber' and 'getWhoseTurn' return correct values.\n");
    assert (getTurnNumber(g) == 750);
    assert (getWhoseTurn(g) == UNI_A);

    printf ("Ensuring UNI_A has been allocated the correct number of players.\n");
    assert (getStudents(g, UNI_A, STUDENT_BPS)    == 0);
    assert (getStudents(g, UNI_A, STUDENT_BQN)    == 0);
    assert (getStudents(g, UNI_A, STUDENT_MJ)     == 150);
    assert (getStudents(g, UNI_A, STUDENT_MTV)    == 150);
    assert (getStudents(g, UNI_A, STUDENT_MMONEY) == 0);
    assert (getStudents(g, UNI_A, STUDENT_THD)    == 0);

    printf ("Ensuring UNI_B has been allocated the correct number of players.\n");
    assert (getStudents(g, UNI_B, STUDENT_BPS)    == 450);
    assert (getStudents(g, UNI_B, STUDENT_BQN)    == 450);
    assert (getStudents(g, UNI_B, STUDENT_MJ)     == 0);
    assert (getStudents(g, UNI_B, STUDENT_MTV)    == 0);
    assert (getStudents(g, UNI_B, STUDENT_MMONEY) == 0);
    assert (getStudents(g, UNI_B, STUDENT_THD)    == 0);

    printf ("Ensuring UNI_C has been allocated the correct number of players.\n");
    assert (getStudents(g, UNI_C, STUDENT_BPS)    == 0);
    assert (getStudents(g, UNI_C, STUDENT_BQN)    == 0);
    assert (getStudents(g, UNI_C, STUDENT_MJ)     == 150);
    assert (getStudents(g, UNI_C, STUDENT_MTV)    == 150);
    assert (getStudents(g, UNI_C, STUDENT_MMONEY) == 0);
    assert (getStudents(g, UNI_C, STUDENT_THD)    == 0);



    // Convert UNI_B's BQNs and BPSs into MJs and MTVs, so that each
    // UNI has the same numbers of students:
    printf ("Testing basic student conversion.\n");

    // Move turn to UNI_B from UNI_A (without giving the UNIs students):
    throwDice(g, 3);

    action convertStudents;
    convertStudents.actionCode = RETRAIN_STUDENTS;

    // Convert BPSs into MJs:
    convertStudents.disciplineFrom = STUDENT_BPS;
    convertStudents.disciplineTo = STUDENT_MJ;

    int numConversions = 0;
    while (numConversions < 150) {
        makeAction(g, convertStudents);
    }

    // Ensure the counts have been updated correctly:
    assert (getStudents(g, UNI_B, STUDENT_BPS) == 0);
    assert (getStudents(g, UNI_B, STUDENT_MJ)  == 150);


    // Convert BQNs into MTVs:
    convertStudents.disciplineFrom = STUDENT_BQN;
    convertStudents.disciplineTo = STUDENT_MTV;

    int numConversions = 0;
    while (numConversions < 150) {
        makeAction(g, convertStudents);
    }

    // Ensure the counts have been updated correctly:
    assert (getStudents(g, UNI_B, STUDENT_BQN) == 0);
    assert (getStudents(g, UNI_B, STUDENT_MTV) == 150);


    // Now each UNI has 150 MTVs and 150 MJs.

    // Set turn to UNI_A:
    throwDice(g, 3); // Now UNI_C's turn
    throwDice(g, 3); // Now UNI_A's turn



    // Get each UNI to perform path-based and path-less actions:
    int activeUNI = UNI_A;
    while (activeUNI != NO_ONE) {

        action testAction;

        testAction.actionCode = PASS


        // Set activeUNI to the next UNI
        // Note: incrementing not used because the values of the
        //       constants are not guaranteed.
        throwDice(g, 3);
        if (activeUNI == UNI_A) {
            activeUNI = UNI_B;
        } else if (activeUNI == UNI_B) {
            activeUNI = UNI_C;
        } else {
            activeUNI = NO_ONE;
        }
    }



    disposeGame (g);
    printf ("Passed\n");
}
Exemple #16
0
MacMenu::MacMenu() :
	QMenuBar(nullptr)
{
	//
	// File menu
	//
	QMenu *filemenu = addMenu(MainWindow::tr("&File"));

	QAction *newdocument = makeAction(filemenu, "newdocument", MainWindow::tr("&New"), QKeySequence::New);
	QAction *open = makeAction(filemenu, "opendocument", MainWindow::tr("&Open..."), QKeySequence::Open);

	connect(newdocument, &QAction::triggered, this, &MacMenu::newDocument);
	connect(open, &QAction::triggered, this, &MacMenu::openDocument);

	_recent = filemenu->addMenu(MainWindow::tr("Open &Recent"));
	connect(_recent, &QMenu::triggered, this, &MacMenu::openRecent);

	// Relocated menu items
	QAction *quit = makeAction(filemenu, "exitprogram", MainWindow::tr("&Quit"), QKeySequence("Ctrl+Q"));
	quit->setMenuRole(QAction::QuitRole);
	connect(quit, &QAction::triggered, this, &MacMenu::quitAll);

	QAction *preferences = makeAction(filemenu, 0, MainWindow::tr("Prefere&nces"), QKeySequence());
	preferences->setMenuRole(QAction::PreferencesRole);
	connect(preferences, &QAction::triggered, &MainWindow::showSettings);

	//
	// Session menu
	//

	QMenu *sessionmenu = addMenu(MainWindow::tr("&Session"));
	QAction *host = makeAction(sessionmenu, "hostsession", MainWindow::tr("&Host..."), QKeySequence());
	QAction *join = makeAction(sessionmenu, "joinsession", MainWindow::tr("&Join..."), QKeySequence());

	host->setEnabled(false);
	connect(join, &QAction::triggered, this, &MacMenu::joinSession);

	//
	// Window menu (Mac specific)
	//
	_windows = addMenu(MainWindow::tr("Window"));
	connect(_windows, &QMenu::triggered, this, &MacMenu::winSelect);
	connect(_windows, &QMenu::aboutToShow, this, &MacMenu::updateWinMenu);

	QAction *minimize = makeAction(_windows, 0, tr("Minimize"), QKeySequence("ctrl+m"));

	_windows->addSeparator();

	connect(minimize, &QAction::triggered, this, &MacMenu::winMinimize);

	//
	// Help menu
	//
	QMenu *helpmenu = addMenu(MainWindow::tr("&Help"));

	QAction *homepage = makeAction(helpmenu, "dphomepage", MainWindow::tr("&Homepage"), QKeySequence());
	QAction *about = makeAction(helpmenu, "dpabout", MainWindow::tr("&About Drawpile"), QKeySequence());
	about->setMenuRole(QAction::AboutRole);
	QAction *aboutqt = makeAction(helpmenu, "aboutqt", MainWindow::tr("About &Qt"), QKeySequence());
	aboutqt->setMenuRole(QAction::AboutQtRole);

	connect(homepage, &QAction::triggered, &MainWindow::homepage);
	connect(about, &QAction::triggered, &MainWindow::about);
	connect(aboutqt, &QAction::triggered, &QApplication::aboutQt);

	//
	// Initialize
	//
	updateRecentMenu();
}
Exemple #17
0
int main(int argc, char * argv[]){
    int disciplines[] = DEFAULT_DISCIPLINES;
    int dice[] = DEFAULT_DICE;
    int turnOver = FALSE;
    int winner = NO_ONE;
    int diceValue;
    action move;
    int whoseTurn = NO_ONE;

    srand(time(NULL)); //initialises a seed
    Game g = newGame(disciplines,dice);

    while (winner == NO_ONE) {

        diceValue = rollDice(2,6);

        throwDice(g,diceValue);

        printf("[Turn %d] The turn now belongs to University %d!\n",
            getTurnNumber(g),
            getWhoseTurn(g));
        printf("The dice casted a %d!\n", diceValue);

        whoseTurn = getWhoseTurn(g);
        //loop until player action is PASS
        turnOver = FALSE;
        while (!turnOver) {
            move = getMove(g);
            //print info about move
            printf("Move %d \n",move.actionCode);
            assert(isLegalAction(g, move));

            if (move.actionCode == START_SPINOFF) {

                //decide if outcome is patent or publication
                if (rand() % 3 <= 1) {
                    move.actionCode = OBTAIN_PUBLICATION;
                } else {
                    move.actionCode = OBTAIN_IP_PATENT;
                }
            }

            if(move.actionCode == PASS){
                 turnOver = TRUE;
                 printf("Pass\n");
            }
            makeAction(g, move);


            if(getKPIpoints(g, whoseTurn) >= WINNING_KPI){
                winner = whoseTurn;
                turnOver = TRUE;
                printf("Winner %d\n",whoseTurn);
            }

        }
    }


    // TODO print statistics

    // TODO free memory

    return EXIT_SUCCESS;
}
Exemple #18
0
YY_ACTION(void) yy_7_primary(GREG *G, char *yytext, int yyleng, yythunk *thunk, YY_XTYPE YY_XVAR)
{
  yyprintf((stderr, "do yy_7_primary\n"));
   push(makeAction(yytext)); ;
}
void LiquidityProvider::makeAction(int a_OrderBookId, double a_currentTime){
	makeAction(a_OrderBookId, a_currentTime,true);
}
Exemple #20
0
int main(int argc, char *argv[]) {
   // miscellaneous
   /*int disciplines[NUM_REGIONS];
   int dice[NUM_REGIONS];*/
   Game g;
   
   // store the winner of each game
   int winner;
   
   // store game states within the game
   int keepPlaying;
   int turnFinished;
   int diceRollAmount;
   
   // random
   char *actions[] = ACTION_NAMES;
   int diceRoll;
   
   int passedTurns = 0;
            
   // seed rand!
   srand(time(NULL));
   
   // while the game is wanting to be played, create new game, etc.
   keepPlaying = TRUE;
   while (keepPlaying == TRUE) {
      // create the game
      //randomDisciplines(disciplines);
      //randomDice(dice);
      
      // you can change this to randomiseDisciplines() and randomiseDice() later
      int disciplines[NUM_REGIONS] = {CYAN,PURP,YELL,PURP,YELL,RED ,GREE,GREE, RED ,GREE,CYAN,YELL,CYAN,BLUE,YELL,PURP,GREE,CYAN,RED };
      int dice[NUM_REGIONS] = {9,10,8,12,6,5,3,7,3,11,4,6,4,9,9,2,8,10,5};

      // rig board like the real game
      rigBoard(disciplines, dice);
      g = newGame(disciplines, dice);
      
      printf("Game created! Now playing...\n");
      
      // start the game with noone as the winner
      winner = NO_ONE;
      while (winner == NO_ONE) {
         printLineBreak();
         // start new turn by setting turnFinished to false then
         // rolling the dice
         
         diceRollAmount = 0;
         diceRoll = 0;
         while (diceRollAmount < DICE_AMOUNT) {
            diceRoll += rollDice();
            diceRollAmount++;
         }
         
         throwDice(g, diceRoll);
         
         // new turn means new line break!
         printf("[Turn %d] The turn now belongs to University %c!\n", 
            getTurnNumber(g),
            getWhoseTurn(g) + UNI_CHAR_NAME);
//         printf("The dice has casted a %d!\n", diceRoll);
         
         printf("\n");
         
         
         // keep going through the player's turn until
         // he/she decided to pass and finish the turn
         turnFinished = FALSE;
         while (turnFinished == FALSE && passedTurns < MAX_PASS) {
            // processes requests and all subrequests for a move and
            // checks if they are legal. only gives a move within the
            // scope of the defined actionCodes that is legal
            int turnPerson = getWhoseTurn(g);
/*            printf("Stats for %c:\n", turnPerson + UNI_CHAR_NAME);
            printf("KPIs: %d\n", getKPIpoints(g, turnPerson));
            printf("ARCs: %d\n", getARCs(g, turnPerson));
            printf("Campuses: %d\n", getCampuses(g, turnPerson));
            printf("GO8s: %d\n", getGO8s(g, turnPerson));
            printf("Publications: %d\n", 
               getPublications(g, turnPerson));
            printf("Patents: %d\n", 
               getIPs(g, turnPerson));
            int discipleIndex = 0;
            char *discipleNames[] = DISCIPLE_NAMES;
            while (discipleIndex < NUM_DISCIPLINES) {
               printf("Type %s: %d\n", discipleNames[discipleIndex],
                  getStudents(g, turnPerson, discipleIndex));
               discipleIndex++;
            } 
*/            printf("\n");
            
            action a = decideAction(g);
            
            // if not passing, make the move; otherwise end the turn
            if (a.actionCode == PASS) {
               turnFinished = TRUE;
               printf("You have passed onto the next person.\n");
            } else {
              
               // write what the player did, for a logs sake.
 /*              printf("The action '%s' has being completed.\n", 
                       actions[a.actionCode]);
               if (a.actionCode == BUILD_CAMPUS 
                   || a.actionCode == OBTAIN_ARC 
                   || a.actionCode == BUILD_GO8) {
                  printf(" -> Destination: %s\n", a.destination);
               } else if (a.actionCode == RETRAIN_STUDENTS) {
                  printf(" -> DisciplineTo: %d\n", a.disciplineTo);
                  printf(" -> DisciplineFrom: %d\n", a.disciplineFrom);
               }
*/
               assert(isLegalAction(g, a));                                   
            
               // break this and the code dies. trololol!
               if (a.actionCode == START_SPINOFF) {
                  if (rand() % 3 <= 1) {
                     a.actionCode = OBTAIN_PUBLICATION;
                  } else {
                     a.actionCode = OBTAIN_IP_PATENT;               
                  }
               }

               makeAction(g, a);
               
               if (a.actionCode == PASS) {
                  passedTurns++;
               } else {
                  passedTurns = 0;
               }
               
               if (passedTurns >= MAX_PASS || getKPIpoints(g, turnPerson) >= WINNING_KPI) {
                  turnFinished = TRUE;
                  
               }
            }
            
            // if there is not a winner or pass, add a seperating line
            // to seperate actions being clumped together
            if (turnFinished == FALSE) {
               printf("\n");
            }
         }
         
         // check if there is a winner
         winner = checkForWinner(g);
      }
      
      if (passedTurns >= MAX_PASS) {
         printf("AI passes too much.\n");
         return EXIT_FAILURE;
      }
      
      printLineBreak();
      printf("GAME OVER!\n");
      printf("Vice Chanceller %c Won in %d Turns!!\n", 
             winner + UNI_CHAR_NAME,
             getTurnNumber(g));
             
      printf("\n");
      int counter = UNI_A;
      while (counter < NUM_UNIS + UNI_A) {
         printf("Uni %c scored %d KPIs\n", counter + UNI_CHAR_NAME,
                getKPIpoints(g, counter));
         counter++;
      }
      printLineBreak();
      
      disposeGame(g);
      
      // ask to play again
      printf("Ctrl+C will exit the game.\nOtherwise, the game will "
             "recommence by hitting enter.");
      int a = scanf("%*c");
      a++;
   }     
   
   return EXIT_SUCCESS;
}
int main (int argc, char * argv[]) {

	int disciplines[19] = {STUDENT_BQN, STUDENT_MMONEY, STUDENT_MJ, \
		STUDENT_MMONEY, STUDENT_MJ, STUDENT_BPS, STUDENT_MTV, \
		STUDENT_MTV, STUDENT_BPS,STUDENT_MTV, STUDENT_BQN, \
		STUDENT_MJ, STUDENT_BQN, STUDENT_THD, STUDENT_MJ, \
		STUDENT_MMONEY, STUDENT_MTV, STUDENT_BQN, STUDENT_BPS};

	int dice[19] = {9,10,8,12,6,5,3,11,3,11,4,6,4,7,9,2,8,10,5};

	Game g = newGame (disciplines, dice);
	action a;
//	int score = 0; //This stores the KPI points of current player 
	int curPlayer = NO_ONE; 
	int curTurn = 0; 
	int playerKPI = 0;
	int numStudents[MAX_STU_TYPES];
	int legal = 0;
	int diceScore = 0; 
	int spinoffDice = 0;
	//int discipline = 0;
	int counter = 0; 

	char *degrees[] = \
		  {"THDs", "BPSs", "BQNs", "MJs", "MTVs", "MMONEYs"};
	


	printf ("New game created, variables are initialized.\n");
	printf ("Let the game begin!\n\n");

	while (playerKPI < MAX_KPIPTS) {
		
		//To simulate an actual real life dice, we throw two dice 
		diceScore = rollDice();
		throwDice (g, diceScore);

		curTurn = getTurnNumber (g);
		curPlayer = getWhoseTurn (g);
		printf ("Turn number: %d\n", curTurn);
		printf ("Player %d's turn. Rolling dice.\n", curPlayer);
		printf ("The two dice rolled a %d! \n", diceScore);

		printf ("You currently have: \n");
		counter = 0;
		while (counter < MAX_STU_TYPES) {
			numStudents[counter] = getStudents (g, curPlayer, counter);
			printf ("    %d: %s\n", numStudents[counter],\
								    degrees[counter]);
			counter ++;
		}
		actionOptions ();
		a = actionPrompt (g);
		legal = isLegalAction (g, a);

		while (a.actionCode != PASS) {
			while (legal == FALSE) {
				printf ("The chosen action is illegal, try again.\n");
				actionPrompt (g);
				legal = isLegalAction (g, a);
			}

			if (a.actionCode == START_SPINOFF) {
				//Ensures dice returns 1, 2 or 3.
				spinoffDice = (rand()%3 + 1);
				if (spinoffDice == 1) {
					a.actionCode = OBTAIN_IP_PATENT;
				} else {
					a.actionCode = OBTAIN_PUBLICATION;
				}
			}

			makeAction (g, a);
			printf("Action made!");

			printf ("Your current stats:\n");
			printf ("    ARC Grants: %d\n", getARCs (g, curPlayer));
			printf ("    No of Campuses: %d\n", getCampuses (g, curPlayer));
			printf ("    No of G08s: %d\n", getGO8s (g, curPlayer));
			printf ("    No of Pubs: %d\n", getPublications (g, curPlayer));
			printf ("    No of IP Patents: %d\n", getIPs (g, curPlayer));

			playerKPI = getKPIpoints (g, curPlayer);
			printf ("Player %d KPI Score: %d\n\n", curPlayer, playerKPI);
		}

		printf ("Next player's turn.\n\n");

	}

	printf ("Congratulations, player %d won.\n", curPlayer);
	printf ("Game completed. Disposing game.\n");
	
	disposeGame (g);

	return EXIT_SUCCESS;
}
Exemple #22
0
YY_ACTION(void) yy_7_primary(char *yytext, int yyleng)
{
  yyprintf((stderr, "do yy_7_primary\n"));
   push(makeAction(yytext)); ;
}
int main(int argc, char *argv[]) {
    int disciplines[] = DEFAULT_DISCIPLINES;
    disciplines[2] = STUDENT_BPS;
    disciplines[7] = STUDENT_BPS;
    disciplines[11] = STUDENT_BQN;
    disciplines[16] = STUDENT_BQN;
    int dice[] = DEFAULT_DICE;
    int i = 0;
    int automation = TRUE;
    int diceRoll = 1;
    char *vertices[54];
    char *sides[72];

    //nanosecond seeding
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);

    populatePaths(vertices);
    populateSides(sides);

    printf("Automatic(1) or Human(0): ");
    scanf("%d", &automation);

    //seeding starts now
    srand((time_t)ts.tv_nsec);

    Game g = newGame(disciplines, dice);
    action a;

    while(getKPILeader(g) < 150  &&  getTurnNumber(g) < 9003) {
        if(automation == FALSE) {
            printf("Enter dice roll: ");
            scanf("%d", &diceRoll);
        } else {
            diceRoll = rand() % 10 + 2;
        }

        throwDice(g, diceRoll);
        printf("diceRoll = %d\n", diceRoll);

        printf("\n");
        printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
        printf("Turn: %d\n", getTurnNumber(g));
        printf("Player %d's turn\n", getWhoseTurn(g));

        printf("\n");
        printf("You have %d ARCs\n", getARCs(g, getWhoseTurn(g)));
        i = 0;
        while(i < 72) {
            if(getARC(g, sides[i]) == getWhoseTurn(g)) { 
                printf("You have an ARC on %s\\0\n", sides[i]);
            }
            i++;
        }
        printf("You have %d Campuses\n", getCampuses(g, getWhoseTurn(g)));
        printf("You have %d GO8s\n", getGO8s(g, getWhoseTurn(g)));
        i = 0;
        while(i < 54) {
            if(getCampus(g, vertices[i]) == getWhoseTurn(g)) { 
                printf("You have a campus on %s\\0\n", vertices[i]);
            }
            if(getCampus(g, vertices[i]) == getWhoseTurn(g) + 3) {
                printf("You have a GO8 on %s\\0\n", vertices[i]);
            }
            i++;
        }
        printf("You have %d Publications\n", getPublications(g, getWhoseTurn(g)));
        printf("You have %d IP Patents\n", getIPs(g, getWhoseTurn(g)));
        printf("\n");
        
        printf("Students:\n");
        printf("You have %d THD Students\n", getStudents(g, getWhoseTurn(g), STUDENT_THD));
        printf("You have %d BPS Students\n", getStudents(g, getWhoseTurn(g), STUDENT_BPS));
        printf("You have %d BQN Students\n", getStudents(g, getWhoseTurn(g), STUDENT_BQN));
        printf("You have %d MJ Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MJ));
        printf("You have %d MTV Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MTV));
        printf("You have %d MMONEY Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MMONEY));
        printf("\n");

        if(automation == FALSE) {
            a = getHumanAction();
        } else {
            a = getAIAction(g);
        }

        while(a.actionCode != PASS) {
            if(isLegalAction(g, a)) {
                if(a.actionCode == START_SPINOFF) {
                    if(rand() % 3 > 1) {
                        a.actionCode = OBTAIN_IP_PATENT;
                    } else {
                        a.actionCode = OBTAIN_PUBLICATION;
                    }
                }
                makeAction(g, a);
            } else {
                printf("Illegal Action");
            }
            printf("\n");
            printf("Player %d's turn\n", getWhoseTurn(g));

            printf("You have %d ARCs\n", getARCs(g, getWhoseTurn(g)));
            printf("You have %d Campuses\n", getCampuses(g, getWhoseTurn(g)));
            printf("You have %d GO8s\n", getGO8s(g, getWhoseTurn(g)));
            printf("You have %d Publications\n", getPublications(g, getWhoseTurn(g)));
            printf("You have %d IP Patents\n", getIPs(g, getWhoseTurn(g)));
            printf("\n");
            printf("Students:\n");
            printf("You have %d THD Students\n", getStudents(g, getWhoseTurn(g), STUDENT_THD));
            printf("You have %d BPS Students\n", getStudents(g, getWhoseTurn(g), STUDENT_BPS));
            printf("You have %d BQN Students\n", getStudents(g, getWhoseTurn(g), STUDENT_BQN));
            printf("You have %d MJ Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MJ));
            printf("You have %d MTV Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MTV));
            printf("You have %d MMONEY Students\n", getStudents(g, getWhoseTurn(g), STUDENT_MMONEY));
            printf("\n");

            if(automation == FALSE) {
                a = getHumanAction();
            } else {
                a = getAIAction(g);
            }

        }
        printf("Player 1 KPI points : %d\n", getKPIpoints(g, UNI_A));
        printf("Player 2 KPI points : %d\n", getKPIpoints(g, UNI_B));
        printf("Player 3 KPI points : %d\n", getKPIpoints(g, UNI_C));
    }
    printf("Winner: Player %d\n", getWinner(g));    
    disposeGame(g);
    return EXIT_SUCCESS;
}