int game_setup(jnx_hashmap *configuration) { assert(configuration); config = configuration; assert(config); videomode = sfVideoMode_getDesktopMode(); JNX_LOG(NULL,"Video mode is %d %d\n",videomode.width,videomode.height); main_window = sfRenderWindow_create(videomode,"Gridfire",sfDefaultStyle,NULL); int max_fps = atoi(jnx_hash_get(config,"MAXFPS")); assert(max_fps); sfRenderWindow_setFramerateLimit(main_window,max_fps); main_view = sfView_create(); sfVector2f view_size; view_size.x = videomode.width; view_size.y = videomode.height; sfView_setSize(main_view,view_size); clear_color = sfColor_fromRGB(0,0,0); JNX_LOG(NULL,"Creating game _clock\n"); _clock = sfClock_create(); JNX_LOG(NULL,"Creating bounding map\n"); int game_bound = atoi(jnx_hash_get(configuration,"GAMEBOUNDS")); cartographer_setbounds(0,game_bound,0,game_bound); int star_density = atoi(jnx_hash_get(configuration,"STARCOUNT")); starfield_create(cartographer_getbounds(),star_density); JNX_LOG(NULL,"Initial setup complete\n"); /*----------------------------------------------------------------------------- * Game text *-----------------------------------------------------------------------------*/ game_start_text = game_ui_text_builder("GRIDFIRE",sfView_getCenter(main_view),sfColor_fromRGB(255,0,0),sfTextRegular,40); game_over_text = game_ui_text_builder("GAME OVER",sfView_getCenter(main_view),sfColor_fromRGB(255,255,255),sfTextRegular,30); game_start_button_text = game_ui_text_builder("Start",sfView_getCenter(main_view),sfColor_fromRGB(255,0,0),sfTextRegular,15); game_author_text = game_ui_text_builder("By Alex Jones",sfView_getCenter(main_view),sfColor_fromRGB(255,0,0),sfTextRegular,15); next_level_text = game_ui_text_builder("Congratulations",sfView_getCenter(main_view),sfColor_fromRGB(255,255,255),sfTextRegular,45); next_level_button_text = game_ui_text_builder("Press enter for the next level",sfView_getCenter(main_view),sfColor_fromRGB(255,0,0),sfTextRegular,20); game_loading_text = game_ui_text_builder("LOADING",sfView_getCenter(main_view),sfColor_fromRGB(255,0,0),sfTextRegular,40); game_finish_text = game_ui_text_builder("GAME COMPLETE",sfView_getCenter(main_view),sfColor_fromRGB(255,0,0),sfTextRegular,40); assert(game_finish_text); assert(game_loading_text); assert(next_level_button_text); assert(game_start_text); assert(game_over_text); assert(game_start_button_text); assert(game_author_text); assert(next_level_text); /*----------------------------------------------------------------------------- * Game level setup *-----------------------------------------------------------------------------*/ max_levels = atoi(jnx_hash_get(configuration,"MAXLEVELS")); assert(max_levels); //start on level one current_level = 1; /*----------------------------------------------------------------------------- * Scoreboard setup *-----------------------------------------------------------------------------*/ score_setup(atoi(jnx_hash_get(configuration,"MAXSCORE"))); /*----------------------------------------------------------------------------- * Load weapon textures *-----------------------------------------------------------------------------*/ weapon_setup(); /*----------------------------------------------------------------------------- * Load ingame music *-----------------------------------------------------------------------------*/ audio_control_setup(configuration); play_music(TITLEMUSIC); if(game_ui_setup(main_window,main_view) != 0) { return 1; } /*----------------------------------------------------------------------------- * Set game state to running *-----------------------------------------------------------------------------*/ current_game_state = GAMESTART; return 0; }
main(int argc, char**argv) { lgopen(argc,argv); char *fname_inerr[5]; int nscores=0; int nweights=0; double weights[100]; char *fname_qualify=NULL; int nloops=10000; int copt=1; int i; for(i=1;i<argc;i++) { int rc=score_argv(argv+i); if(rc>0) { i+=rc-1; continue; } if(!strcmp(argv[i],"-le")) fname_inerr[nscores++]=argv[++i]; else if(!strcmp(argv[i],"-lew")) weights[nweights++]=atof(argv[++i]); else if(!strcmp(argv[i],"-se")) fname_outerr=argv[++i]; else if(!strcmp(argv[i],"-sq")) fname_qualify=argv[++i]; else if(!strcmp(argv[i],"-l")) nloops=atoi(argv[++i]); else if(!strcmp(argv[i],"-c")) copt^=1; else if(!strcmp(argv[i],"-a")) aopt=1; else if(!strcmp(argv[i],"-lm")) load_model=1; else if(!strcmp(argv[i],"-sm")) save_model=1; else { lg("Unrecognized argument %d %s ?\n",i,argv[i]); lg("-le <fname> - load precomputed error file.\n"); lg("-lew <weight> - In case of several -le, use wrights, instead of fit\n"); lg("-se <fname> - store resulted error file.\n"); lg("-l <n> - number of training loops to perform\n"); lg("-a - Perform training also on probe data\n"); lg("-c - Dont clip scores to be between 0...4\n"); lg("-sq <fname> - write qualifying submission to file.\n"); lg("-lm - load precomputed model.\n"); lg("-sm - save computed model.\n"); exit(0); } } if(fname_qualify && !aopt) lg("WARNING: -sq without -a\n"); if(fname_qualify && !copt) lg("WARNING: -sq with -c\n"); if(nweights && nscores && nweights!=nscores) lg("Number of weights %d (-lew) does not match number of files %d (-le)\n",nweights,nscores); load_bin(useridx_path,useridx,sizeof(useridx)); { int count[4],u,k; ZERO(count); for(u=0;u<NUSERS;u++) for(k=1;k<4;k++) count[k]+=useridx[u][k]; lg("Train=%d Probe=%d Qualify=%d\n",count[1],count[2],count[3]); } load_bin(userent_path,userent,sizeof(userent)); if(nscores) { if(nscores==1) load_bin(fname_inerr[0],err,sizeof(err)); else if(nweights) loadmix(fname_inerr,nscores,weights); else loadmix(fname_inerr,nscores,NULL); } else { int i; for(i=0;i<NENTRIES;i++) err[i]=(userent[i]>>USER_LMOVIEMASK)&7; globalavg(); } if(copt) cliperr(); rmse_print(copt); // if(nloops) { score_setup(); if(copt) cliperr(); rmse_print(copt); } int loop; int rc=1; for(loop=0;loop<nloops;loop++) { lg("Loop %d\n",loop); clock_t t0=clock(); if(!score_train(loop)) break; lg("%f sec\n",(clock()-t0)/((double)CLOCKS_PER_SEC)); if(copt && !dontclip) cliperr(); dontclip=0; rmse_print(copt); } if(fname_outerr) dump_bin(fname_outerr,err,sizeof(err)); if(fname_qualify) { FILE *fp=fopen(fname_qualify,"w"); char *qualify_path="data/qualify.bin"; unsigned int *qualify=malloc(NQUALIFY_SIZE*4); load_bin(qualify_path,qualify,NQUALIFY_SIZE*4); unsigned int *q=qualify; while (q<(qualify+NQUALIFY_SIZE)) { int m=*q++; fprintf(fp,"%d:\n",m+1); int l=*q++; int j; for(j=0;j<l;j++) { int u=*q++; int base2=useridx[u][0]+useridx[u][1]+useridx[u][2]; int d2=+useridx[u][3]; int k; for(k=0;k<d2;k++) { if((userent[base2+k]&USER_MOVIEMASK) == m) break; //lg("%d\n",userent[base2+k]&USER_MOVIEMASK); } if(k==d2) error("Bad qualify %d %d\n",m,u); fprintf(fp,"%.1f\n",8.-err[base2+k]); } } fclose(fp); } }