static void test_json_report(CuTest * tc) { region * r; faction * f; unit * u; cJSON * json; cleargame(true); turn = 0; r = create_region(0, 1, 1, create_terrain("plain")); f = addplayer(r, 0, 0); u = r->units; update_world(0, 0, 1, 1); json = json_report(f); CuAssertIntEquals(tc, turn, cJSON_GetObjectItem(json, "turn")->valueint); free(json); }
static int tolua_bindings_atlantis_free_game00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isboolean(tolua_S,1,0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { bool conf = ((bool) tolua_toboolean(tolua_S,1,0)); { cleargame(conf); } } return 0; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'free_game'.",&tolua_err); return 0; #endif }
int main(int argc, char *argv[]) { /* Seed randomness. */ srand(time(NULL) ^ getpid()); bake_args(argc, argv); initgame(); do { if(thegame.players == 1) whatside(); else player = X; thegame.restart = false; cleargame(); while(thegame.running) { if(thegame.players == 0) { printboard(false); compmove(player); if(checkwinner()) break; compmove(-player); } else if(thegame.players == 1) { if(player == X){ printboard(true); makemove(player); if(checkwinner()) break; compmove(-player); } else { compmove(-player); if(checkwinner()) break; printboard(true); makemove(player); } } else { printboard(true); makemove(player); player = -player; } checkwinner(); } printwinner(); restart(); } while(thegame.restart); /* we so funny */ if(thegame.players == 0) wargames(); return 0; }
int main(int argc, char **argv) { int i; char buf[12]; const char *arg, *orders = 0, *cfgfile = 0; rnd_seed((unsigned int) time(0)); puts("Atlantis v1.0 " __DATE__ "\n" "Copyright 1993 by Russell Wallace.\n" "Type ? for list of commands."); turn = -1; for (i = 1; i != argc; ++i) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'c': cfgfile = (argv[i][2]) ? (argv[i] + 2) : argv[++i]; break; case 'i': ignore_password = 1; break; case 'p': /* process */ orders = (argv[i][2]) ? (argv[i] + 2) : argv[++i]; break; case 't': /* turn */ arg = (argv[i][2]) ? (argv[i] + 2) : argv[++i]; turn = atoi(arg); break; default: fprintf(stderr, "invalid argument %d: '%s'\n", i, argv[i]); return -1; } } } if (cfgfile) { FILE * F = fopen(cfgfile, "r"); if (F) { cJSON *json; char *data; size_t len; fseek(F, 0,SEEK_END); len = ftell(F); fseek(F,0,SEEK_SET); data = (char *)malloc(len+1); if (data) { fread(data,1,len,F); } json = cJSON_Parse(data); if (json) { read_config_json(json); cJSON_Delete(json); } else { fprintf(stderr, "could not parse configuration file '%s'\n", cfgfile); } free(data); } else { fprintf(stderr, "could not open configuration file '%s'\n", cfgfile); return errno ? errno : -1; } } initgame(); if (orders) { return processturn(orders); } for (;;) { printf("> "); fgets(buf, sizeof(buf), stdin); switch (tolower(buf[0])) { case 'm': writemap(stdout); break; case 'g': turn = 0; cleargame(false); autoworld("players"); writemap(stdout); break; case 'r': reports(); break; case 'f': fixme(); break; case 'w': writesummary(); writegame(); break; case 'p': printf("Name of orders file? "); fgets(buf, sizeof(buf), stdin); if (!buf[0]) return -1; return processturn(buf); case 'q': return 0; default: puts("C - Create New Continent.\n" "A - Add New Players.\n" "M - Draw Map.\n" "P - Process Game Turn.\n" "R - Write Reports.\n" "G - Generate New World.\n" "Q - Quit.\n" "W - Write Game.\n"); } } }