int main(int argc, char **argv) { int id1, id2, errs=0; if (argc < 3) { fprintf(stderr, "Usage: %s Place1 Place2\n", argv[0]); exit(1); } // convert args to place IDs id1 = (strlen(argv[1]) == 2) ? abbrevToID(argv[1]) : nameToID(argv[1]); id2 = (strlen(argv[1]) == 2) ? abbrevToID(argv[2]) : nameToID(argv[2]); // check place validity if (id1 == NOWHERE) { errs++; fprintf(stderr, "Invalid place name: %s\n", argv[1]); } if (id2 == NOWHERE) { errs++; fprintf(stderr, "Invalid place name: %s\n", argv[2]); } if (errs > 0) exit(1); Map europe; europe = newMap(); // find shortest path int i, n; LocationID path[NUM_MAP_LOCATIONS]; TransportID trans[NUM_MAP_LOCATIONS]; printf("Starting from %s ...\n", idToName(id1)); n = shortestPath(europe, id1, id2, path, trans); if (n == 0) printf("you cannot reach %s\n", idToName(id2)); else { for (i = 1; i < n; i++) { if (i > 1 && n > 2) printf("then "); printf("go to %s by ", idToName(path[i])); switch (trans[i]) { case ROAD: printf("road\n"); break; case RAIL: printf("rail\n"); break; case BOAT: printf("boat\n"); break; default: printf("????\n"); break; } } printf("You have reached your destination\n"); } //DEBUG printf("start is: %d; end is: %d\n", id1, id2); printf("path[0] is: %d; path[1] is: %d\n", path[0], path[1]); return 0; }
int main(int argc, char **argv) { int id1, id2, errs=0; if (argc < 3) { fprintf(stderr, "Usage: %s Place1 Place2\n", argv[0]); exit(1); } // convert args to place IDs id1 = (strlen(argv[1]) == 2) ? abbrevToID(argv[1]) : nameToID(argv[1]); id2 = (strlen(argv[1]) == 2) ? abbrevToID(argv[2]) : nameToID(argv[2]); // check place validity if (id1 == NOWHERE) { errs++; fprintf(stderr, "Invalid place name: %s\n", argv[1]); } if (id2 == NOWHERE) { errs++; fprintf(stderr, "Invalid place name: %s\n", argv[2]); } if (errs > 0) exit(1); Map europe; europe = newMap(); // check for direct connection Transport t[NUM_TRANSPORT]; int i, n; printf("Between %s and %s ...\n", idToName(id1), idToName(id2)); n = connections(europe, id1, id2, t); if (n == 0) printf("No direct connection\n"); else { for (i = 0; i < n; i++) { switch (t[i]) { case ROAD: printf("Road connection\n"); break; case RAIL: printf("Rail connection\n"); break; case BOAT: printf("Boat connection\n"); break; default: printf("Weird connection\n"); break; } } } return 0; }
int main(void) { NumericsOptions NO; setDefaultNumericsOptions(&NO); NO.verboseMode = 1; // turn verbose mode to off by default int total_info = 0; double q[] = { -1, 1, 3, -1, 1, 3, -1, 1, 3}; double mu[] = {0.1, 0.1, 0.1}; double Wdata[81] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; NumericsMatrix* tmpM = createNumericsMatrixFromData(NM_DENSE, 9, 9, Wdata); NumericsMatrix* W = createNumericsMatrix(NM_SPARSE, 9, 9); NM_copy_to_sparse(tmpM, W); int solvers_to_test[] = {SICONOS_FRICTION_3D_NSGS, SICONOS_FRICTION_3D_NSN_AC, SICONOS_FRICTION_3D_NSN_FB, SICONOS_FRICTION_3D_NSN_NM, SICONOS_FRICTION_3D_SOCLCP, SICONOS_FRICTION_3D_PROX}; for (size_t s = 0; s < sizeof(solvers_to_test); ++s) { int solver_id = solvers_to_test[s]; FrictionContactProblem* FC = frictionContactProblem_new(3, 3, W, q, mu); double r[9] = {0.}; double u[9] = {0.}; SolverOptions SO;; fc3d_setDefaultSolverOptions(&SO, solver_id); int info = fc3d_driver(FC, r, u, &SO, &NO); if (info) { fprintf(stderr, "Solver %s failed with error %d\n", idToName(solver_id), info); total_info = 1; } FC->M = NULL; FC->q = NULL; FC->mu = NULL; deleteSolverOptions(&SO); freeFrictionContactProblem(FC); free(FC); } freeNumericsMatrix(W); tmpM->matrix0 = NULL; freeNumericsMatrix(tmpM); free(W); free(tmpM); return total_info; }
// Display content of Map/Graph void showMap(Map g) { assert(g != NULL); printf("V=%d, E=%d\n", g->nV, g->nE); int i; for (i = 0; i < g->nV; i++) { VList n = g->connections[i]; while (n != NULL) { printf("%s connects to %s ",idToName(i),idToName(n->v)); switch (n->type) { case ROAD: printf("by road\n"); break; case RAIL: printf("by rail\n"); break; case BOAT: printf("by boat\n"); break; default: printf("by ????\n"); break; } n = n->next; } } }
LocationID *connectedLocations(GameView currentView, int *numLocations, LocationID from, PlayerID player, Round round, int road, int rail, int sea) { // use map in gameview if(player != PLAYER_DRACULA) { printf("Player is %d, road is %d, rail is %d, sea is %d\n", player, road, rail, sea); printf("Start location is %d\n", from); printf("Start location is %s\n", idToName(from)); } // pass it onto Map.c return connLocs(currentView->europe, numLocations, from, player, round, road, rail, sea); }
void decideDraculaMove(DracView gameState) { char* nextPos = NULL; if (giveMeTheRound(gameState) == 0){ nextPos = "MR"; } else { int numLocations; LocationID* possibleDest = whereCanIgo(gameState, &numLocations, 1, 0); srand((unsigned int)time(NULL)); //seed random nextPos = idToName(possibleDest[rand()%numLocations]); } PlayerMessage msg = "Dracula MSG"; registerBestPlay(nextPos,msg); }
void filename_datafiles(const int iter, const int solverId, const char* base_name, unsigned len, char* template_name, char* log_filename) { char iterStr[40]; snprintf(iterStr, sizeof(iterStr), "-i%d-%s", iter, idToName(solverId)); if (base_name) { strncpy(template_name, base_name, len); strncpy(log_filename, base_name, len); } else { strncpy(template_name, "fc3d_avi-condensed", len); strncpy(log_filename, "fc3d_avi-condense-log", len); } strncat(template_name, iterStr, len - strlen(template_name) - 1); strncat(log_filename, iterStr, len - strlen(log_filename) - 1); strncat(log_filename, ".log", len - strlen(log_filename) - 1); }
void set_SolverOptions(SolverOptions* options, int solverId) { int iSize = 0; int dSize = 0; int iter_max = 0; double tol = 0.0; switch (solverId) { case SICONOS_LCP_PATH: { tol = 1e-12; } case SICONOS_LCP_PGS: case SICONOS_LCP_CPG: case SICONOS_LCP_NEWTONMIN: case SICONOS_LCP_QP: case SICONOS_LCP_NSQP: { iSize = 2; dSize = 2; iter_max = 1000; tol = tol == 0. ? 1e-8 : tol; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); break; } case SICONOS_LCP_RPGS: { iSize = 2; dSize = 3; iter_max = 1000; tol = 1e-8; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); options->dparam[2] = 1.0; break; } case SICONOS_LCP_LATIN: { iSize = 2; dSize = 3; iter_max = 1000; tol = 1e-8; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); options->dparam[2] = 0.3; break; } case SICONOS_LCP_LATIN_W: { iSize = 2; dSize = 4; iter_max = 1000; tol = 1e-8; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); options->dparam[2] = 0.3; options->dparam[3] = 1.0; break; } case SICONOS_LCP_ENUM: { iSize = 5; dSize = 2; iter_max = 0; /* this indicates the number of solutions ... */ tol = 1e-8; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); /*use dgels:*/ options->iparam[4] = 0; break; } case SICONOS_NCP_NEWTON_FBLSA: case SICONOS_NCP_NEWTON_MINFBLSA: case SICONOS_MCP_NEWTON_FBLSA: case SICONOS_MCP_NEWTON_MINFBLSA: case SICONOS_LCP_NEWTON_FBLSA: case SICONOS_LCP_NEWTON_MINFBLSA: case SICONOS_VI_BOX_QI: iSize = 6; dSize = 3; iter_max = 1000; tol = 1e-12; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); newton_lsa_default_SolverOption(options); break; case SICONOS_NCP_PATHSEARCH: iSize = 9; dSize = 8; iter_max = 100; tol = 1e-12; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); pathsearch_default_SolverOption(options); break; case SICONOS_VI_BOX_AVI_LSA: iSize = 6; dSize = 3; iter_max = 100; tol = 1e-12; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); vi_box_AVI_extra_SolverOptions(options); break; case SICONOS_AVI_CAOFERRIS: case SICONOS_LCP_AVI_CAOFERRIS: case SICONOS_RELAY_AVI_CAOFERRIS: case SICONOS_RELAY_AVI_CAOFERRIS_TEST: iSize = 6; dSize = 3; iter_max = 10000; tol = 1e-12; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); break; case SICONOS_LCP_LEMKE: case SICONOS_LCP_BARD: case SICONOS_LCP_MURTY: case SICONOS_LCP_PIVOT: case SICONOS_LCP_PIVOT_LUMOD: case SICONOS_LCP_PATHSEARCH: iSize = 6; dSize = 3; iter_max = 10000; tol = 100*DBL_EPSILON; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); options->iparam[SICONOS_IPARAM_PIVOT_RULE] = SICONOS_LCP_PIVOT_LEMKE; break; case SICONOS_LCP_GAMS: { tol = 1e-12; } case SICONOS_FRICTION_3D_GAMS_PATH: case SICONOS_FRICTION_3D_GAMS_PATHVI: case SICONOS_FRICTION_3D_GAMS_LCP_PATH: case SICONOS_FRICTION_3D_GAMS_LCP_PATHVI: case SICONOS_GLOBAL_FRICTION_3D_GAMS_PATH: case SICONOS_GLOBAL_FRICTION_3D_GAMS_PATHVI: { #ifdef HAVE_GAMS_C_API iSize = 5; dSize = 4; // stupid thing in checkTrivialCase in fc3d_driver.c iter_max = 10000; tol = tol == 0. ? 1e-9 : tol; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); if (!options->solverParameters) { options->solverParameters = createGAMSparams(GAMS_MODELS_SHARE_DIR, GAMS_DIR); } break; #else printf("set_SolverOptions :: GAMS was not enabled, exiting!\n"); exit(EXIT_FAILURE); #endif } case SICONOS_NCP_PATH: case SICONOS_VI_BOX_PATH: iSize = 6; dSize = 3; iter_max = 10000; tol = 1e-12; fill_SolverOptions(options, solverId, iSize, dSize, iter_max, tol); break; default: printf("set_SolverOptions not supported for solver id %d named %s\n", solverId, idToName(solverId)); exit(EXIT_FAILURE); } }
void recursive_printSolverOptions(SolverOptions* options, int level) { char* marge; int i; marge = (char*) malloc((level + 1) * sizeof(char)); for (i = 0; i < level; i++) marge[i] = ' '; marge[level] = '\0'; printf("%s\n ========== Numerics Non Smooth Solver parameters: \n", marge); if (options->isSet == 0) printf("%sThe solver parameters have not been set. \t options->isSet = %i \n", marge, options->isSet); else { printf("%sThe solver parameters below have been set \t options->isSet = %i\n", marge, options->isSet); printf("%sId of the solver\t\t\t\t options->solverId = %d \n", marge, options->solverId); printf("%sName of the solver\t\t\t\t %s \n", marge, idToName(options->solverId)); if (options->iparam != NULL) { printf("%sint parameters \t\t\t\t\t options->iparam\n", marge); printf("%ssize of the int parameters\t\t\t options->iSize = %i\n", marge, options->iSize); for (int i = 0; i < options->iSize; ++i) printf("%s\t\t\t\t\t\t options->iparam[%i] = %d\n", marge, i, options->iparam[i]); } if (options->dparam != NULL) { printf("%sdouble parameters \t\t\t\t options->dparam\n", marge); printf("%ssize of the double parameters\t\t\t options->dSize = %i\n", marge, options->dSize); for (int i = 0; i < options->dSize; ++i) printf("%s\t\t\t\t\t\t options->dparam[%i] = %.6le\n", marge, i, options->dparam[i]); } } if (options->iWork == NULL) { printf("%sinteger work array have not been allocated. \t options->iWork = NULL \n", marge); } else { printf("%sinteger work array have been allocated. \t options->iWork = %p \n", marge, options->iWork); printf("%sinteger work array size \t\t\t options->iSize = %i \n", marge, options->iSize); } if (options->dWork == NULL) { printf("%sdouble work array have not been allocated. \t options->dWork = NULL \n", marge); } else { printf("%sdouble work array have been allocated. \t options->dWork = %p \n", marge, options->dWork); printf("%sdouble work array size \t\t\t options->dSize = %i \n", marge, options->dSize); } printf("%sSee %s documentation for parameters definition)\n", marge, idToName(options->solverId)); printf("\n"); printf("%snumber of internal (or local) solvers \t\t options->numberOfInternalSolvers = %i\n", marge, options->numberOfInternalSolvers); for (i = 0; i < options->numberOfInternalSolvers; i++) { recursive_printSolverOptions(options->internalSolvers + i, level + 1); } free(marge); }
int main() { int i; DracView dv; printf("Test for basic functions, just before Dracula's first move\n"); PlayerMessage messages1[] = {"Hello","Rubbish","Stuff",""}; dv = newDracView("GST.... SAO.... HZU.... MBB....", messages1); assert(giveMeTheRound(dv) == 0); assert(whereIs(dv,PLAYER_LORD_GODALMING) == STRASBOURG); assert(whereIs(dv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN); assert(whereIs(dv,PLAYER_VAN_HELSING) == ZURICH); assert(whereIs(dv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY); assert(whereIs(dv,PLAYER_DRACULA) == UNKNOWN_LOCATION); assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); printf("passed\n"); disposeDracView(dv); printf("Test for encountering Dracula and hunter history\n"); PlayerMessage messages2[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","",""}; dv = newDracView("GST.... SAO.... HCD.... MAO.... DGE.... " "GGED... SAO.... HCD.... MAO....", messages2); assert(giveMeTheRound(dv) == 1); assert(whereIs(dv,PLAYER_DRACULA) == GENEVA); assert(howHealthyIs(dv,PLAYER_LORD_GODALMING) == 5); assert(howHealthyIs(dv,PLAYER_DRACULA) == 30); assert(whereIs(dv,PLAYER_LORD_GODALMING) == GENEVA); LocationID history[TRAIL_SIZE]; giveMeTheTrail(dv,PLAYER_DRACULA,history); assert(history[0] == GENEVA); assert(history[2] == UNKNOWN_LOCATION); giveMeTheTrail(dv,PLAYER_LORD_GODALMING,history); assert(history[0] == GENEVA); assert(history[1] == STRASBOURG); assert(history[2] == UNKNOWN_LOCATION); giveMeTheTrail(dv,PLAYER_DR_SEWARD,history); assert(history[0] == ATLANTIC_OCEAN); assert(history[1] == ATLANTIC_OCEAN); assert(history[2] == UNKNOWN_LOCATION); printf("passed\n"); disposeDracView(dv); printf("Test for Dracula leaving minions\n"); PlayerMessage messages3[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Drop a V","Party in Strasbourg","Party","Party","Party"}; dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. " "GST.... SST.... HST.... MST.... DMNT... " "GST.... SST.... HST.... MST....", messages3); int nT, nV; whatsThere(dv,EDINBURGH,&nT,&nV); assert(nT == 0 && nV == 1); whatsThere(dv,MANCHESTER,&nT,&nV); assert(nT == 1 && nV == 0); assert(whereIs(dv,PLAYER_DRACULA) == MANCHESTER); giveMeTheTrail(dv,PLAYER_DRACULA,history); assert(history[0] == MANCHESTER); assert(history[1] == EDINBURGH); assert(history[2] == UNKNOWN_LOCATION); giveMeTheTrail(dv,PLAYER_MINA_HARKER,history); assert(history[0] == STRASBOURG); assert(history[1] == STRASBOURG); assert(history[2] == GENEVA); assert(history[3] == UNKNOWN_LOCATION); printf("passed\n"); disposeDracView(dv); // needs further work - double back 2 not working dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. " "GST.... SST.... HST.... MST.... DHIT... " "GST.... SST.... HST.... MST.... DMNT... " "GST.... SST.... HST.... MST.... DD2T...", messages3); whatsThere(dv,EDINBURGH,&nT,&nV); assert(nV == 1); whatsThere(dv, MANCHESTER, &nT, &nV); assert(nT == 1 && nV == 0); whatsThere(dv,EDINBURGH,&nT,&nV); assert(nT == 2 && nV == 1); dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. " "GST.... SST.... HST.... MST.... DHIT... " "GST.... SST.... HST.... MST.... DMNT... " "GST.... SST.... HST.... MST.... DD1T...", messages3); whatsThere(dv,EDINBURGH,&nT,&nV); assert(nV == 1); whatsThere(dv, MANCHESTER, &nT, &nV); assert(nT == 2 && nV == 0); whatsThere(dv,EDINBURGH,&nT,&nV); assert(nT == 1 && nV == 1); dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. " "GST.... SST.... HST.... MST.... DHIT... " "GST.... SST.... HST.... MST.... DMNT... " "GST.... SST.... HST.... MST.... DD3T...", messages3); whatsThere(dv,EDINBURGH,&nT,&nV); assert(nV == 1); whatsThere(dv, MANCHESTER, &nT, &nV); assert(nT == 1 && nV == 0); whatsThere(dv,EDINBURGH,&nT,&nV); assert(nT == 2 && nV == 1); printf("Our test right here\n"); dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. " "GST.... SST.... HST.... MST.... DHIT... " "GST.... SST.... HST.... MST.... DMNT... " "GGE.... SGE.... HGE.... MGE.... DLVT... " "GST.... SST.... HST.... MST.... DD3T...", messages3); printf("called the funciton\n"); whatsThere(dv,EDINBURGH,&nT,&nV); assert(nV == 1); printf("up to first ed\n"); whatsThere(dv, MANCHESTER, &nT, &nV); assert(nT == 1 && nV == 0); whatsThere(dv, LIVERPOOL, &nT, &nV); assert(nT == 1 && nV == 0); whatsThere(dv,EDINBURGH,&nT,&nV); assert(nT == 2 && nV == 1); printf("passed our tests\n"); //------------------------- // Visual inspection required! printf("\nConn. locs. tests. Eyeball for authenticity:\n"); dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. " "GST.... SST.... HST.... MST.... DMNT... " "GST.... SST.... HST.... MST.... DLOT...", messages3); int numlocations; LocationID *locations = whereCanIgo(dv, &numlocations, TRUE, FALSE); for (int i = numlocations-1; i >= 0; i--) { printf("Location is %d, aka %s\n", locations[i], idToName(locations[i])); } dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. " "GST.... SST.... HST.... MST.... DMNT... " "GST.... SST.... HST.... MST.... DD2T...", messages3); locations = whereCanIgo(dv, &numlocations, TRUE, FALSE); for (int i = numlocations-1; i >= 0; i--) { printf("Location is %d, aka %s\n", locations[i], idToName(locations[i])); } dv = newDracView("GST.... SST.... HST.... MST.... DMNT... " "GST.... SST.... HST.... MST.... DLOT... " "GST.... SST.... HST.... MST.... DD2T... " "GST.... SST.... HST.... MST.... DHIT... " "GST.... SST.... HST.... MST....", messages3); locations = whereCanIgo(dv, &numlocations, TRUE, FALSE); for (int i = numlocations-1; i >= 0; i--) { printf("Location is %d, aka %s\n", locations[i], idToName(locations[i])); } printf("last devious test\n"); dv = newDracView("GST.... SST.... HST.... MST.... DPRT... " "GST.... SST.... HST.... MST.... DBRT... " "GST.... SST.... HST.... MST.... DHAT... " "GST.... SST.... HST.... MST.... DCOT... " "GST.... SST.... HST.... MST.... DAMT... " "GST.... SST.... HST.... MST.... DD3T... " "GST.... SST.... HST.... MST.... DHIT... " "GST.... SST.... HST.... MST....", messages3); locations = whereCanIgo(dv, &numlocations, TRUE, FALSE); for (int i = numlocations-1; i >= 0; i--) { printf("Location is %d, aka %s\n", locations[i], idToName(locations[i])); } printf("passed tricky conn. locs. tests\n"); //------------------------- printf("Test for connections\n"); int size, seen[NUM_MAP_LOCATIONS], *edges; printf("Checking Galatz road connections\n"); PlayerMessage messages5[] = {"Gone to Galatz"}; dv = newDracView("GGA....", messages5); edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,1,0,0); memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int)); for (i = 0; i< size ; i++) seen[edges[i]] = 1; assert(size == 5); assert(seen[GALATZ]); assert(seen[CONSTANTA]); assert(seen[BUCHAREST]); assert(seen[KLAUSENBURG]); assert(seen[CASTLE_DRACULA]); free(edges); disposeDracView(dv); printf("Checking Ionian Sea sea connections\n"); PlayerMessage messages6[] = {"Sailing the Ionian"}; dv = newDracView("GIO....", messages6); edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,0,1); memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int)); for (i = 0; i < size; i++) seen[edges[i]] = 1; assert(size == 7); assert(seen[IONIAN_SEA]); assert(seen[BLACK_SEA]); assert(seen[ADRIATIC_SEA]); assert(seen[TYRRHENIAN_SEA]); assert(seen[ATHENS]); assert(seen[VALONA]); assert(seen[SALONICA]); free(edges); disposeDracView(dv); printf("Checking Athens rail connections (none)\n"); PlayerMessage messages7[] = {"Leaving Athens by train"}; dv = newDracView("GAT....", messages7); edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,1,0); assert(size == 1); assert(edges[0] == ATHENS); free(edges); disposeDracView(dv); printf("passed\n"); // Test whatsThere () printf("Test whatsThere ()\n"); PlayerMessage messages685[] = {"Hello","Rubbish","Stuff",""}; dv = newDracView("GST.... SAO.... HZU.... MBB....", messages685); assert(giveMeTheRound(dv) == 0); assert(whereIs(dv,PLAYER_LORD_GODALMING) == STRASBOURG); assert(whereIs(dv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN); assert(whereIs(dv,PLAYER_VAN_HELSING) == ZURICH); assert(whereIs(dv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY); assert(whereIs(dv,PLAYER_DRACULA) == UNKNOWN_LOCATION); assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); printf("passed\n"); disposeDracView(dv); // EXTRA TEST 1 printf("extra test 1\n"); PlayerMessage messages9[] = {"Hello","Rubbish","Stuff",""}; dv = newDracView("GVI.... SZU.... HBB.... MSO....", messages9); assert(whereIs(dv, PLAYER_LORD_GODALMING) == VIENNA); assert(whereIs(dv, PLAYER_DR_SEWARD) == ZURICH); assert(whereIs(dv, PLAYER_VAN_HELSING) == BAY_OF_BISCAY); assert(whereIs(dv, PLAYER_MINA_HARKER) == SOFIA); assert(whereIs(dv, PLAYER_DRACULA) == UNKNOWN_LOCATION); assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); disposeDracView(dv); printf("passed extra1!\n"); // EXTRA TEST 2 - test putting traps twice printf("extra test 2\n"); PlayerMessage messages10[] = {"Drop","party","at","Varrock"}; dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. " "GCO.... SSR.... HSO.... MNP.... DZAT... " "GFR.... STO.... HBE.... MRO....", messages10); assert(giveMeTheRound(dv) == 2); assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)))); assert(whereIs(dv, PLAYER_LORD_GODALMING) == FRANKFURT); assert(whereIs(dv, PLAYER_DR_SEWARD) == TOULOUSE); assert(whereIs(dv, PLAYER_VAN_HELSING) == BELGRADE); assert(whereIs(dv, PLAYER_MINA_HARKER) == ROME); assert(whereIs(dv, PLAYER_DRACULA) == ZAGREB); int numOfTraps, numOfVamps; whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 1); whatsThere(dv,ZAGREB,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); // whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps); // assert(numOfTraps == 1 && numOfVamps == 0); assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS); disposeDracView(dv); printf("passed extra2!\n"); // EXTRA TEST 3 - deleting traps once trail has passed printf("extra test 3!\n"); PlayerMessage messages11[] = {"Drop","party","at","Varrock"}; dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZT... " "GCO.... SSR.... HSO.... MNP.... DZAT... " "GFR.... STO.... HBE.... MRO.... DVIT... " "GCO.... SSR.... HSO.... MNP.... DPRT... " "GHA.... SMA.... HVR.... MBI.... DNUT... " "GFR.... STO.... HBE.... MRO.... DSTT... " "GHA.... SMA.... HVR.... MBI.... DPAT.M. " "GHA.... SMA.... HVR.... MBI.... ", messages11); assert(giveMeTheRound(dv) == 7); assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)))); assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG); assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID); assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA); assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI); assert(whereIs(dv, PLAYER_DRACULA) == PARIS); LocationID dracTrail[6] = {0}; giveMeTheTrail(dv, PLAYER_DRACULA, dracTrail); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); // since traps are destroyed after every 6 moves in the trail assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PARIS,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); disposeDracView(dv); printf("passed extra3!\n"); printf("extra test 3!\n"); dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZT... " "GCO.... SSR.... HSO.... MNP.... DZAT... " "GFR.... STO.... HBE.... MRO.... DVIT... " "GCO.... SSR.... HSO.... MNP.... DPRT... " "GHA.... SMA.... HVR.... MBI.... DNUT... " "GFR.... STO.... HBE.... MRO.... DSTT... " "GHA.... SMA.... HVR.... MBI.... DPAT.M. " "GHA.... SMA.... HVR.... MBI.... ", messages11); assert(giveMeTheRound(dv) == 7); assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)))); assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG); assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID); assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA); assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI); assert(whereIs(dv, PLAYER_DRACULA) == PARIS); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); // since traps are destroyed after every 6 moves in the trail assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PARIS,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); disposeDracView(dv); printf("passed extra3!\n"); printf("extra test 4!\n"); dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. " "GCO.... SSR.... HSO.... MNP.... DZAT... " "GFR.... STO.... HBE.... MRO.... DVIT... " "GCO.... SSR.... HSO.... MNP.... DPRT... " "GHA.... SMA.... HVR.... MBI.... DNUT... " "GFR.... STO.... HBE.... MRO.... DSTT... " "GHA.... SMA.... HVR.... MBI.... DPAT.V. " "GHA.... SMA.... HVR.... MBI.... ", messages11); assert(giveMeTheRound(dv) == 7); assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)) - SCORE_LOSS_VAMPIRE_MATURES)); assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG); assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID); assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA); assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI); assert(whereIs(dv, PLAYER_DRACULA) == PARIS); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); // since traps are destroyed after every 6 moves in the trail assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PARIS,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); disposeDracView(dv); printf("passed extra4!\n"); printf("extra test 5!\n"); dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. " "GCO.... SSR.... HSO.... MNP.... DZAT... " "GFR.... STO.... HBE.... MRO.... DVIT... " "GCO.... SSR.... HSO.... MNP.... DPRT... " "GHA.... SMA.... HVR.... MBI.... DNU.V.. " "GFR.... STO.... HBE.... MRO.... DSTT... " "GHA.... SMA.... HVR.... MBI.... DPAT.V. " "GHA.... SMA.... HVR.... MBI.... ", messages11); assert(giveMeTheRound(dv) == 7); assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)) - SCORE_LOSS_VAMPIRE_MATURES)); assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG); assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID); assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA); assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI); assert(whereIs(dv, PLAYER_DRACULA) == PARIS); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); // since traps are destroyed after every 6 moves in the trail assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 1); whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PARIS,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); disposeDracView(dv); printf("passed extra5!\n"); printf("extra test 6!\n"); dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. " "GCO.... SSR.... HSO.... MNP.... DZAT... " "GFR.... STO.... HBE.... MRO.... DVIT... " "GCO.... SSR.... HSO.... MNP.... DPRT... " "GHA.... SMA.... HVR.... MBI.... DNU.V.. " "GFR.... SNUV... HBE.... MRO.... DSTT... " "GHA.... SMA.... HVR.... MBI.... DPAT.V. " "GHA.... SMA.... HVR.... MBI.... ", messages11); assert(giveMeTheRound(dv) == 7); assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)) - SCORE_LOSS_VAMPIRE_MATURES)); assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG); assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID); assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA); assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI); assert(whereIs(dv, PLAYER_DRACULA) == PARIS); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); // since traps are destroyed after every 6 moves in the trail assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PARIS,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); disposeDracView(dv); printf("passed extra6!\n"); printf("extra test 7!\n"); dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. " "GCO.... SSR.... HSO.... MNP.... DZAT... " "GFR.... STO.... HBE.... MRO.... DVIT... " "GCO.... SSR.... HSO.... MNP.... DPRT... " "GHA.... SMA.... HVR.... MBI.... DNU.V.. " "GFR.... SNUV... HSZV... MRO.... DSTT... " "GHA.... SMA.... HVR.... MBI.... DPAT... " "GHA.... SMA.... HVR.... MBI.... ", messages11); assert(giveMeTheRound(dv) == 7); assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)))); assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG); assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID); assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA); assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI); assert(whereIs(dv, PLAYER_DRACULA) == PARIS); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps); // since traps are destroyed after every 6 moves in the trail assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 0 && numOfVamps == 0); whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); whatsThere(dv,PARIS,&numOfTraps,&numOfVamps); assert(numOfTraps == 1 && numOfVamps == 0); disposeDracView(dv); printf("passed extra7!\n"); return 0; }
void decideHunterMove(HunterView gameState) { //printf("------------------------------------------"); int playerID = whoAmI(gameState); if(howHealthyIs(gameState,playerID)==0){ registerBestPlay("JM","Dead"); }else if(playerID == 0){ int round = giveMeTheRound(gameState); LocationID trail[TRAIL_SIZE]; giveMeTheTrail(gameState, whoAmI(gameState), trail); int dead = 0; int i; for(i=0; i<3; i++){ if(trail[i] == nameToID("JM")) dead = i; fprintf(stderr, "Dead%d\n",dead); } if(dead){ if(round%2==0){ registerBestPlay("KL","Camping 1"); }else if(round%2==1){ registerBestPlay("BC","Camping 2"); } }else{ if(dead == 0){ registerBestPlay("SZ","Recovery 1"); }else if(dead == 1){ registerBestPlay("KL","Recovery 2"); }else{ registerBestPlay("KL","Recovery 3"); } } }else{ fprintf(stderr, "\n\nHunters\n"); srand((unsigned) time(NULL)); if(giveMeTheRound(gameState) == 0){ registerBestPlay("MU","Let the games Begin"); }else{ int numLocations = 0; int *places; char message[15]; int i; fprintf(stderr,"huntFrom:%s\n",idToName(whereIs(gameState, playerID))); fprintf(stderr, "\n\n\n"); places = whereCanIgo(gameState, &numLocations, 1, 1, 0); fprintf(stderr, "Free\nnumLoc:%d\n", numLocations); for(i=0; i<numLocations; i++){ fprintf(stderr, "%s,",idToName(places[i])); } srand(time(NULL)); registerBestPlay(idToAbbrev(places[rand()%numLocations]),message); //if(places[0]) // printf("a"); sprintf(message, "\n\n"); //registerBestPlay("MU",""); } } //printf("\n\n\n\n"); //egisterBestPlay("GE","I'm on holiday in Geneva"); }
int fc2d_driver(FrictionContactProblem* problem, double *reaction , double *velocity, SolverOptions* options, NumericsOptions* global_options) { #ifdef DUMP_PROBLEM char fname[256]; sprintf(fname, "FrictionContactProblem%.5d.dat", fccounter++); printf("Dump of FrictionContactProblem%.5d.dat", fccounter); FILE * foutput = fopen(fname, "w"); frictionContact_printInFile(problem, foutput); fclose(foutput); #endif if (options == NULL || global_options == NULL) numericsError("fc2d_driver", "null input for solver and/or global options"); /* Set global options */ setNumericsOptions(global_options); /* Checks inputs */ if (problem == NULL || reaction == NULL || velocity == NULL) numericsError("fc2d_driver", "null input for FrictionContactProblem and/or unknowns (reaction,velocity)"); /* If the options for solver have not been set, read default values in .opt file */ int NoDefaultOptions = options->isSet; /* true(1) if the SolverOptions structure has been filled in else false(0) */ if (!NoDefaultOptions) readSolverOptions(3, options); if (verbose > 0) printSolverOptions(options); /* Solver name */ /*char * name = options->solverName;*/ int info = -1 ; if (problem->dimension != 2) numericsError("fc2d_driver", "Dimension of the problem : problem-> dimension is not compatible or is not set"); /* Non Smooth Gauss Seidel (NSGS) */ if (problem->M->storageType == 1) { if (options->solverId == SICONOS_FRICTION_2D_NSGS) { if (verbose) printf(" ======================= Call Sparse NSGS solver for Friction-Contact 2D problem ======================\n"); fc2d_sparse_nsgs(problem, reaction , velocity , &info , options); } else { fprintf(stderr, "fc2d_driver error: unknown solver named: %s\n", idToName(options->solverId)); exit(EXIT_FAILURE); } } else if (problem->M->storageType == 0) { switch (options->solverId) { /****** NLGS algorithm ******/ case SICONOS_FRICTION_2D_PGS: case SICONOS_FRICTION_2D_NSGS: { if (verbose) printf(" ========================== Call NLGS solver for Friction-Contact 2D problem ==========================\n"); fc2d_nsgs(problem, reaction, velocity, &info, options); break; } /****** CPG algorithm ******/ case SICONOS_FRICTION_2D_CPG: { if (verbose) printf(" ========================== Call CPG solver for Friction-Contact 2D problem ==========================\n"); fc2d_cpg(problem, reaction, velocity, &info, options); break; } /****** Latin algorithm ******/ case SICONOS_FRICTION_2D_LATIN: { if (verbose) printf(" ========================== Call Latin solver for Friction-Contact 2D problem ==========================\n"); fc2d_latin(problem, reaction, velocity, &info, options); break; } /****** Lexicolemke algorithm ******/ case SICONOS_FRICTION_2D_LEMKE: { if (verbose) printf(" ========================== Call Lemke solver for Friction-Contact 2D problem ==========================\n"); fc2d_lexicolemke(problem, reaction, velocity, &info, options, global_options); break; } /****** Enum algorithm ******/ case SICONOS_FRICTION_2D_ENUM: { if (verbose) printf(" ========================== Call Enumerative solver for Friction-Contact 2D problem ==========================\n"); fc2d_enum(problem, reaction, velocity, &info, options, global_options); break; } /*error */ default: { fprintf(stderr, "fc2d_driver error: unknown solver named: %s\n", idToName(options->solverId)); exit(EXIT_FAILURE); } } #ifdef DUMP_PROBLEM_IF_INFO if (info) { char fname[256]; sprintf(fname, "FrictionContactProblem%.5d.dat", fccounter++); printf("Dump of FrictionContactProblem%.5d.dat\n", fccounter); FILE * foutput = fopen(fname, "w"); frictionContact_printInFile(problem, foutput); fclose(foutput); } #endif } else { numericsError("fc2d_driver", " error: unknown storagetype named"); exit(EXIT_FAILURE); } return info; }
void initializeLocalSolver_nsgs_velocity(SolverPtr* solve, FreeSolverPtr* freeSolver, ComputeErrorPtr* computeError, FrictionContactProblem* problem, FrictionContactProblem* localproblem, SolverOptions* localsolver_options) { /** Connect to local solver */ /* Projection */ if (localsolver_options->solverId == SICONOS_FRICTION_3D_ProjectionOnCone_velocity) { *solve = &frictionContact3D_projectionOnCone_velocity_solve; *freeSolver = (FreeSolverPtr)&frictionContact3D_projection_free; *computeError = (ComputeErrorPtr)&FrictionContact3D_compute_error_velocity; frictionContact3D_projection_initialize(problem, localproblem); } else { fprintf(stderr, "Numerics, FrictionContact3D_nsgs_velocity failed. Unknown internal solver : %s.\n", idToName(localsolver_options->solverId)); exit(EXIT_FAILURE); } }