void mvZeroNextToTarget(searchData *d,int placeTarget) { int placeZero = searchChar(&d->b, '0'); int xd = (placeTarget % d->b.w) - (placeZero % d->b.w); int yd = (int)(placeTarget / d->b.w) - (int)(placeZero / d->b.w); char ways[4]; int len; while(abs(xd) + abs(yd) > 0){ len = nextMove(d->b, ways, d->preMove); char next; if(len == 1) next = ways[0]; else next = chooseNext(ways, xd, yd, searchChar); move(&d->b, next); d->preMove = next; d->r.push_back(next); repairXdXy(next, &xd, &yd); #ifdef DEBUG printf("ways=%s\n", ways); printBoard(d->b); getchar(); #endif } }
int main() { //initialize and clear 7-Segment Display (assembly subroutine) setup_sequence(); seg_driver_initialize(); seg_driver(0); //check for wav file lcd.cls(); lcd.printf("Locating WAV file..."); FILE *test_file; while(1) { test_file=fopen(BOMB_WAVFILE,"r"); if(test_file != NULL) { lcd.printf("File not found"); break; } wait(0.5); } fclose(test_file); lcd.cls(); //notification lcd.cls(); lcd.printf("Battleship"); wait(1); while(1) { //synchronize front end display startGame(); print("Lets play!"); //Re-Init board for(int i = 0; i<10; i++) { for(int j = 0; j<10; j++) { board[i][j] = -2; } } //Re-Init gloabls int shipsizes[] = {2, 3, 3, 4, 5}; aliveSize[0] = 2; aliveSize[1] = 3; aliveSize[2] = 3; aliveSize[3] = 4; aliveSize[4] = 5; sunkenShips = 0; //# of sunken ships numBombs = 0; int shotResult = -1; while(sunkenShips<5) { //Calculate board probability probality(); //bomb best move chooseNext(); //print("Hitting Row: %d, Col: %d", max_row, max_col); shotResult = placeBomb(max_row, max_col); //print("Result: %d", shotResult); //Got a hit, sink the bastard if(shotResult == HIT) { sinkIt(max_row, max_col); } }//Finished game! lcd.cls(); lcd.printf("GAME OVER!"); } }