コード例 #1
0
ファイル: config_controls.cpp プロジェクト: jopek/zapper
void config_controls::update()
{
	if (capture && input::anykey) {

		int keydef = input::event.key.keysym.sym;
		if (!checkKey(keydef)) {
			bad->play(0,1);
			return;
		}
		select->play(0,1);
		if (hot < (int) names.size()){
			names[hot] = input::keyname(keydef);
			input::keys[hot]->set(keydef);
		}
		capture = false;
		input::clear();
		return;
	}
	if (input::pressed(KEY_UP)) {
		setHot(hot-1);
		move->play(0,1);
		return;
	}

	if (input::pressed(KEY_DOWN)) {
		setHot(hot+1);
		move->play(0,1);
		return;
	}
	if (input::pressed(KEY_ACCEPT)) {
		if (hot < CP_DEFAULT) {
			capture = true;
			names[hot] = "_";
		}
		else if (hot == CP_DEFAULT) {
			select->play(0,1);
			input::defaultKeys();
			set_names();
		}
		else if (hot == CP_BACK) {
			select->play(0,1);
			fsm->change(GS_OPTIONS);

			fsm->history.pop_back();
		}
		return;
	}
}
コード例 #2
0
ファイル: config_controls.cpp プロジェクト: jopek/zapper
config_controls::config_controls(game * g)
{
	fsm = g;
	capture = false;

	opt = gfx::loadFont("./data/fonts/mono.ttf", 20);
	title = gfx::loadFont("./data/fonts/bit.ttf", 33);
	select = audio::loadSfx("./data/sfx/select.wav");
	move = audio::loadSfx("./data/sfx/move.wav");
	bad = audio::loadSfx("./data/sfx/bad.wav");
	background = gfx::loadImage("./data/gfx/paper.png");

	for (int i=0; i<KEY_CONFIG_TOTAL; i++) {
		opts.push_back(input::keyTags[i]);
	}

	opts.push_back("Restore Default Controls");
	opts.push_back("Back");
	set_names();

	setHot(0);
}
コード例 #3
0
ファイル: fileio.c プロジェクト: dschwen/jszip
void open_story( const char *storyname )
{
   char *path, *p;
   char tmp[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1];

   if ( !STANDALONE_FLAG )
   {
      story_offset = 0;
   }
   else
   {
      /* standalone game; offset to story start is saved in low-endian */
      /* format after magic string */
      story_offset =
            magic[MAGIC_END + 1] + magic[MAGIC_END + 2] * 256L + magic[MAGIC_END + 3] * 65536L;
   }

   strcpy( tmp, storyname );    
   if ( ( gfp = jz_open( tmp, "rb" ) ) != NULL )
   {                            
#if defined BUFFER_FILES        
#ifndef USE_ZLIB
      setbuf( gfp, gfpbuffer ); 
#endif
#endif 
      set_names( storyname );   
      return;                   
#if defined MSDOS || defined OS2 
   }                            
   else                         
   {                            
      sprintf( tmp, "%s.exe", storyname ); 
      if ( ( gfp = jz_open( tmp, "rb" ) ) != NULL )
      {                         
#if defined BUFFER_FILES        
#ifndef USE_ZLIB
         setbuf( gfp, gfpbuffer ); 
#endif
#endif 
         set_names( storyname ); 
         return;                
      }                         
#endif 
   }                            

   if ( !STANDALONE_FLAG && ( path = getenv( "INFOCOM_PATH" ) ) == NULL )
   {
      fprintf( stderr, "%s ", tmp );
      fatal( "open_story(): Zcode file not found" );
   }
   else if ( STANDALONE_FLAG && ( path = getenv( "PATH" ) ) == NULL )
   {
      fprintf( stderr, "%s ", tmp );
      fatal( "open_story(): Zcode file not found" );
   }

   /* dos path will be like:                                                 */
   /* SET INFOCOM_PATH = C:\INFOCOM\LTOI1;C:\INFOCOM\LTOI2;C:\INFOCOM\INFORM */
#if defined MSDOS || defined OS2 
   p = strtok( path, ";" );
#else
   /* UNIX path will be like:                                                */
   /* setenv INFOCOM_PATH /usr/local/lib/ltoi1:/usr/local/lib/ltoi2          */
   p = strtok( path, ":" );
#endif

   while ( p )
   {
      sprintf( tmp, "%s/%s", p, storyname );
      if ( ( gfp = jz_open( tmp, "rb" ) ) != NULL )
      {
#if defined BUFFER_FILES        
#ifndef USE_ZLIB
         setbuf( gfp, gfpbuffer ); 
#endif
#endif 
         set_names( storyname );
         return;
#if defined MSDOS || defined OS2 
      }                         
      else                      
      {                         
         sprintf( tmp, "%s/%s.exe", p, storyname ); 
         if ( ( gfp = jz_open( tmp, "rb" ) ) != NULL )
         {                      
#if defined BUFFER_FILES        
#ifndef USE_ZLIB
            setbuf( gfp, gfpbuffer ); 
#endif
#endif 
            set_names( storyname ); 
            return;             
         }                      
#endif 
      }
#if defined MSDOS || defined OS2 
      p = strtok( NULL, ";" );
#else
      p = strtok( NULL, ":" );
#endif
   }

   fprintf( stderr, "%s ", tmp );
   fatal( "open_story(): Zcode file not found" );
}                               /* open_story */
コード例 #4
0
JNIEXPORT void
JNIFn(zebra, ZebraEngine, zePlay)(JNIEnv *env, jobject thiz, jint providedMoveCount,
                                  jbyteArray providedMoves) {
    EvaluationType eval_info;
    const char *black_name;
    const char *white_name;
    const char *opening_name;
    const char *op;
    double move_start, move_stop;
    int i;
    int side_to_move;
    int curr_move;
    int timed_search;
    int black_hash1, black_hash2, white_hash1, white_hash2;
    ui_event_t evt;
    int provided_move_count;
    int provided_move_index;
    int provided_move[65];
    int silent = FALSE;
    int use_book = s_use_book;

    DROIDZEBRA_JNI_SETUP;

    force_exit = 0;

    if (skill[BLACKSQ] < 0 || skill[WHITESQ] < 0) {
        fatal_error("Set Player Info first");
    }

    /* copy provided moves */
    provided_move_index = 0;
    provided_move_count = 0;
    if (providedMoveCount > 0 && providedMoves) {
        jbyte *providedMovesJNI;
        provided_move_count = providedMoveCount;
        i = (*env)->GetArrayLength(env, providedMoves);
        if (provided_move_count > i)
            fatal_error("Provided move count is greater than array size %d>%d", provided_move_count,
                        i);
        if (provided_move_count > 64)
            fatal_error("Provided move count is greater that 64: %d", provided_move_count);
        providedMovesJNI = (*env)->GetByteArrayElements(env, providedMoves, 0);
        if (!providedMovesJNI)
            fatal_error("failed to get provide moves (jni)");
        for (i = 0; i < provided_move_count; i++) {
            provided_move[i] = providedMovesJNI[i];
        }
        (*env)->ReleaseByteArrayElements(env, providedMoves, providedMovesJNI, 0);
    }

    /* Set up the position and the search engine */
    game_init(NULL, &side_to_move);
    setup_hash(TRUE);
    clear_stored_game();
    set_slack(floor(s_slack * 128.0));
    set_perturbation(floor(s_perturbation * 128.0));
    toggle_human_openings(s_human_opening);
    set_forced_opening(s_forced_opening_seq);
    opening_name = NULL;

    reset_book_search();
    set_deviation_value(0, 0, 0.0);

    if (skill[BLACKSQ] == 0)
        black_name = "Player";
    else
        black_name = "Zebra";

    if (skill[WHITESQ] == 0)
        white_name = "Player";
    else
        white_name = "Zebra";

    set_names(black_name, white_name);
    set_move_list(black_moves, white_moves, score_sheet_row);
    set_evals(0.0, 0.0);

    for (i = 0; i < 60; i++) {
        black_moves[i] = PASS;
        white_moves[i] = PASS;
    }

    black_hash1 = my_random();
    black_hash2 = my_random();
    white_hash1 = my_random();
    white_hash2 = my_random();

    droidzebra_msg_game_start();

    AGAIN:
    curr_move = PASS;
    while (game_in_progress() && !force_exit) {
        force_return = 0;
        silent = (provided_move_index < provided_move_count);

        droidzebra_enable_messaging(!silent);

        droidzebra_msg_move_start(side_to_move);

        remove_coeffs(disks_played);
        clear_evaluated();

        if (SEPARATE_TABLES) {  /* Computer players won't share hash tables */
            if (side_to_move == BLACKSQ) {
                hash1 ^= black_hash1;
                hash2 ^= black_hash2;
            } else {
                hash1 ^= white_hash1;
                hash2 ^= white_hash2;
            }
        }

        generate_all(side_to_move);

        if (side_to_move == BLACKSQ)
            score_sheet_row++;

        // echo
        droidzebra_msg_candidate_moves();
        set_move_list(black_moves, white_moves, score_sheet_row);
        set_times(floor(player_time[BLACKSQ]),
                  floor(player_time[WHITESQ]));
        op = find_opening_name();
        if (op != NULL && (!opening_name || strcmp(op, opening_name))) {
            opening_name = op;
        }
        droidzebra_msg_opening_name(opening_name);
        droidzebra_msg_last_move(disks_played > 0 ? get_stored_move(disks_played - 1) : PASS);
        display_board(stdout, board, side_to_move, TRUE, TRUE, TRUE);
        // echo

        if (move_count[disks_played] != 0) {
            move_start = get_real_timer();
            clear_panic_abort();

            if (provided_move_index >= provided_move_count) {
                if (skill[side_to_move] == 0) {
                    curr_move = -1;

                    if (auto_make_forced_moves && move_count[disks_played] == 1) {
                        curr_move = move_list[disks_played][0];
                    } else {
                        // compute evaluations
                        if (s_practice_mode) {
                            _droidzebra_compute_evals(side_to_move);
                            if (force_exit) break;
                            if (force_return) force_return = 0; // interrupted by user input
                        }

                        // wait for user event
                        droidzebra_msg_get_user_input(side_to_move, &evt);
                        if (evt.type == UI_EVENT_EXIT) {
                            force_exit = 1;
                            break;
                        } else if (evt.type == UI_EVENT_MOVE) {
                            curr_move = evt.evt_move.move;
                            _droidzebra_undo_stack_clear(); // once player makes the move undo info is stale
                        } else if (evt.type == UI_EVENT_UNDO) {
                            _droidzebra_undo_turn(&side_to_move);
                            // adjust for increment at the beginning of the game loop
                            if (side_to_move == BLACKSQ)
                                score_sheet_row--;
                            continue;
                        } else if (evt.type == UI_EVENT_REDO) {
                            _droidzebra_redo_turn(&side_to_move);
                            // adjust for increment at the beginning of the game loop
                            if (side_to_move == BLACKSQ)
                                score_sheet_row--;
                            continue;
                        } else if (evt.type == UI_EVENT_SETTINGS_CHANGE) {
                            _droidzebra_on_settings_change();
                            // repeat move on settings change
                            if (side_to_move == BLACKSQ)
                                score_sheet_row--; // adjust for increment at the beginning of the game loop
                            continue;
                        } else {
                            fatal_error("Unsupported UI event: %d", evt.type);
                        }
                    }
                    assert(curr_move >= 0);
                } else {
                    start_move(player_time[side_to_move],
                               player_increment[side_to_move],
                               disks_played + 4);
                    determine_move_time(player_time[side_to_move],
                                        player_increment[side_to_move],
                                        disks_played + 4);
                    timed_search = (skill[side_to_move] >= 60);
                    toggle_experimental(FALSE);

                    curr_move =
                            compute_move(side_to_move, TRUE, player_time[side_to_move],
                                         player_increment[side_to_move], timed_search,
                                         use_book, skill[side_to_move],
                                         exact_skill[side_to_move], wld_skill[side_to_move],
                                         FALSE, &eval_info);
                    if (side_to_move == BLACKSQ)
                        set_evals(produce_compact_eval(eval_info), 0.0);
                    else
                        set_evals(0.0, produce_compact_eval(eval_info));
                }
            } else {
                curr_move = provided_move[provided_move_index];
                if (!valid_move(curr_move, side_to_move))
                    fatal_error("Invalid move %c%c in move sequence", TO_SQUARE(curr_move));
            }

            move_stop = get_real_timer();
            if (player_time[side_to_move] != INFINIT_TIME)
                player_time[side_to_move] -= (move_stop - move_start);

            store_move(disks_played, curr_move);

            (void) make_move(side_to_move, curr_move, TRUE);
            if (side_to_move == BLACKSQ)
                black_moves[score_sheet_row] = curr_move;
            else {
                white_moves[score_sheet_row] = curr_move;
            }
        } else {
            // this is where we pass
            if (side_to_move == BLACKSQ)
                black_moves[score_sheet_row] = PASS;
            else
                white_moves[score_sheet_row] = PASS;
            if (!auto_make_forced_moves && skill[side_to_move] == 0) {
                droidzebra_msg_pass();
            }
        }

        droidzebra_msg_move_end(side_to_move);

        side_to_move = OPP(side_to_move);

        provided_move_index++;
    }

    droidzebra_enable_messaging(TRUE);

    if (side_to_move == BLACKSQ)
        score_sheet_row++;

    set_move_list(black_moves, white_moves, score_sheet_row);
    set_times(floor(player_time[BLACKSQ]), floor(player_time[WHITESQ]));
    droidzebra_msg_opening_name(opening_name);
    display_board(stdout, board, side_to_move, TRUE, TRUE, TRUE);

    /*
    double node_val, eval_val;
    adjust_counter( &total_nodes );
    node_val = counter_value( &total_nodes );
    adjust_counter( &total_evaluations );
    eval_val = counter_value( &total_evaluations );
    printf( "\nBlack: %d   White: %d\n", disc_count( BLACKSQ ),
            disc_count( WHITESQ ) );
    printf( "Nodes searched:        %-10.0f\n", node_val );

    printf( "Positions evaluated:   %-10.0f\n", eval_val );

    printf( "Total time: %.1f s\n", total_time );
    */

    if (!force_exit)
        droidzebra_msg_game_over();

    // loop here until we are told to exit so the user has a chance to undo
    while (!force_exit) {
        droidzebra_msg_get_user_input(side_to_move, &evt);
        if (evt.type == UI_EVENT_EXIT) {
            force_exit = 1;
            break;
        } else if (evt.type == UI_EVENT_UNDO) {
            _droidzebra_undo_turn(&side_to_move);
            // adjust for increment at the beginning of the game loop
            if (side_to_move == BLACKSQ)
                score_sheet_row--;
            goto AGAIN;
        } else if (evt.type == UI_EVENT_SETTINGS_CHANGE) {
            _droidzebra_on_settings_change();
        }
    }

    DROIDZEBRA_JNI_CLEAN;
}