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 SDLMouse::translate(std::string name) { int id; id = nameToID(name, "button"); if(id > 0 && id <= 8) return BUTTON1 + id - 1; if(name == "relx") return RELX; if(name == "rely") return RELY; return NOT_FOUND; }
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"); }