void evalWith(const GridState * const grid, const GridEvaluation * const originEvaluation, GridEvaluation * const realEvaluation) { GridState tmp; GridEvaluation evaluation; // Evaluate the potential to destroy more flobos // for each flobo except the lower line and the columns top evaluation = nullEvaluation; for (int x = 0; x < IA_FLOBOBAN_DIMX; x++) { int h = columnHeight(x, grid); if (h > realEvaluation->height) realEvaluation->height = h; h = stripedColumnHeight(x, grid); for (int y = 1; y < h-1; y++) { // if free on the left or free on the right if ( ((x > 0) && ((*grid)[x-1][y] == FLOBO_EMPTY)) || ((x < IA_FLOBOBAN_DIMX-1) && ((*grid)[x+1][y] == FLOBO_EMPTY))) { // then try to remove it and see what happens copyGrid(&tmp,grid); tmp[x][y] = FLOBO_EMPTY; columnCompress(x,&tmp); evaluation = nullEvaluation; int r; for (r=0; suppressGroups(&tmp, &evaluation); r++) {}; // if we used more than 1 round more neutrals willbe dropped to the ennemy if (r>1) evaluation.floboSuppressed += (r-1)*FLOBOBAN_DIMX; if (evaluation.floboSuppressed > realEvaluation->floboSuppressedPotential) { realEvaluation->floboSuppressedPotential = evaluation.floboSuppressed; } } } } // count the groups of more than 1 flobo evaluation = nullEvaluation; copyGrid(&tmp,grid); for (int x = 0; x < IA_FLOBOBAN_DIMX; x++) { int h = stripedColumnHeight(x, grid); for (int y = 0; y < h; y++) { if ((tmp[x][y] != FLOBO_EMPTY) && (tmp[x][y] != FLOBO_NEUTRAL)) { countSameFloboAround(x, y, (FloboState)tmp[x][y], &tmp, &evaluation); } } } int d = evaluation.floboSuppressed - originEvaluation->floboSuppressed; if (d>0) realEvaluation->floboGrouped = d; }
void cellularAutomataRound(short **grid, char birthParameters[9], char survivalParameters[9]) { short i, j, nbCount, newX, newY; enum directions dir; short **buffer2; buffer2 = allocGrid(); copyGrid(buffer2, grid); // Make a backup of grid in buffer2, so that each generation is isolated. for(i=0; i<DCOLS; i++) { for(j=0; j<DROWS; j++) { nbCount = 0; for (dir=0; dir< DIRECTION_COUNT; dir++) { newX = i + nbDirs[dir][0]; newY = j + nbDirs[dir][1]; if (coordinatesAreInMap(newX, newY) && buffer2[newX][newY]) { nbCount++; } } if (!buffer2[i][j] && birthParameters[nbCount] == 't') { grid[i][j] = 1; // birth } else if (buffer2[i][j] && survivalParameters[nbCount] == 't') { // survival } else { grid[i][j] = 0; // death } } } freeGrid(buffer2); }
gridNode *copyGridNode(gridNode *toCopy) { gridNode* gn = malloc(sizeof(gridNode)); gn->entry = copyGrid(toCopy->entry); gn->next = toCopy->next; gn->pathTerminus = toCopy->pathTerminus; return gn; }
void MainWindow::solveClicked() { for (int i=0;i<9;++i) for(int j=0;j<9;++j) { if(square[i][j]->text()=="") grid[i][j]='0'; else { int x = QString(square[i][j]->text())[0].unicode(); grid[i][j]=(char)x; } } for (int i=0;i<9;++i) for(int j=0;j<9;++j) if (identical_row(grid, i, j) + identical_collumn(grid, i, j) + identical_block(grid, i, j) != 0) return; for (int i=0;i<9;++i) for(int j=0;j<9;++j) { square[i][j]->setEnabled(false); square[i][j]->setPalette(*blackText); } solveButton->setEnabled(false); char workingArr[9][9]; copyGrid(workingArr); solve(workingArr); setGrid(workingArr); display(); }
bool dropBinom(const FloboBinom binom, const GridState * const src, GridState * const dst, GridEvaluation * const evaluation) { // Copy the matrix if (src != NULL) copyGrid(dst,src); // Drop the Flobos and return false if not possible if (dropFlobos(binom, dst) == false) return false; // Delete all eligible groups while (suppressGroups(dst, evaluation) == true) {}; // return return true; }
void allMeanders(gridNodeStack *solutions, grid *toWalk){ gridNodeStack *toSolve = createGridNodeStack(); //copy toWalk so the original is not freed in this method as part //of the solving loop gridNode *currentNode = createGridNode(copyGrid(toWalk), toWalk->start); int endX = toWalk->end.x-1; while (currentNode) { if (currentNode->pathTerminus.x == endX) { gridNodeStack_push(solutions, currentNode); } else { takeNextSteps(currentNode, toSolve); releaseGrid(currentNode->entry); releaseGridNode(currentNode); } currentNode = gridNodeStack_pop(toSolve); } releaseGridNodeStack(toSolve); }
void XdmfUnstructuredGrid::read() { if (mGridController) { if (shared_ptr<XdmfUnstructuredGrid> grid = shared_dynamic_cast<XdmfUnstructuredGrid>(mGridController->read())) { copyGrid(grid); } else if (shared_ptr<XdmfGrid> grid = shared_dynamic_cast<XdmfGrid>(mGridController->read())) { XdmfError::message(XdmfError::FATAL, "Error: Grid Type Mismatch"); } else { XdmfError::message(XdmfError::FATAL, "Error: Invalid Grid Reference"); } } }
void dropNeutrals(int number, int totalFromStart, GridState * const grid, GridState * const src) { copyGrid(grid, src); while (number > 0) { int cycleNeutral; if (number >= IA_FLOBOBAN_DIMX) cycleNeutral = IA_FLOBOBAN_DIMX; else cycleNeutral = number; for (int i = 0 ; i < cycleNeutral ; i++) { int posX = fallingTable[(totalFromStart++) % IA_FLOBOBAN_DIMX]; int posY = (*grid)[posX][HEIGHTS_ROW]; number--; if (((*grid)[posX][posY] = FLOBO_EMPTY) || (posY >= IA_FLOBOBAN_DIMY)) continue; // Creating a new neutral flobo (*grid)[posX][posY] = FLOBO_NEUTRAL; (*grid)[posX][HEIGHTS_ROW]++; } } }
// ************ Matrix ******************* // Groesse von mret bestimmen !! // Aufruf M = m+3*m2; ?? bool auswert_matrix(BBBaumMatrixPoint& b, GridWerte& mret, double& fret) { if (b.typ == BBBaumInteger::NoOp) throw BBFehlerAusfuehren(); if (!b.isMatrix) // ????? throw BBFehlerAusfuehren(); GridWerte m, m2; double f, f2; bool ret1, ret2; switch(b.typ) { case BBBaumMatrixPoint::BIOperator: switch (b.k.BiOperator.OpTyp) { case BBBaumMatrixPoint::BBKnoten::BBBiOperator::Plus: ret1 = auswert_matrix(*b.k.BiOperator.links, m, f); ret2 = auswert_matrix(*b.k.BiOperator.rechts, m2, f); assert(ret1 && ret2); mret = m; mret.getMem(); if (!(m.xanz == m2.xanz && m.yanz == m2.yanz && mret.xanz == m2.xanz && mret.yanz == m2.yanz )) throw BBFehlerMatrixNotEqual(); { for (int i=0; i<m.yanz; i++) for (int j=0; j<m.xanz; j++) mret.Set_Value(j,i, m(j,i) + m2(j,i)); } return true; case BBBaumMatrixPoint::BBKnoten::BBBiOperator::Minus: ret1 = auswert_matrix(*b.k.BiOperator.links, m, f); ret2= auswert_matrix(*b.k.BiOperator.rechts, m2, f); assert(ret1 && ret2); if (!(m.xanz == m2.xanz && m.yanz == m2.yanz && mret.xanz == m2.xanz && mret.yanz == m2.yanz )) throw BBFehlerMatrixNotEqual(); { for (int i=0; i<m.yanz; i++) for (int j=0; j<m.xanz; j++) mret.Set_Value(j,i, m(j,i) - m2(j,i)); } return true; case BBBaumMatrixPoint::BBKnoten::BBBiOperator::Mal: ret1 = auswert_matrix(*b.k.BiOperator.links, m, f); ret2= auswert_matrix(*b.k.BiOperator.rechts, m2, f2); assert((ret1 && !ret2) || (!ret1 && ret2)); if (ret1) { if (!(mret.xanz == m.xanz && mret.yanz == m.yanz)) throw BBFehlerMatrixNotEqual(); for (int i=0; i<m.yanz; i++) for (int j=0; j<m.xanz; j++) mret.Set_Value(j,i, m(j,i) * f2); } else { if (!(mret.xanz == m2.xanz && mret.yanz == m2.yanz)) throw BBFehlerMatrixNotEqual(); for (int i=0; i<m2.yanz; i++) for (int j=0; j<m2.xanz; j++) mret.Set_Value(j,i, m2(j,i) * f); } return true; case BBBaumMatrixPoint::BBKnoten::BBBiOperator::Geteilt: ret1 = auswert_matrix(*b.k.BiOperator.links, m, f); ret2= auswert_matrix(*b.k.BiOperator.rechts, m2, f2); assert((ret1 && !ret2) || (!ret1 && ret2)); if (ret1) { if (!(mret.xanz == m.xanz && mret.yanz == m.yanz)) throw BBFehlerMatrixNotEqual(); for (int i=0; i<m.yanz; i++) for (int j=0; j<m.xanz; j++) mret.Set_Value(j,i, m(j,i) / f2); } else { if (!(mret.xanz == m2.xanz && mret.yanz == m2.yanz)) throw BBFehlerMatrixNotEqual(); for (int i=0; i<m2.yanz; i++) for (int j=0; j<m2.xanz; j++) mret.Set_Value(j,i, m2(j,i) / f); } return true; } break; case BBBaumMatrixPoint::UniOperator: switch (b.k.UniOperator.OpTyp) { case BBBaumMatrixPoint::BBKnoten::BBUniOperator::Plus: ret1 = auswert_matrix(*b.k.UniOperator.rechts, mret, f); assert(ret1); return true; case BBBaumMatrixPoint::BBKnoten::BBUniOperator::Minus: ret1 = auswert_matrix(*b.k.UniOperator.rechts, mret, f); assert(ret1); { for (int i=0; i<mret.yanz; i++) for (int j=0; j<mret.xanz; j++) mret.Set_Value(j,i, -mret(j,i)); } return true; } break; case BBBaumMatrixPoint::IFAusdruck: fret = auswert_float(*b.k.IntFloatAusdruck.b); return true; // ?????? false; case BBBaumMatrixPoint::MVar: copyGrid(mret, *(b.k.M->M), true); return true; // ???? break; case BBBaumMatrixPoint::PVar: assert(false); return true; } assert(false); return false; }
void display() { /* This function is used to display the content on to the screen... This is not important for the participant... He can skip it */ int gridDup[6][7],moveDup=move,endGameFlagDup,rowNum; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); drawGrid(grid); if(animate) { drawPiece(result,displacement,move); if(stopAnimate(grid,result,displacement)) { animate=0; if(!errorFlag) { rowNum=updateGrid(move,grid,result); // update the grid implying the move has been made drawGrid(grid); if(checkWinOrLose(grid,result,rowNum)) { // check for win condition win=move; // win will contain which bot has won endGameFlag=1; } else if(checkDraw(grid)) { // check for draw condition win=0; // win=0 implies draw endGameFlag=1; } move*=-1; // toggle between plaper 1 and player 2 } } } if(errorFlag) // If error occurs text(displayStr,-1.5,-1.8,font3); if(endGameFlag) { // If game ends if(win>0) // player 1 wins strcpy(displayStr,"Bot 1 wins!!!"); else if(win<0) // player 2 wins strcpy(displayStr,"Bot 2 wins!!!"); else // draw strcpy(displayStr,"Game drawn!!!"); text(displayStr,-1.5,-1.8,font3); printf("\n\n\t%s\n\n\t\tgrid content : \n\n",displayStr); displayStatus(grid); } glFlush(); glutSwapBuffers(); if(animate) displacement+=0.005; if(!endGameFlag && !errorFlag && !animate) { copyGrid(grid,gridDup); moveDup=move; endGameFlagDup=endGameFlag; if(move>0) result=bot1(grid,move); else result=bot2(grid,move); if(!(equalGrid(grid,gridDup) && move==moveDup && endGameFlagDup==endGameFlag)) { // grid() and move variables should not be changed sprintf(displayStr,"Bot %d error : Grid or move is modified!!!",move); errorFlag=1; } checkForErrors(result,move,grid); // errors like result should be within the 0 to 6 range, etc... animate=1; displacement=0; } }