int main (int argc, char * argv[]) { int a1[4] = {1,2,3,BLANK}; int a2[4] = {1,2,BLANK,3}; Board b1 = makeBoard (a1, 2); Board b2 = makeBoard (a2, 2); State s1 = makeState (b1, NO_PARENT, 23, 42); State s2 = makeState (b2, s1, 24, 50); PTree p = newPTree (4); assert (inPTree (p, b1) == NULL); addToPTree (p, s1); assert (inPTree (p, b1) == s1); assert (inPTree (p, b2) == NULL); addToPTree (p, s2); assert (inPTree (p, b2) == s2); disposePTree (p); printf ("PTree ADT passed all tests\n"); return EXIT_SUCCESS; }
void disorderTest (void) { int contentsA[9] = {1,2,3,4,5,6,7,8,BLANK}; Board a = makeBoard (contentsA, 3); assert (disorder (a) == 0); int contentsB[9] = {BLANK,8,7,6,5,4,3,2,1}; Board b = makeBoard (contentsB, 3); assert (disorder (b) == 28); int contentsC[9] = {1,8,2,7,BLANK,3,6,4,5}; Board c = makeBoard (contentsC, 3); assert (disorder (c) == 12); int contentsD[9] = {1,2,3,4,5,6,7,8,BLANK}; Board d = makeBoard (contentsD, 3); int contentsE[9] = {1,2,3,4,5,6,7,BLANK,8}; Board e = makeBoard (contentsE, 3); assert (disorder (d) % 2 == disorder (e) % 2); disposeBoard (a); disposeBoard (b); disposeBoard (c); disposeBoard (d); disposeBoard (e); }
void compareTest (void) { int contentsA[] = {1,2,3,4}; Board a = makeBoard (contentsA, 2); int contentsB[] = {1,2,3,4}; Board b = makeBoard (contentsB, 2); int contentsC[] = {1,2,4,3}; Board c = makeBoard (contentsC, 2); assert (compareBoards (a, b) == TRUE); assert (compareBoards (a, c) == FALSE); }
int rate(Group animalsOnBoard, Move move, Group enemyHand){ // Score a Move Board board = makeBoard(&animalsOnBoard,move); // Get Tile info from Group and Move int i; for(i=0; i<animalsOnBoard.num; i++){ applyReach(animalsOnBoard.animal[i], &board); // apply list of animals that can reach the tile } int score = getScore(board); score -= placePenalty(move); score += effectRange(board); score += catchLion(board); score += touchDown(board); score += placeDanger(board,enemyHand); score += lionPosition(animalsOnBoard); // Score is (board score) + (placement penalty) // + (moveable range) + (did we catched lion?) + (did lion get touchdown?) int x,y; for(y=0; y<4; y++){ for(x=0; x<3; x++){ printf("%c",board.tile[x][y].occupied); } printf("\n"); } printf("place : %d\nlion : %d\ntotal : %d\n",placeDanger(board,enemyHand),lionPosition(animalsOnBoard),score); return score; }
int main(int argc, char ** argv) { if (argc != 4) { fprintf(stderr,"Usage: minesweeper width height numMines\n"); return EXIT_FAILURE; } int width = atoi(argv[1]); int height = atoi(argv[2]); int numMines = atoi(argv[3]); if (width <= 0 || height <= 0 || numMines <= 0) { fprintf(stderr, "Width, height, and numMines must all be positive ints\n"); return EXIT_FAILURE; } char * line = NULL; size_t linesz = 0; do { board_t * b = makeBoard (width, height, numMines); int gameOver = 0; while (!gameOver) { gameOver = playTurn(b, &line, &linesz); } freeBoard(b); do { printf("Do you want to play again?\n"); } while(getline(&line, &linesz, stdin) == -1); } while(line[0] == 'Y' || line[0] == 'y'); free(line); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { // Variable declarations int count = 1; int rows,cols,iters,numCoords,x,y,neighbors; FILE *inFile = openFile(argv[1]); struct timeval start, end; char *newBoard = NULL; char *refBoard = NULL; char *temp; // Threading variables // Process command line arguments verifyCmdArgs(argc, argv); // Open test parameter file and read in first 4 lines fscanf(inFile, "%d %d %d %d", &rows, &cols, &iters, &numCoords); // Create game board initialized to starting state newBoard = makeBoard(rows,cols,inFile,numCoords); refBoard = copyBoard(newBoard,rows,cols); print(refBoard,atoi(argv[2]),rows,cols,0); //printf("refBoard2: %s\n", refBoard); // Apply the life and death conditions to the board /*gettimeofday(&start, NULL); while (count < iters+1) { evolve(x,y,rows,cols,newBoard,refBoard,argv,numCoords,count); *temp = *refBoard; *refBoard = *newBoard; // reference board updated to be the newer board *newBoard = *temp;*/ // Very helpful visuals for showing which versions of the board // are being stored in our three char *'s /*printf("temBoard: %s\n", temp); printf("refBoard: %s\n", refBoard); printf("newBoard: %s\n", newBoard);* s/ temp = copyBoard(newBoard,rows,cols); refBoard = temp; // reference board updated to be the newer board //newBoard = temp; ++count; } gettimeofday(&end, NULL); */ // Time calculations long elapsed = (end.tv_sec-start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec); printf("\nElapsed time for %d steps of a %d x %d board is: %f seconds\n", iters, rows, cols, elapsed/1000000.); free(newBoard); free(refBoard); fclose(inFile); refBoard = NULL; newBoard = NULL; temp = NULL; return 0; }
int main(int argc, char** argv) { char board[26][26]; int n; int numberOfMoves = 0; int *moves = &numberOfMoves; char computerColour, currentColour; printf("Enter the board dimension: "); scanf("%d", &n); makeBoard(board, n); printf("Computer plays (B/W) : "); scanf(" %c", &computerColour); currentColour = 'B'; char nextColour = 'W'; char tempColour; bool gameOver = 0; char rowMove, colMove; printBoard(board, n); while(!gameOver){ if(movesAvailable(board, n, currentColour)){ if(currentColour == computerColour){ decideMove(board, n, computerColour, moves); numberOfMoves++; } else{ printf("Enter move for colour %c (RowCol): ", currentColour); scanf(" %c%c", &rowMove, &colMove); if(checkLegalInPosition(board, n, rowMove - 'a', colMove - 'a', currentColour)){ makeMove(board, n, rowMove - 'a', colMove - 'a', currentColour); numberOfMoves++; } else{ printf("Invalid move.\n"); printf("%c player wins.\n", findWinner(board, n)); return 0; } } printBoard(board, n); } else{ printf("%c player has no valid move.\n", currentColour); } tempColour = currentColour; currentColour = nextColour; nextColour = tempColour; if(!movesAvailable(board, n, 'B') && !movesAvailable(board, n, 'W')){ printf("%c player wins.\n", findWinner(board, n)); gameOver = true; } } return (EXIT_SUCCESS); }
GameBoard::GameBoard(Shapes *shapes, int screenHeight) { this->shapes = shapes; this->screenHeight = screenHeight; makeBoard(); }
void gameInit() { sramWrite(keepScore, 0); sramWrite(counter, 0); makeBoard(); alt_putstr("Welcome to Battleship!\n"); }
void outOfPlaceCostTest (void) { int contentsA[9] = {1,1,1,1,1,1,1,1,1}; Board a = makeBoard (contentsA, 3); int contentsB[9] = {9,9,9,9,9,9,9,9,9}; Board b = makeBoard (contentsB, 3); int contentsC[9] = {1,2,1,2,1,2,1,2,1}; Board c = makeBoard (contentsC, 3); assert (outOfPlaceCost (a, b) == 9); assert (outOfPlaceCost (a, c) == 4); disposeBoard (a); disposeBoard (b); disposeBoard (c); }
int main() { while ( gets(buf) ) { makeBoard(); attack(); //printBoard(); printf("%d\n", countSquares()); } }
void manhattanCostTest (void) { int contentsI[4] = {1,2,3,BLANK}; Board i = makeBoard (contentsI, 2); int contentsJ[4] = {1,2,BLANK,3}; Board j = makeBoard (contentsJ, 2); assert (manhattanCost (i, j) == 1); int contentsK[4] = {BLANK,1,2,3}; Board k = makeBoard (contentsK, 2); assert (manhattanCost (i, k) == 4); disposeBoard (i); disposeBoard (j); disposeBoard (k); }
static SCENEGRAPH* loadIDFBoard( const wxString& aFileName ) { LOCALESWITCH switcher; IDF3_BOARD brd( IDF3::CAD_ELEC ); // note: if the IDF model is defective no outline substitutes shall be made if( !brd.ReadFile( aFileName, true ) ) { #ifdef DEBUG do { std::ostringstream ostr; std::cerr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; std::cerr << " * [INFO] Failed to read IDF file:\n"; std::cerr << brd.GetError() << "\n\n"; std::cerr << " * [INFO] IDF file '" << aFileName.ToUTF8() << "'"; wxLogTrace( MASK_IDF, "%s\n", ostr.str().c_str() ); } while( 0 ); #endif return NULL; } IFSG_TRANSFORM tx0( true ); SGNODE* topNode = tx0.GetRawPtr(); bool noBoard = false; bool noComp = false; bool noOther = false; if( NULL == makeBoard( brd, topNode ) ) noBoard = true; if( !makeComponents( brd, topNode ) ) noComp = true; if( !makeOtherOutlines( brd, topNode ) ) noOther = true; if( noBoard && noComp && noOther ) { tx0.Destroy(); return NULL; } return (SCENEGRAPH*) topNode; }
int main (int argc, char * argv[]) { int contentsT[9] = {1,2,3,4,5,6,7,8,BLANK}; Board t = makeBoard (contentsT, 3); disposeBoard (t); compareTest(); outOfPlaceCostTest(); manhattanCostTest(); disorderTest(); printf ("Board ADT passed all tests\n"); return EXIT_SUCCESS; }