static VALUE count_tdata_objects(int argc, VALUE *argv, VALUE self) { VALUE hash = setup_hash(argc, argv); rb_objspace_each_objects(cto_i, (void *)hash); return hash; }
static VALUE count_objects_size(int argc, VALUE *argv, VALUE os) { size_t counts[T_MASK+1]; size_t total = 0; enum ruby_value_type i; VALUE hash = setup_hash(argc, argv); for (i = 0; i <= T_MASK; i++) { counts[i] = 0; } rb_objspace_each_objects(cos_i, &counts[0]); if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } for (i = 0; i <= T_MASK; i++) { if (counts[i]) { VALUE type = type2sym(i); total += counts[i]; rb_hash_aset(hash, type, SIZET2NUM(counts[i])); } } rb_hash_aset(hash, ID2SYM(rb_intern("TOTAL")), SIZET2NUM(total)); return hash; }
Ewl_Widget * ewl_io_manager_plugin_uri_read(const char *uri) { Ewl_Widget *ret = NULL; FILE *file; DENTER_FUNCTION(DLEVEL_STABLE); DCHECK_PARAM_PTR_RET(uri, NULL); if (!key1) setup_hash(); file = fopen(uri, "r"); if (file) { struct stat buf; char *str; ret = ewl_text_new(); ewl_text_font_set(EWL_TEXT(ret), "ewl/monospace"); stat(uri, &buf); str = malloc(sizeof(char) * (buf.st_size + 1)); fread(str, buf.st_size, 1, file); str[buf.st_size] = '\0'; fclose(file); text_set(EWL_TEXT(ret), str); FREE(str); } DRETURN_PTR(ret, DLEVEL_STABLE); }
Ewl_Widget * ewl_io_manager_plugin_string_read(const char *string) { Ewl_Widget *ret = NULL; char *txt; DENTER_FUNCTION(DLEVEL_STABLE); if (!key1) setup_hash(); ret = ewl_text_new(); ewl_text_font_set(EWL_TEXT(ret), "ewl/monospace"); txt = strdup(string); text_set(EWL_TEXT(ret), txt); free(txt); DRETURN_PTR(ret, DLEVEL_STABLE); }
static VALUE count_imemo_objects(int argc, VALUE *argv, VALUE self) { VALUE hash = setup_hash(argc, argv); if (imemo_type_ids[0] == 0) { imemo_type_ids[0] = rb_intern("imemo_none"); imemo_type_ids[1] = rb_intern("imemo_cref"); imemo_type_ids[2] = rb_intern("imemo_svar"); imemo_type_ids[3] = rb_intern("imemo_throw_data"); imemo_type_ids[4] = rb_intern("imemo_ifunc"); imemo_type_ids[5] = rb_intern("imemo_memo"); imemo_type_ids[6] = rb_intern("imemo_ment"); imemo_type_ids[7] = rb_intern("imemo_iseq"); } rb_objspace_each_objects(count_imemo_objects_i, (void *)hash); return hash; }
static VALUE count_symbols(int argc, VALUE *argv, VALUE os) { struct dynamic_symbol_counts dynamic_counts = {0, 0}; VALUE hash = setup_hash(argc, argv); size_t immortal_symbols = rb_sym_immortal_count(); rb_objspace_each_objects(cs_i, &dynamic_counts); if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } rb_hash_aset(hash, ID2SYM(rb_intern("mortal_dynamic_symbol")), SIZET2NUM(dynamic_counts.mortal)); rb_hash_aset(hash, ID2SYM(rb_intern("immortal_dynamic_symbol")), SIZET2NUM(dynamic_counts.immortal)); rb_hash_aset(hash, ID2SYM(rb_intern("immortal_static_symbol")), SIZET2NUM(immortal_symbols - dynamic_counts.immortal)); rb_hash_aset(hash, ID2SYM(rb_intern("immortal_symbol")), SIZET2NUM(immortal_symbols)); return hash; }
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; }
void keyboard_manager::register_done () { setup_hash (); }
void setup_position(char* fen) { ply = begin_ply; turn_to_move = WHITE; ply->en_passant = 0; ply->castlings = 0; ply->number_of_insignificant_plies = 0; for(int i = 0; i < 120; i += 1) board[i] = BORDER; for(int i = 0; i < 64; i += 1) board[board64[i]] = EMPTY; int i = 0; int current_cell = 0; for(; fen[i] != ' ' && fen[i] != '\0'; i += 1, current_cell += 1) { int index_of_figure = board64[current_cell]; switch(fen[i]) { case '/': current_cell -= 1; break; case 'K': place_of_white_king = index_of_figure; board[index_of_figure] = create_figure(WHITE, KING); break; case 'Q': board[index_of_figure] = create_figure(WHITE, QUEEN); break; case 'R': board[index_of_figure] = create_figure(WHITE, ROOK); break; case 'B': board[index_of_figure] = create_figure(WHITE, BISHOP); break; case 'N': board[index_of_figure] = create_figure(WHITE, KNIGHT); break; case 'P': board[index_of_figure] = create_figure(WHITE, PAWN); break; case 'k': place_of_black_king = index_of_figure; board[index_of_figure] = create_figure(BLACK, KING); break; case 'q': board[index_of_figure] = create_figure(BLACK, QUEEN); break; case 'r': board[index_of_figure] = create_figure(BLACK, ROOK); break; case 'b': board[index_of_figure] = create_figure(BLACK, BISHOP); break; case 'n': board[index_of_figure] = create_figure(BLACK, KNIGHT); break; case 'p': board[index_of_figure] = create_figure(BLACK, PAWN); break; default: current_cell += fen[i] - '0' - 1; } } if(fen[i] == '\0') { setup_hash(); return; } i += 1; if(fen[i] == 'w') turn_to_move = WHITE; else if(fen[i] == 'b') turn_to_move = BLACK; i += 1; if(fen[i] == '\0') { setup_hash(); return; } i += 1; for(; fen[i] != ' ' && fen[i] != '\0'; i += 1) { switch(fen[i]) { case 'K': ply->castlings |= K_castling; break; case 'Q': ply->castlings |= Q_castling; break; case 'k': ply->castlings |= k_castling; break; case 'q': ply->castlings |= q_castling; break; } } if(fen[i] == '\0') { setup_hash(); return; } i += 1; if(fen[i] == '-') i += 1; else { ply->en_passant = ('8' - fen[i + 1] + 2) * 10 + fen[i] - 'a' + 1; i += 2; } if(fen[i] == '\0') { setup_hash(); return; } i += 1; if(fen[i + 1] == ' ' || fen[i + 1] == '\0') ply->number_of_insignificant_plies = fen[i] - '0'; else ply->number_of_insignificant_plies = ((fen[i] - '0') * 10 + fen[i + 1] - '0'); setup_hash(); }
static VALUE count_nodes(int argc, VALUE *argv, VALUE os) { size_t nodes[NODE_LAST+1]; size_t i; VALUE hash = setup_hash(argc, argv); for (i = 0; i <= NODE_LAST; i++) { nodes[i] = 0; } rb_objspace_each_objects(cn_i, &nodes[0]); if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } for (i=0; i<NODE_LAST; i++) { if (nodes[i] != 0) { VALUE node; switch (i) { #define COUNT_NODE(n) case n: node = ID2SYM(rb_intern(#n)); break; COUNT_NODE(NODE_SCOPE); COUNT_NODE(NODE_BLOCK); COUNT_NODE(NODE_IF); COUNT_NODE(NODE_CASE); COUNT_NODE(NODE_WHEN); COUNT_NODE(NODE_OPT_N); COUNT_NODE(NODE_WHILE); COUNT_NODE(NODE_UNTIL); COUNT_NODE(NODE_ITER); COUNT_NODE(NODE_FOR); COUNT_NODE(NODE_BREAK); COUNT_NODE(NODE_NEXT); COUNT_NODE(NODE_REDO); COUNT_NODE(NODE_RETRY); COUNT_NODE(NODE_BEGIN); COUNT_NODE(NODE_RESCUE); COUNT_NODE(NODE_RESBODY); COUNT_NODE(NODE_ENSURE); COUNT_NODE(NODE_AND); COUNT_NODE(NODE_OR); COUNT_NODE(NODE_MASGN); COUNT_NODE(NODE_LASGN); COUNT_NODE(NODE_DASGN); COUNT_NODE(NODE_DASGN_CURR); COUNT_NODE(NODE_GASGN); COUNT_NODE(NODE_IASGN); COUNT_NODE(NODE_IASGN2); COUNT_NODE(NODE_CDECL); COUNT_NODE(NODE_CVASGN); COUNT_NODE(NODE_CVDECL); COUNT_NODE(NODE_OP_ASGN1); COUNT_NODE(NODE_OP_ASGN2); COUNT_NODE(NODE_OP_ASGN_AND); COUNT_NODE(NODE_OP_ASGN_OR); COUNT_NODE(NODE_OP_CDECL); COUNT_NODE(NODE_CALL); COUNT_NODE(NODE_FCALL); COUNT_NODE(NODE_VCALL); COUNT_NODE(NODE_SUPER); COUNT_NODE(NODE_ZSUPER); COUNT_NODE(NODE_ARRAY); COUNT_NODE(NODE_ZARRAY); COUNT_NODE(NODE_VALUES); COUNT_NODE(NODE_HASH); COUNT_NODE(NODE_RETURN); COUNT_NODE(NODE_YIELD); COUNT_NODE(NODE_LVAR); COUNT_NODE(NODE_DVAR); COUNT_NODE(NODE_GVAR); COUNT_NODE(NODE_IVAR); COUNT_NODE(NODE_CONST); COUNT_NODE(NODE_CVAR); COUNT_NODE(NODE_NTH_REF); COUNT_NODE(NODE_BACK_REF); COUNT_NODE(NODE_MATCH); COUNT_NODE(NODE_MATCH2); COUNT_NODE(NODE_MATCH3); COUNT_NODE(NODE_LIT); COUNT_NODE(NODE_STR); COUNT_NODE(NODE_DSTR); COUNT_NODE(NODE_XSTR); COUNT_NODE(NODE_DXSTR); COUNT_NODE(NODE_EVSTR); COUNT_NODE(NODE_DREGX); COUNT_NODE(NODE_DREGX_ONCE); COUNT_NODE(NODE_ARGS); COUNT_NODE(NODE_ARGS_AUX); COUNT_NODE(NODE_OPT_ARG); COUNT_NODE(NODE_KW_ARG); COUNT_NODE(NODE_POSTARG); COUNT_NODE(NODE_ARGSCAT); COUNT_NODE(NODE_ARGSPUSH); COUNT_NODE(NODE_SPLAT); COUNT_NODE(NODE_TO_ARY); COUNT_NODE(NODE_BLOCK_ARG); COUNT_NODE(NODE_BLOCK_PASS); COUNT_NODE(NODE_DEFN); COUNT_NODE(NODE_DEFS); COUNT_NODE(NODE_ALIAS); COUNT_NODE(NODE_VALIAS); COUNT_NODE(NODE_UNDEF); COUNT_NODE(NODE_CLASS); COUNT_NODE(NODE_MODULE); COUNT_NODE(NODE_SCLASS); COUNT_NODE(NODE_COLON2); COUNT_NODE(NODE_COLON3); COUNT_NODE(NODE_DOT2); COUNT_NODE(NODE_DOT3); COUNT_NODE(NODE_FLIP2); COUNT_NODE(NODE_FLIP3); COUNT_NODE(NODE_SELF); COUNT_NODE(NODE_NIL); COUNT_NODE(NODE_TRUE); COUNT_NODE(NODE_FALSE); COUNT_NODE(NODE_ERRINFO); COUNT_NODE(NODE_DEFINED); COUNT_NODE(NODE_POSTEXE); COUNT_NODE(NODE_ALLOCA); COUNT_NODE(NODE_BMETHOD); COUNT_NODE(NODE_DSYM); COUNT_NODE(NODE_ATTRASGN); COUNT_NODE(NODE_PRELUDE); COUNT_NODE(NODE_LAMBDA); #undef COUNT_NODE default: node = INT2FIX(i); } rb_hash_aset(hash, node, SIZET2NUM(nodes[i])); } } return hash; }