/********************************************************************* Makes a "beginner" level gameboard which is 10 x 10 and has 10 mines. It starts out with all tiles marked as "covered" ************************************************************************/ void Minesweeper::Beginner() { setBoardSize(10, 10); int mines = 0; while (mines < 10) { /******************************************************************* Loops through the array and places either a mine or an empty cell based on output from RNG ********************************************************************/ for (int r = 0; r < 10; ++r) { for (int c = 0; c < 10; ++c) { for (int idx = 0; idx < r*c; ++idx) { if ((1 + (rand() % 10)) == 1) { setBoard(getMine()); } else { setBoard(getBlank()); } } } } } }
int main(int argc, char const *argv[]) { int x,y,m,i,count=0; srand(time(NULL)); while(count!=7){ clear(); setBoard(rand()%8,rand()%8); count=0; while(counter()!=0){ // print(); access(); m=min(); setBoard(m/10,m%10); // printf("\n"); count++; } } print(); printf("\n"); // for(x=0;x<8;x++){ // for(y=0;y<8;y++){ // printf("%d\t",accessibility[x][y]); // } // printf("\n"); // } // printf("%d",min()); return 0; }
void BoardSetupDialog::swapColors() { QString fen = board().toFen(); QString fenRows = fen.left(fen.indexOf(" ")); QStringList rows = fenRows.split("/"); for(QStringList::Iterator iter = rows.begin(); iter != rows.end(); ++iter) { QString& fenString = (*iter); for(QString::Iterator pChar = fenString.begin(); pChar != fenString.end(); ++pChar) { if(*pChar >= 'a' && *pChar <= 'z') { (*pChar) = (*pChar).toUpper(); } else if(*pChar >= 'A' && *pChar <= 'Z') { (*pChar) = (*pChar).toLower(); } } } QString newFen = rows.join("/"); Board b(newFen); b.setMoveNumber(board().moveNumber()); b.setHalfMoveClock(board().halfMoveClock()); setBoard(b); }
void BoardSetupDialog::slotCopyPiece(Square from, Square to) { Board b = ui.boardView->board(); Piece p = b.pieceAt(from); b.setAt(to, p); setBoard(b); }
void BoardSetupDialog::slotPasteFen() { // Prepare Fen - clean up code like this: // [FEN "***"] to *** QString fen = QApplication::clipboard()->text().simplified(); if(fen.contains("\"")) { int n1 = fen.indexOf('"'); int n2 = fen.lastIndexOf('"'); if(n2 > n1 + 1) { fen = fen.mid(n1 + 1, n2 - n1 - 1); } } // Another go at Fens copied from Wikis: [FEN]***[/FEN] is reduced to *** fen.remove(QRegExp("\\[[^\\]]*\\]")); // Now parse the hopefully naked Fen Board b; if(!b.fromFen(fen)) { QString msg = fen.length() ? tr("Text in clipboard does not represent valid FEN:<br><i>%1</i>").arg(fen) : tr("There is no text in clipboard."); MessageDialog::warning(msg); } else { setBoard(b); } }
void testDoubling() { printf("\n\nTEST ACCETTAZIONE DOUBLE...\n"); int b[2][25] = { {2, 2, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},//ALL BEARED OFF {0, 3, 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0},//ALL BEARED OFF //{2, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0} }; ms.anScore[0] = 0; ms.anScore[1] = 0; ms.nMatchTo = 7; ms.fMove = 0; ms.fTurn = 1; ms.fCubeOwner = -1; setBoard((ConstTanBoard)b); printBoard(msBoard()); printf("ACCETTAZIONE: %s\n\n", acceptDouble()?"OK":"NO"); ms.fMove = 1; ms.fTurn = 0; ms.fCubeOwner = -1; SwapSides(ms.anBoard); printBoard(msBoard()); printf("ACCETTAZIONE: %s\n", acceptDouble()?"OK":"NO"); }
void BoardSetupDialog::slotClear() { Board b; b.setAt(e1, WhiteKing); b.setAt(e8, BlackKing); setBoard(b); }
void BoardSetupDialog::slotToggleSide() { m_toMove = oppositeColor(m_toMove); Board b = ui.boardView->board(); b.setToMove(m_toMove); setBoard(b); }
void testMoveGen() { puts("Some hard positions for the moves generator."); puts(""); puts(" A worthy test position by Albert Bertilsson for a *true* move generator \n testing!");//Belka: Albert Bertilsson's test position puts(" 8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - - \n"); puts(" Running Perft the following nodes are true: "); puts(" depth=1, nodes= 14"); puts(" depth=2, nodes= 191"); puts(" depth=3, nodes= 2,812"); puts(" depth=4, nodes= 43,238"); puts(" depth=5, nodes= 674,624"); puts(" depth=6, nodes= 11,030,083"); puts(" depth=7, nodes=178,633,661 \n"); setBoard("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -"); hdp = 0; fifty = 0; hashKeyPosition(); /* hash of the initial position */ int i; for (i=1; i<7; ++i) printf("Perft %d: %d\n", i, perft(i)); puts(""); puts(" The famous test position by Peter McKenzie for a *true* move generator testing!");//Belka: Albert Bertilsson's test position puts(" r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - \n"); puts(" Running Perft the following nodes are true: "); puts(" depth=1, nodes= 48"); puts(" depth=2, nodes= 2,039"); puts(" depth=3, nodes= 97,862"); puts(" depth=4, nodes= 4,085,603"); puts(" depth=5, nodes= 193,690,690"); puts(" depth=6, nodes=8,031,647,685"); setBoard("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R wKQkq -"); hdp = 0; fifty = 0; hashKeyPosition(); /* hash of the initial position */ for (i=1; i<7; ++i) printf("Perft %d: %d\n", i, perft(i)); }
/** @param type The type - either HOST or CLIENT. @note Host is white and client black. @note The host start (white starts). */ void OnlinePlayer::init(PeerType type) { if(type == HOST) { setBoard(new Board(80, false)); mWaitingForOpponent = true; mWaitingOnMove = false; setColor(WHITE); mGui->setStatus("Waiting for opponent!", RED, 300.0f); } else if(type == CLIENT) { setBoard(new Board(80, true)); mWaitingForOpponent = false; mWaitingOnMove = true; setColor(BLACK); } }
UnplacedComponentsDock::~UnplacedComponentsDock() { setBoard(nullptr); mDisableListUpdate = true; disconnect(mCircuitConnection1); mCircuitConnection1 = QMetaObject::Connection(); disconnect(mCircuitConnection2); mCircuitConnection2 = QMetaObject::Connection(); delete mFootprintPreviewGraphicsView; mFootprintPreviewGraphicsView = nullptr; delete mFootprintPreviewGraphicsScene; mFootprintPreviewGraphicsScene = nullptr; delete mUi; mUi = nullptr; }
//core void Clear(){ int i,j; for(i=0;i<10;i++) { for(j=0;j<20;j++) { setBoard(i,j,0); } } }
void BoardSetupDialog::slotInvalidMove(Square from) { Board b = ui.boardView->board(); Piece p = b.pieceAt(from); if(pieceType(p) != King) { b.removeFrom(from); setBoard(b); } }
void countNodes() { puts("Evals a series of positions and count the number of nodes."); puts("The idea is to make a check when changes in the search are made (vg move ordering)"); int depth = 6; int allNodes = 0; setBoard("1kr5/3n4/q3p2p/p2n2p1/PppB1P2/5BP1/1P2Q2P/3R2K1 w - -"); ComputerThink(depth); allNodes += nodes; setBoard("1n5k/3q3p/pp1p2pB/5r2/1PP1Qp2/P6P/6P1/2R3K1 w - -"); ComputerThink(depth); allNodes += nodes; setBoard("1n6/4bk1r/1p2rp2/pP2pN1p/K1P1N2P/8/P5R1/3R4 w - -"); ComputerThink(depth); allNodes += nodes; setBoard("1nr5/1k5r/p3pqp1/3p4/1P1P1PP1/R4N2/3Q1PK1/R7 w - -"); ComputerThink(depth); allNodes += nodes; setBoard("1q4k1/5p1p/p1rprnp1/3R4/N1P1P3/1P6/P5PP/3Q1R1K w - -"); ComputerThink(depth); allNodes += nodes; setBoard("1qr1k2r/1p2bp2/pBn1p3/P2pPbpp/5P2/2P1QBPP/1P1N3R/R4K2 b k -"); ComputerThink(depth); allNodes += nodes; setBoard("1r1b2k1/2r2ppp/p1qp4/3R1NPP/1pn1PQB1/8/PPP3R1/1K6 w - -"); ComputerThink(depth); allNodes += nodes; setBoard("1r1r2k1/p3n2p/b1nqpbp1/2pp4/1p3PP1/2PP1N2/PPN3BP/R1BRQ2K w - -"); ComputerThink(depth); allNodes += nodes; setBoard("1r2n1rk/pP2q2p/P2p4/4pQ2/2P2p2/5B1P/3R1P1K/3R4 w - -"); ComputerThink(depth); allNodes += nodes; setBoard("r1bq1rk1/pp3pbp/3Pp1p1/2p5/4PP2/2P5/P2QB1PP/1RB1K2R b K -"); ComputerThink(depth); allNodes += nodes; printf ("Total nodes = %d\n", allNodes); }
void BoardSetupDialog::mirrorVertical() { QString fen = board().toFen(); QString fenRows = fen.left(fen.indexOf(" ")); QStringList rows = fenRows.split("/"); QAlgorithmsPrivate::qReverse(rows.begin(), rows.end()); QString newFen = rows.join("/"); Board b(newFen); b.setMoveNumber(board().moveNumber()); b.setHalfMoveClock(board().halfMoveClock()); setBoard(b); }
void BoardSetupDialog::slotEnPassantSquare() { Board b(board()); if(ui.epCombo->currentIndex() == 0) { b.clearEnPassantSquare(); } else { int shift = b.toMove() == White ? 39 : 15; b.setEnPassantSquare(shift + ui.epCombo->currentIndex()); } setBoard(b); }
void BoardSetupDialog::mirrorHorizontal() { QString fen = board().toFen(); QString fenRows = fen.left(fen.indexOf(" ")); QStringList rows = fenRows.split("/"); for(QStringList::Iterator iter = rows.begin(); iter != rows.end(); ++iter) { QAlgorithmsPrivate::qReverse((*iter).begin(), (*iter).end()); } QString newFen = rows.join("/"); Board b(newFen); b.setMoveNumber(board().moveNumber()); b.setHalfMoveClock(board().halfMoveClock()); setBoard(b); }
void testPlayTurn() { int b[2][25] = { //MEGLIO NON RADDOPPIARE //{0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, //{0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //PC //RICHIESTA DI RADDOPPIO SU 0 A 0 //{1, 1, 2, 2, 2, 2, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0}, //{0, 2, 2, 3, 0, 3, 2, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} //PC //RACE GAME.. //{0, 0, 0, 0, 2, 5, 2, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0}, //{0, 0, 0, 2, 0, 4, 2, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0} //PC {0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0},//BLACK (HUMAN) BGV {0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0}//WHITE (PC) }; setBoard((ConstTanBoard)b); ms.nCube = 1; ms.fCubeOwner = 1; ms.fMove = 1; ms.fTurn = 1; ms.anScore[0] = 0; ms.anScore[1] = 0; ms.nMatchTo = 1; ms.fCrawford = FALSE; printf("\n\nTEST TURNO IA...\n"); printBoard((ConstTanBoard)b); //printf("RESIGN: %d\n", askForResignation()); //printf("DOUBLING: %s\n", askForDoubling()?"YES":"NO"); int dices[2] = {6, 4}; int move[8]; //rollDice(dices); printDices(dices); evaluateBestMove(dices, move); printMove(move); printf("AIlevel: %d\n\n", currentAILevel); }
void testResignation() { int b[2][25] = { {2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15} }; setBoard((ConstTanBoard)b); ms.fMove = 1; ms.fTurn = 0; ms.nCube = -1; ms.fCubeOwner = 1; ms.anScore[0] = 0; ms.anScore[1] = 0; ms.nMatchTo = 7; printf("\n\nTEST ACCETTAZIONE RESIGN...\n"); printBoard(msBoard()); printf("RESIGN 1: %s\n", acceptResign(1)?"OK":"NO"); printf("RESIGN 2: %s\n", acceptResign(2)?"OK":"NO"); printf("RESIGN 3: %s\n", acceptResign(3)?"OK":"NO"); printf("AIlevel: %d\n\n", currentAILevel); }
void BoardSetupDialog::slotSelected(Square square, int button) { Piece piece = (button & Qt::MidButton) ? Empty : m_selectedPiece; if(button & Qt::RightButton) { if(piece >= BlackKing) { piece = (Piece)(piece - (BlackKing - WhiteKing)); } else if(piece != Empty) { piece = (Piece)(piece + (BlackKing - WhiteKing)); } } Board board = ui.boardView->board(); if(board.pieceAt(square) == piece) { piece = Empty; } board.setAt(square, piece); setBoard(board); }
void BoardSetupDialog::slotCastlingRights() { Board b(board()); CastlingRights cr = 0; if(ui.wkCastleCheck->isChecked()) // && b.pieceAt(4) == WhiteKing && b.pieceAt(7) == WhiteRook) { cr += WhiteKingside; } if(ui.wqCastleCheck->isChecked()) // && b.pieceAt(4) == WhiteKing && b.pieceAt(0) == WhiteRook) { cr += WhiteQueenside; } if(ui.bkCastleCheck->isChecked()) // && b.pieceAt(60) == BlackKing && b.pieceAt(63) == BlackRook) { cr += BlackKingside; } if(ui.bqCastleCheck->isChecked()) // && b.pieceAt(60) == BlackKing && b.pieceAt(56) == BlackRook) { cr += BlackQueenside; } b.setCastlingRights(cr); setBoard(b); }
void BogglePlayer::getCustomBoard(string** &board, unsigned int *rows, unsigned int *cols) { // Set rows and columns *rows = 4; *cols = 4; unsigned int r = *rows; unsigned int c = *cols; // Allocate board board = new string*[r]; for (size_t i=0;i<r;i++) board[i] = new string[c]; // Initialize values here board[0][0] = "s"; board[0][1] = "t"; board[0][2] = "h"; board[0][3] = "r"; board[1][0] = "qu"; board[1][1] = "a"; board[1][2] = "v"; board[1][3] = "i"; board[2][0] = "a"; board[2][1] = "t"; board[2][2] = "d"; board[2][3] = "j"; board[3][0] = "u"; board[3][1] = "l"; board[3][2] = "t"; board[3][3] = "r"; setBoard(r, c, board); }
int main(int argc, char* argv[]) { // set up board PositionType board[BoardSize][BoardSize]; int numberOfBombs = atoi(argv[1]); setBoard(board, numberOfBombs); // game loop int gameState, row, column; do { // ask for guess printf("Your move?: \n"); scanf("%d %d", &row, &column); printf("\n"); // process move gameState = processGuess(board, row - 1, column - 1); if (gameState == -1) { printf("Invalid move!\n\n"); } else if (gameState == 0) { printf("You've already played there!\n\n"); } // show the board displayBoard(board); printf("\n"); } while (gameState != 2 && hasWon(board) == 0); // game over, check for win or lose if (gameState != 2) { printf("YOU WIN!\n\n"); } else { printf("YOU LOSE!\n\n"); } return 0; }
Game::Game(Board *board, QObject *parent) : QObject(parent), m_board(NULL), m_boardGenerationThread(NULL), m_boardGeneratorWrapper(NULL), m_hintGenerationThread(NULL), m_hintGenerator(NULL), m_currentColorIndex(0), m_boardGenerationRunning(false), m_publicGame(false) { setBoard(board); }
int main(int argc, char* argv[]){ if(argc==1){ printf("Incorrect number of command line arguments\n"); printf("Correct usage: ./a.out <number of bombs>\n"); return -1; } PositionType board[BoardSize][BoardSize]; int numberOfBomb=atoi(argv[1]); int totalNumberOfSafePlace=BoardSize*BoardSize-numberOfBomb; setBoard(board,numberOfBomb); displayBoard(board); printf("Game begins, there are total %d grids, and there are %d bombs there, %d total safe grids.\n", BoardSize*BoardSize, numberOfBomb, totalNumberOfSafePlace); int row; int col; printf("Enter a row and col:\n"); scanf("%d %d",&row,&col); int result; while(1){ result=processGuess( board, row , col ); switch(result){ case -1: printf("Invalid position.\n"); break; case 0: printf("That position has already been picked.\n"); break; case 1: totalNumberOfSafePlace--; break; case 2: printf("Game over, you lose\n"); displayBoard(board); return -1; } displayBoard(board); if(totalNumberOfSafePlace==0){ break; } printf("Total Number Of Safe Place Left: %d\n",totalNumberOfSafePlace); printf("Enter a row and col:\n"); scanf("%d %d",&row,&col); } printf("You win!\n"); return 0; }
/*function the present the page- SETTING MENU- and handle the events releated to him*/ int SettingMenu(SDL_Surface* screen, int isLoaded){ int x, y; int move_next_page = FALSE; SDL_Surface* Setting_Menu = NULL; SDL_Event event; Setting_Menu = SDL_LoadBMP("Images/settingsmenu.bmp"); if (Setting_Menu == NULL) return 1; apply_surface(0, 0, Setting_Menu, screen); drawArrows(screen, SET_SETTINGS); // the function draw arrows on the chosen options SDL_Flip(screen); while (quit == FALSE && move_next_page == FALSE){ if (SDL_PollEvent(&event)){ if (event.type == SDL_MOUSEBUTTONUP){ //Get the mouse offsets x = event.button.x; y = event.button.y; //If the mouse is over the button: //gameMode if ((x > 52) && (x < 52 + 155) && (y > 212) && (y < 212 + 70)){ game_mode = 1; } if ((x > 52) && (x < 52 + 155) && (y > 332) && (y < 332 + 70)){ game_mode = 2; } //cancel if ((x > 52) && (x < 52 + 155) && (y > 501) && (y < 501 + 70)){ return FALSE;// return to previous page- but dont exit the program! } //to setTheBoard if (isLoaded == 0 && (x > 318) && (x < 318 + 155) && (y > 379) && (y < 379 + 70)){ if (setBoard(screen)){ quit = TRUE; break; } } //color if ((x > 579) && (x < 579 + 155) && (y > 212) && (y < 212 + 70)){ nextPlayer = WHITE; } if ((x > 579) && (x < 579 + 155) && (y > 332) && (y < 332 + 70)){ nextPlayer = BLACK; } //next if ((x > 581) && (x < 581 + 155) && (y > 501) && (y < 501 + 70)){ if (game_mode == 2){ if (AISettings(screen)){ quit = TRUE; break; } } if (game_mode == 1){ if (GamePlay(screen, fileName)){ quit = TRUE; break; } } } apply_surface(0, 0, Setting_Menu, screen); drawArrows(screen, SET_SETTINGS); //the user clicked- maybe somthings changed- need to update the arrows SDL_Flip(screen); //update screen } //If the user has Xed out the window if (event.type == SDL_QUIT){ quit = TRUE; break; } } } //Free the loaded image SDL_FreeSurface(Setting_Menu); return quit; }
void BoardSetupDialog::slotReset() { Board b; b.setStandardPosition(); setBoard(b); }
void BoardSetupDialog::slotDroppedPiece(Square s, Piece p) { Board b = ui.boardView->board(); b.setAt(s, p); setBoard(b); }
void BoardSetupDialog::slotHalfmoveClock() { Board b(board()); b.setHalfMoveClock(ui.halfmoveSpin->value()); setBoard(b); }
void BoardSetupDialog::slotMoveNumber() { Board b(board()); b.setMoveNumber(ui.moveSpin->value()); setBoard(b); }