void test_bit_count() { /* bitcount() */ assert(bit_count(PAWN_START_WHITE)==8); assert(bit_count(FULL_BOARD)==64); assert(bit_count(EMPTY_BOARD)==0); }
struct ir_remote *sort_by_bit_count(struct ir_remote *remotes) { struct ir_remote *top, *rem, *next, *prev, *scan; rem = remotes; top = NULL; while (rem != NULL) { next = rem->next; scan = top; prev = NULL; while (scan && bit_count(scan) <= bit_count(rem)) { prev = scan; scan = scan->next; } if (prev) { prev->next = rem; } else { top = rem; } if (scan) { rem->next = scan; } else { rem->next = NULL; } rem = next; } return top; }
void Solver :: solve () { int highest_bit_count = 0; int bc; int i; for (i = 0; i < 1; i++) { initialize_values(); find_best_Ms(); execute(); bc = 0; /* for (j = 0; j < 16; j++) { bc += M[j]->mask_count(); } if (bc > 32 * 12) { output_state(); std::cout << "FOUND M\n"; } */ if (bit_count() > highest_bit_count) { highest_bit_count = bit_count(); output_state(); } std::cout.flush(); } }
int bfd_m68k_features_to_mach (unsigned features) { int superset = 0, subset = 0; unsigned extra = 99, missing = 99; unsigned ix; for (ix = 0; ix != sizeof (m68k_arch_features) / sizeof (m68k_arch_features[0]); ix++) { unsigned this_extra, this_missing; if (m68k_arch_features[ix] == features) return ix; this_extra = bit_count (m68k_arch_features[ix] & ~features); if (this_extra < extra) { extra = this_extra; superset = ix; } this_missing = bit_count (features & ~m68k_arch_features[ix]); if (this_missing < missing) { missing = this_missing; superset = ix; } } return superset ? superset : subset; }
/** * @brief Move generator performance test function. * * @param board * @param depth * @param global_stats statistics */ static void count_game(const Board *board, const int depth, GameStatistics *global_stats) { GameStatistics stats = GAME_STATISTICS_INIT; unsigned long long moves; int x; Board next[1]; if (depth == 1) { moves = get_moves(board->player, board->opponent); stats.n_moves = stats.max_mobility = stats.min_mobility = bit_count(moves); if (moves == 0) { if (can_move(board->opponent, board->player)) { stats.n_passes = 1; } else { const int n_player = bit_count(board->player); const int n_opponent = bit_count(board->opponent); if (n_player > n_opponent) stats.n_wins = 1; else if (n_player == n_opponent) stats.n_draws = 1; else stats.n_losses = 1; } } } else { moves = get_moves(board->player, board->opponent); if (moves) { foreach_bit (x, moves) { board_next(board, x, next); count_game(next, depth - 1, &stats); } } else {
int eval_material() { int score; int whitepawns, whiteknights, whitebishops, whiterooks, whitequeens; int blackpawns, blackknights, blackbishops, blackrooks, blackqueens; whitepawns = bit_count(board.white_pawns); whiteknights = bit_count(board.white_knights); whitebishops = bit_count(board.white_bishops); whiterooks = bit_count(board.white_rooks); whitequeens = bit_count(board.white_queens); blackpawns = bit_count(board.black_pawns); blackknights = bit_count(board.black_knights); blackbishops = bit_count(board.black_bishops); blackrooks = bit_count(board.black_rooks); blackqueens = bit_count(board.black_queens); score = (whitepawns-blackpawns) + (whiteknights-blackknights) * KNIGHT_VALUE + (whitebishops-blackbishops) * BISHOP_VALUE + (whiterooks-blackrooks) * ROOK_VALUE + (whitequeens-blackqueens) * QUEEN_VALUE; if (board.color) return -score; else return +score; }
int test_base_bitset(const char* param) { rand_seed((uint32_t)time(NULL)); // bit create int size = param ? atoi(param) : rand() % 1024; bit_t* bit = bit_create(size); if (!bit) { fprintf(stderr, "bit create fail\n"); return -1; } // bit set int test_size = (size >> 1); for (int i = 0; i < test_size; ++ i) { bit_set(bit, i); } // bit is set for (int i = 0; i < size; ++ i) { if (i < test_size && bit_isset(bit, i)) { fprintf(stderr, "bit-set error\n"); bit_release(bit); return -1; } if (i >= test_size && bit_isset(bit, i) == 0) { fprintf(stderr, "bit-set error\n"); bit_release(bit); return -1; } } // bit count if (bit_count(bit) != test_size) { fprintf(stderr, "bit-count = %d error\n", bit_count(bit)); bit_release(bit); return -1; } // bit reset -> bit count for (int i = 0; i < test_size; ++ i) { bit_reset(bit, i); } if (bit_count(bit) != 0) { fprintf(stderr, "bit-count error\n"); bit_release(bit); return -1; } bit_release(bit); return 0; }
char *test_new() { a = bit_new(256); mu_assert(a != NULL, "bit_new returns NULL.\n"); mu_assert(bit_length(a) == 256, "bit_new returns wrong length.\n"); mu_assert(bit_count(a) == 0, "bit_new returns wrong count.\n"); b = bit_new(256); mu_assert(b != NULL, "bit_new returns NULL.\n"); mu_assert(bit_length(b) == 256, "bit_new returns wrong length.\n"); mu_assert(bit_count(b) == 0, "bit_new returns wrong count.\n"); return NULL; }
static Debug_Module * add_auto_module(QSP_ARG_DECL const char *name, debug_flag_t mask) { Debug_Module *dmp; /* user of savestr() eliminates a warning, but wastes some memory... */ //auto_dbm_tbl[n_debug_modules].db_name = (char *) name; dmp = new_debug(name); assert( dmp != NULL ); SET_DEBUG_MASK(dmp, mask ); SET_DEBUG_FLAGS(dmp, DEBUG_SET); // default // Don't increase the number of modules for the special choices yes/no all/none if( bit_count(mask) == 1 ){ if( mask != (1<<n_debug_modules) ){ sprintf(ERROR_STRING, "Debug module %s (mask = 0x%x) added out of sequence (n_debug_modules = %d)!?", name,mask,n_debug_modules); warn(ERROR_STRING); } n_debug_modules++; } return dmp; }
void Solver :: output_state () { int i; std::list <Word *> :: iterator it; std::cout << "GConstant " << GConstant->bit_string() << "\n"; for (i = 0; i < 16; i++) { std::cout << "M[" << i << "] " << M[i]->bit_string() << "\n"; } for (i = 0; i < 13; i++) { std::cout << "a[" << i << "] " << a[i]->bit_string() << "\n"; std::cout << "b[" << i << "] " << b[i]->bit_string() << "\n"; std::cout << "c[" << i << "] " << c[i]->bit_string() << "\n"; std::cout << "d[" << i << "] " << d[i]->bit_string() << "\n"; } for (it = this->op_words.begin(); it != this->op_words.end(); it++) { std::cout << (*it)->g_name() << " " << (*it)->bit_string() << "\n"; } std::cout << "bit_count: " << bit_count() << "\n"; }
gc_t *string_from_cache(su_state *s, const char *str, unsigned size) { value_t v; string_cache_t entry; string_cache_t *entries; unsigned hash = murmur(str, size, 0); unsigned index = (unsigned)bit_count((int)hash) - 8; int i; if (index < 16) { entries = s->string_cache[index]; for (i = 0; i < STRING_CACHE_SIZE; i++) { if (entries[i].hash == hash && !memcmp(entries[i].str->str, str, size)) return &entries[i].str->gc; } } v.type = SU_STRING; v.obj.ptr = su_allocate(s, NULL, sizeof(string_t) + size); v.obj.str->size = size; memcpy(v.obj.str->str, str, size); v.obj.str->str[size] = '\0'; v.obj.str->hash = hash; if (index < 16) { entry.hash = hash; entry.str = v.obj.str; entries[s->string_cache_head[index]] = entry; s->string_cache_head[index] = (s->string_cache_head[index] + 1) % STRING_CACHE_SIZE; } gc_insert_object(s, v.obj.gc_object, SU_STRING); return v.obj.gc_object; }
/*static*/ CRCValue<uint64> CRCValue<uint64>::check_and_create(uint64 _v){ CRCValue<uint64> crcv(_v, true); if(crcv.crc() == bit_count(crcv.value())){ return crcv; }else{ return CRCValue<uint64>(-1LL, true); } }
/*static*/ CRCValue<uint32> CRCValue<uint32>::check_and_create(uint32 _v){ CRCValue<uint32> crcv(_v, true); if(crcv.crc() == bit_count(crcv.value())){ return crcv; }else{ return CRCValue<uint32>(0xffffffff, true); } }
static void bit_object_show(void* B) { fprintf(stdout, "\t__bit__ -> {\n" "\t object=>0x%p,\n" "\t size=>%d,\n" "\t count=>%d,\n" "\t}\n", B, bit_size(B), bit_count(B) ); }
/** * @brief Initialize global hash code data. */ void hash_code_init(void) { int i, j; Random r; random_seed(&r, 0x5DEECE66Dull); for (i = 0; i < 16; ++i) for (j = 0; j < 256; ++j) { do { hash_rank[i][j] = random_get(&r); } while (bit_count(hash_rank[i][j]) < 8); } }
/** * @brief Initialize global hash move data. */ void hash_move_init(void) { int i, j; Random r; random_seed(&r, 0x5DEECE66Dull); for (i = 0; i < 64; ++i) for (j = 0; j < 60; ++j) { do { hash_move[i][j] = random_get(&r); } while (bit_count(hash_move[i][j]) < 8); } }
/* ------------------------------------------------------------------------ bitboard get_lowest_bit(bitboard *board) purpose: gets and removes the lowest bit from a bit board. Note: the bit IS REMOVED from the original bitboard. ------------------------------------------------------------------------ */ bitboard get_lowest_bit(bitboard *board) { int count = bit_count(*board); bitboard lowest_bit=0; if (count>0) { lowest_bit = (*board & ((~*board)+1)); *board = *board & ~lowest_bit; } return lowest_bit; }
int bitcnt(long long * in, int mm, int * out, int nn) { bit_count(in, mm, &out[0], nn); bitcount(in, mm, &out[1], nn); //ntbl_bitcnt(in, mm, &out[2], nn); ntbl_bitcount(in, mm, &out[2], nn); BW_btbl_bitcount(in, mm, &out[3], nn); AR_btbl_bitcount(in, mm, &out[4], nn); bit_shifter(in, mm, &out[5], nn); return mm+nn; }
main(int argc, char *argv[]) { long n; while(--argc) { int i; n = atol(*++argv); i = bit_count(n); printf("%ld contains %d bit%s set\n", n, i, plural_text(i)); } return 0; }
inline int expectzero(struct ir_remote *remote, int bit) { if (is_biphase(remote)) { int all_bits = bit_count(remote); ir_code mask; mask = ((ir_code) 1) << (all_bits - 1 - bit); if (mask & remote->rc6_mask) { if (!expectpulse(remote, 2 * remote->pzero)) { unget_rec_buffer(1); return (0); } set_pending_space(2 * remote->szero); } else { if (!expectpulse(remote, remote->pzero)) { unget_rec_buffer(1); return (0); } set_pending_space(remote->szero); } } else if (is_space_first(remote)) { if (remote->szero > 0 && !expectspace(remote, remote->szero)) { unget_rec_buffer(1); return (0); } if (remote->pzero > 0 && !expectpulse(remote, remote->pzero)) { unget_rec_buffer(2); return (0); } } else { if (!expectpulse(remote, remote->pzero)) { unget_rec_buffer(1); return (0); } if (remote->ptrail > 0) { if (!expectspace(remote, remote->szero)) { unget_rec_buffer(2); return (0); } } else { set_pending_space(remote->szero); } } return (1); }
void send_data(struct ir_remote *remote,ir_code data,int bits,int done) { int i; int all_bits = bit_count(remote); int toggle_bit_mask_bits = bits_set(remote->toggle_bit_mask); ir_code mask; data=reverse(data,bits); if(is_rcmm(remote)) { mask=(ir_code)1<<(all_bits-1-done); if(bits%2 || done%2) { return; } for(i=0;i<bits;i+=2,mask>>=2) { switch(data&3) { case 0: send_pulse(remote->pzero); send_space(remote->szero); break; /* 2 and 1 swapped due to reverse() */ case 2: send_pulse(remote->pone); send_space(remote->sone); break; case 1: send_pulse(remote->ptwo); send_space(remote->stwo); break; case 3: send_pulse(remote->pthree); send_space(remote->sthree); break; } data=data>>2; } return; } else if(is_xmp(remote))
int main(int argc, char *argv[]) { int value; printf("enter value: "); scanf("%d", &value); /* * check for -ve and limit values */ if(value < 0) { printf("%d is -ve input\n Using Brian-Kernighan's algorithm", value); printf("num of set bits= %d\n", bk_algorithm(value)); } else { int result = bit_count(value); printf("num of set bits= %d\n",result); } printf("is_Nth_bit_set for bit 3= %d\n", is_Nth_bit_set(value, 3)); }
unsigned Get_Skew::cast_ray( const Raster &raster, int row, const Fixed &dx, int dy) { unsigned bits = 0; Fixed start = 0; Fixed end = 0; Fixed width = static_cast<int>( raster.width()); int r = row; while (start < width) { end = start + dx; if (end > width) { end = width; } bits += bit_count( raster[ r] , static_cast<int>( start) , static_cast<int>( end)); start = end; r += dy; } return bits; }
size_t row_size() const { size_t row_size = (size_t)width() * (bit_count() / 8); row_size = (row_size % 4) ? row_size + 4 - row_size % 4 : row_size; return row_size; }
static struct ir_remote * read_config_recursive(FILE *f, const char *name, int depth) { char buf[LINE_LEN+1], *key, *val, *val2; int len,argc; struct ir_remote *top_rem=NULL,*rem=NULL; struct void_array codes_list,raw_codes,signals; struct ir_ncode raw_code={NULL,0,0,NULL}; struct ir_ncode name_code={NULL,0,0,NULL}; struct ir_ncode *code; int mode=ID_none; line=0; parse_error=0; LOGPRINTF(2, "parsing '%s'", name); while(fgets(buf,LINE_LEN,f)!=NULL) { line++; len=strlen(buf); if(len==LINE_LEN && buf[len-1]!='\n') { logprintf(LOG_ERR,"line %d too long in config file", line); parse_error=1; break; } if(len>0) { len--; if(buf[len]=='\n') buf[len]=0; } if(len>0) { len--; if(buf[len]=='\r') buf[len]=0; } /* ignore comments */ if(buf[0]=='#'){ continue; } key=strtok(buf, whitespace); /* ignore empty lines */ if(key==NULL) continue; val=strtok(NULL, whitespace); if(val!=NULL){ val2=strtok(NULL, whitespace); LOGPRINTF(3,"\"%s\" \"%s\"",key,val); if (strcasecmp("include",key)==0){ FILE* childFile; const char *childName; const char *fullPath; char result[FILENAME_MAX+1]; if (depth > MAX_INCLUDES) { logprintf(LOG_ERR,"error opening child file defined at %s:%d",name,line); logprintf(LOG_ERR,"too many files included"); parse_error=-1; break; } childName = lirc_parse_include(val); if (!childName){ logprintf(LOG_ERR,"error parsing child file value defined at line %d:",line); logprintf(LOG_ERR,"invalid quoting"); parse_error=-1; break; } fullPath = lirc_parse_relative(result, sizeof(result), childName, name); if (!fullPath) { logprintf(LOG_ERR,"error composing relative file path defined at line %d:",line); logprintf(LOG_ERR,"resulting path too long"); parse_error=-1; break; } childFile = fopen(fullPath, "r"); if (childFile == NULL){ logprintf(LOG_ERR,"error opening child file '%s' defined at line %d:",fullPath, line); logprintf(LOG_ERR,"ignoring this child file for now."); } else{ int save_line = line; if (!top_rem){ /* create first remote */ LOGPRINTF(2,"creating first remote"); rem = read_config_recursive(childFile, fullPath, depth + 1); if(rem != (void *) -1 && rem != NULL) { top_rem = rem; } else { rem = NULL; } }else{ /* create new remote */ LOGPRINTF(2,"creating next remote"); rem->next=read_config_recursive(childFile, fullPath, depth + 1); if(rem->next != (void *) -1 && rem->next != NULL) { rem=rem->next; } else { rem->next = NULL; } } fclose(childFile); line = save_line; } }else if (strcasecmp("begin",key)==0){ if (strcasecmp("codes", val)==0){ /* init codes mode */ LOGPRINTF(2," begin codes"); if (!checkMode(mode, ID_remote, "begin codes")) break; if (rem->codes){ logprintf(LOG_ERR,"error in configfile line %d:",line); logprintf(LOG_ERR,"codes are already defined"); parse_error=1; break; } init_void_array(&codes_list,30, sizeof(struct ir_ncode)); mode=ID_codes; }else if(strcasecmp("raw_codes",val)==0){ /* init raw_codes mode */ LOGPRINTF(2," begin raw_codes"); if(!checkMode(mode, ID_remote, "begin raw_codes")) break; if (rem->codes){ logprintf(LOG_ERR,"error in configfile line %d:",line); logprintf(LOG_ERR,"codes are already defined"); parse_error=1; break; } set_protocol(rem, RAW_CODES); raw_code.code=0; init_void_array(&raw_codes,30, sizeof(struct ir_ncode)); mode=ID_raw_codes; }else if(strcasecmp("remote",val)==0){ /* create new remote */ LOGPRINTF(1,"parsing remote"); if(!checkMode(mode, ID_none, "begin remote")) break; mode=ID_remote; if (!top_rem){ /* create first remote */ LOGPRINTF(2,"creating first remote"); rem=top_rem=s_malloc(sizeof(struct ir_remote)); }else{ /* create new remote */ LOGPRINTF(2,"creating next remote"); rem->next=s_malloc(sizeof(struct ir_remote));; rem=rem->next; } }else if(mode==ID_codes){ code=defineCode(key, val, &name_code); while(!parse_error && val2!=NULL) { struct ir_code_node *node; if(val2[0]=='#') break; /* comment */ node=defineNode(code, val2); val2=strtok(NULL, whitespace); } code->current=NULL; add_void_array(&codes_list, code); }else{ logprintf(LOG_ERR,"error in configfile line %d:",line); logprintf(LOG_ERR,"unknown section \"%s\"",val); parse_error=1; } if(!parse_error && val2!=NULL) { logprintf(LOG_WARNING,"garbage after " "'%s' token in line %d ignored", val,line); } }else if (strcasecmp("end",key)==0){ if (strcasecmp("codes", val)==0){ /* end Codes mode */ LOGPRINTF(2," end codes"); if (!checkMode(mode, ID_codes, "end codes")) break; rem->codes=get_void_array(&codes_list); mode=ID_remote; /* switch back */ }else if(strcasecmp("raw_codes",val)==0){ /* end raw codes mode */ LOGPRINTF(2," end raw_codes"); if(mode==ID_raw_name){ raw_code.signals=get_void_array(&signals); raw_code.length=signals.nr_items; if(raw_code.length%2==0) { logprintf(LOG_ERR,"error in configfile line %d:",line); logprintf(LOG_ERR,"bad signal length"); parse_error=1; } if(!add_void_array(&raw_codes, &raw_code)) break; mode=ID_raw_codes; } if(!checkMode(mode,ID_raw_codes, "end raw_codes")) break; rem->codes=get_void_array(&raw_codes); mode=ID_remote; /* switch back */ }else if(strcasecmp("remote",val)==0){ /* end remote mode */ LOGPRINTF(2,"end remote"); /* print_remote(rem); */ if (!checkMode(mode,ID_remote, "end remote")) break; if(!sanityChecks(rem)) { parse_error=1; break; } # ifdef DYNCODES if(rem->dyncodes_name==NULL) { rem->dyncodes_name=s_strdup("unknown"); } rem->dyncodes[0].name=rem->dyncodes_name; rem->dyncodes[1].name=rem->dyncodes_name; # endif /* not really necessary because we clear the alloced memory */ rem->next=NULL; rem->last_code=NULL; mode=ID_none; /* switch back */ }else if(mode==ID_codes){ code=defineCode(key, val, &name_code); while(!parse_error && val2!=NULL) { struct ir_code_node *node; if(val2[0]=='#') break; /* comment */ node=defineNode(code, val2); val2=strtok(NULL, whitespace); } code->current=NULL; add_void_array(&codes_list, code); }else{ logprintf(LOG_ERR,"error in configfile line %d:",line); logprintf(LOG_ERR,"unknown section %s",val); parse_error=1; } if(!parse_error && val2!=NULL) { logprintf(LOG_WARNING,"garbage after '%s'" " token in line %d ignored", val,line); } } else { switch (mode){ case ID_remote: argc=defineRemote(key, val, val2, rem); if(!parse_error && ((argc==1 && val2!=NULL) || (argc==2 && val2!=NULL && strtok(NULL, whitespace)!=NULL))) { logprintf(LOG_WARNING,"garbage after '%s'" " token in line %d ignored", key,line); } break; case ID_codes: code=defineCode(key, val, &name_code); while(!parse_error && val2!=NULL) { struct ir_code_node *node; if(val2[0]=='#') break; /* comment */ node=defineNode(code, val2); val2=strtok(NULL, whitespace); } code->current=NULL; add_void_array(&codes_list, code); break; case ID_raw_codes: case ID_raw_name: if(strcasecmp("name",key)==0){ LOGPRINTF(3,"Button: \"%s\"",val); if(mode==ID_raw_name) { raw_code.signals=get_void_array(&signals); raw_code.length=signals.nr_items; if(raw_code.length%2==0) { logprintf(LOG_ERR,"error in configfile line %d:",line); logprintf(LOG_ERR,"bad signal length"); parse_error=1; } if(!add_void_array(&raw_codes, &raw_code)) break; } if(!(raw_code.name=s_strdup(val))){ break; } raw_code.code++; init_void_array(&signals,50,sizeof(lirc_t)); mode=ID_raw_name; if(!parse_error && val2!=NULL) { logprintf(LOG_WARNING,"garbage after '%s'" " token in line %d ignored", key,line); } }else{ if(mode==ID_raw_codes) { logprintf(LOG_ERR,"no name for signal defined at line %d",line); parse_error=1; break; } if(!addSignal(&signals, key)) break; if(!addSignal(&signals, val)) break; if (val2){ if (!addSignal(&signals, val2)){ break; } } while ((val=strtok(NULL, whitespace))){ if (!addSignal(&signals, val)) break; } } break; } } }else if(mode==ID_raw_name){ if(!addSignal(&signals, key)){ break; } }else{ logprintf(LOG_ERR,"error in configfile line %d", line); parse_error=1; break; } if (parse_error){ break; } } if(mode!=ID_none) { switch(mode) { case ID_raw_name: if(raw_code.name!=NULL) { free(raw_code.name); if(get_void_array(&signals)!=NULL) free(get_void_array(&signals)); } case ID_raw_codes: rem->codes=get_void_array(&raw_codes); break; case ID_codes: rem->codes=get_void_array(&codes_list); break; } if(!parse_error) { logprintf(LOG_ERR,"unexpected end of file"); parse_error=1; } } if (parse_error){ static int print_error = 1; if(print_error) { logprintf(LOG_ERR, "reading of file '%s' failed", name); print_error = 0; } free_config(top_rem); if(depth == 0) print_error = 1; return((void *) -1); } /* kick reverse flag */ /* handle RC6 flag to be backwards compatible: previous RC-6 config files did not set rc6_mask */ rem=top_rem; while(rem!=NULL) { if((!is_raw(rem)) && rem->flags&REVERSE) { struct ir_ncode *codes; if(has_pre(rem)) { rem->pre_data=reverse(rem->pre_data, rem->pre_data_bits); } if(has_post(rem)) { rem->post_data=reverse(rem->post_data, rem->post_data_bits); } codes=rem->codes; while(codes->name!=NULL) { codes->code=reverse(codes->code,rem->bits); codes++; } rem->flags=rem->flags&(~REVERSE); rem->flags=rem->flags|COMPAT_REVERSE; /* don't delete the flag because we still need it to remain compatible with older versions */ } if(rem->flags&RC6 && rem->rc6_mask==0 && rem->toggle_bit>0) { int all_bits=bit_count(rem); rem->rc6_mask=((ir_code) 1)<<(all_bits-rem->toggle_bit); } if(rem->toggle_bit > 0) { int all_bits=bit_count(rem); if(has_toggle_bit_mask(rem)) { logprintf(LOG_WARNING, "%s uses both toggle_bit and " "toggle_bit_mask", rem->name); } else { rem->toggle_bit_mask=((ir_code) 1)<<(all_bits-rem->toggle_bit); } rem->toggle_bit = 0; } if(has_toggle_bit_mask(rem)) { if(!is_raw(rem) && rem->codes) { rem->toggle_bit_mask_state = (rem->codes->code & rem->toggle_bit_mask); if(rem->toggle_bit_mask_state) { /* start with state set to 0 for backwards compatibility */ rem->toggle_bit_mask_state ^= rem->toggle_bit_mask; } } } if(is_serial(rem)) { lirc_t base; if(rem->baud>0) { base=1000000/rem->baud; if(rem->pzero==0 && rem->szero==0) { rem->pzero=base; } if(rem->pone==0 && rem->sone==0) { rem->sone=base; } } if(rem->bits_in_byte==0) { rem->bits_in_byte=8; } } if(rem->min_code_repeat>0) { if(!has_repeat(rem) || rem->min_code_repeat>rem->min_repeat) { logprintf(LOG_WARNING, "invalid min_code_repeat value"); rem->min_code_repeat = 0; } } calculate_signal_lengths(rem); rem=rem->next; } top_rem = sort_by_bit_count(top_rem); # if defined(DEBUG) && !defined(DAEMONIZE) /*fprint_remotes(stderr, top_rem);*/ # endif return (top_rem); }
static int mask2prefix(struct in_addr mask) { return bit_count(ntohl(mask.s_addr)); }
int eval() { int score, square; int whitepawns, whiteknights, whitebishops, whiterooks, whitequeens, whitetotal; int blackpawns, blackknights, blackbishops, blackrooks, blackqueens, blacktotal; int totalpawns; int whitetotalmat, blacktotalmat, totalmat; int whitekingsquare, blackkingsquare; int valpawn, valknight, valbishop, valrook, valqueen; //bool opening, middlegame; endgame; bool endgame; Bitmap temp; if( hash_probe(&score) ) return score; whitepawns = bit_count(board.white_pawns); whiteknights = bit_count(board.white_knights); whitebishops = bit_count(board.white_bishops); whiterooks = bit_count(board.white_rooks); whitequeens = bit_count(board.white_queens); whitetotalmat = 3 * whiteknights + 3 * whitebishops + 5 * whiterooks + 10 * whitequeens; whitetotal = whitepawns + whiteknights + whitebishops + whiterooks + whitequeens; blackpawns = bit_count(board.black_pawns); blackknights = bit_count(board.black_knights); blackbishops = bit_count(board.black_bishops); blackrooks = bit_count(board.black_rooks); blackqueens = bit_count(board.black_queens); blacktotalmat = 3 * blackknights + 3 * blackbishops + 5 * blackrooks + 10 * blackqueens; blacktotal = blackpawns + blackknights + blackbishops + blackrooks + blackqueens; // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Remember where the kings are // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (board.white_king) { whitekingsquare = first_one(board.white_king); } else { return (board.color) ? MATESCORE : -MATESCORE; } if (board.black_king) { blackkingsquare = first_one(board.black_king); } else { return (board.color) ? -MATESCORE : +MATESCORE; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate for draws due to insufficient material: // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (!whitepawns && !blackpawns) { // king versus king: if ((whitetotalmat == 0) && (blacktotalmat == 0)) { if (board.color) { return -DRAWSCORE; } else { return DRAWSCORE; } } // king and knight versus king: if (((whitetotalmat == 3) && (whiteknights == 1) && (blacktotalmat == 0)) || ((blacktotalmat == 3) && (blackknights == 1) && (whitetotalmat == 0))) { if (board.color) { return -DRAWSCORE; } else { return DRAWSCORE; } } // 2 kings with one or more bishops, and all bishops on the same colour: if ((whitebishops + blackbishops) > 0) { if ((whiteknights == 0) && (whiterooks == 0) && (whitequeens == 0) && (blackknights == 0) && (blackrooks == 0) && (blackqueens == 0)) { if (!((board.white_bishops | board.black_bishops) & WHITE_SQUARES) || !((board.white_bishops | board.black_bishops) & BLACK_SQUARES)) { return DRAWSCORE; } } } } // ---------------------------------------------------------------------------- // Value of pieces // ---------------------------------------------------------------------------- totalpawns = whitepawns + blackpawns; // closed positions - 13-16 ps left if( totalpawns >= 13 ) { valqueen = QUEEN_VALUE*90/100; valrook = ROOK_VALUE*85/100; valbishop = BISHOP_VALUE; valknight = KNIGHT_VALUE*110/100; } // semi-closed positions - 9-12 ps left else if( totalpawns >= 9) { valqueen = QUEEN_VALUE*95/100; valrook = ROOK_VALUE*90/100; valbishop = BISHOP_VALUE*105/100; valknight = KNIGHT_VALUE*110/100; } // semi-open positions - 5-8 ps else if( totalpawns >= 5) { valqueen = QUEEN_VALUE*120/100; valrook = ROOK_VALUE*110/100; valbishop = BISHOP_VALUE*115/100; valknight = KNIGHT_VALUE*90/100; } // open positions - 0-4 ps else { valqueen = QUEEN_VALUE*130/100; valrook = ROOK_VALUE*110/100; valbishop = BISHOP_VALUE*120/100; valknight = KNIGHT_VALUE*85/100; } // Grading of pawns // Pawns will be graded in relation to the pieces left on the board (defining middlegame or // endgame; if 60 is the overall piece strength, then middlegame starts from 30 piece strength // upwards, and endgame downwards). It is obvious that with decreasing piece strength left ps // become gradually more powerful, in respect to their structure, passer status and influence on // the board. // Pawns might be graded in four categories in decreasing order: // Piece strength 60-45 - no change from standard value // Piece strength 45-30 - +5% standard value // Piece strength 30-15 - +10% standard value // Piece strength 15-0 - +15% totalmat = whitetotalmat+blacktotalmat; if( totalmat >= 48 ) valpawn = PAWN_VALUE; else if( totalmat >= 32 ) valpawn = PAWN_VALUE*105/100; else if( totalmat >= 16 ) valpawn = PAWN_VALUE*110/100; else valpawn = PAWN_VALUE*115/100; // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Check if we are in the endgame // Anything less than a queen (=10) + rook (=5) is considered endgame // (pawns excluded in this count) // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ endgame = (whitetotalmat < 15 || blacktotalmat < 15); // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate MATERIAL // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ score = (whitepawns-blackpawns) * valpawn + (whiteknights-blackknights) * valknight + (whitebishops-blackbishops) * valbishop + (whiterooks-blackrooks) * valrook + (whitequeens-blackqueens) * valqueen; // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Have the winning side prefer to exchange pieces // Every exchange with unequal material adds 3 centipawns to the score // Loosing a piece (from balanced material) becomes more // severe in the endgame // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (whitetotalmat + whitepawns > blacktotalmat + blackpawns) { score += 45 + 3 * whitetotal - 6 * blacktotal; } else if (whitetotalmat + whitepawns < blacktotalmat + blackpawns) { score += -45 - 3 * blacktotal + 6 * whitetotal; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate WHITE PIECES // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate white pawns // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.white_pawns; while (temp) { square = first_one(temp); // - position on the board score += PAWNPOS_W[square]; // - distance from opponent king score += PAWN_OPPONENT_DISTANCE[DISTANCE[square][blackkingsquare]]; // - distance from own king if (endgame) score += PAWN_OWN_DISTANCE[DISTANCE[square][whitekingsquare]]; // - passed, doubled, isolated or backward pawns if (!(PASSED_WHITE[square] & board.black_pawns)) score += BONUS_PASSED_PAWN; if (board.white_pawns & PASSED_WHITE[square]) score -= PENALTY_DOUBLED_PAWN; temp ^= BITSET[square]; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate white knights // - position on the board // - distance from opponent king // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.white_knights; while (temp) { square = first_one(temp); score += KNIGHTPOS_W[square]; score += KNIGHT_DISTANCE[DISTANCE[square][blackkingsquare]]; temp ^= BITSET[square]; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate white bishops // - having the pair // - position on the board // - distance from opponent king // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.white_bishops; if (temp && (temp & WHITE_SQUARES) && (temp & BLACK_SQUARES)) score += BONUS_BISHOP_PAIR; while (temp) { square = first_one(temp); score += BISHOPPOS_W[square]; score += BISHOP_DISTANCE[DISTANCE[square][blackkingsquare]]; temp ^= BITSET[square]; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate white rooks // - position on the board // - distance from opponent king // - on the same file as a passed pawn // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.white_rooks; while (temp) { square = first_one(temp); score += ROOKPOS_W[square]; score += ROOK_DISTANCE[DISTANCE[square][blackkingsquare]]; temp ^= BITSET[square]; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate white queens // - position on the board // - distance from opponent king // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.white_queens; while (temp) { square = first_one(temp); score += QUEENPOS_W[square]; score += QUEEN_DISTANCE[DISTANCE[square][blackkingsquare]]; temp ^= BITSET[square]; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate the white king // - position on the board // - proximity to the pawns // - pawn shield (not in the endgame) // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (endgame) { score += KINGPOS_ENDGAME_W[whitekingsquare]; } else { score += KINGPOS_W[whitekingsquare]; score += BONUS_PAWN_SHIELD_STRONG * bit_count(KINGSHIELD_STRONG_W[whitekingsquare] & board.white_pawns); score += BONUS_PAWN_SHIELD_WEAK * bit_count(KINGSHIELD_WEAK_W[whitekingsquare] & board.white_pawns); } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate BLACK PIECES // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate black pawns // - position on the board // - distance from opponent king // - distance from own king // - passed, doubled, isolated or backward pawns // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.black_pawns; while (temp) { square = first_one(temp); score -= PAWNPOS_B[square]; temp ^= BITSET[square]; // - distance from opponent king score += PAWN_OPPONENT_DISTANCE[DISTANCE[square][whitekingsquare]]; // - distance from own king if (endgame) score += PAWN_OWN_DISTANCE[DISTANCE[square][blackkingsquare]]; // - passed, doubled, isolated or backward pawns if (!(PASSED_WHITE[square] & board.white_pawns)) score += BONUS_PASSED_PAWN; if (board.black_pawns & PASSED_WHITE[square]) score -= PENALTY_DOUBLED_PAWN; square = first_one(temp); } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate black knights // - position on the board // - distance from opponent king // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.black_knights; while (temp) { square = first_one(temp); score -= KNIGHTPOS_B[square]; score -= KNIGHT_DISTANCE[DISTANCE[square][whitekingsquare]]; temp ^= BITSET[square]; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate black bishops // - having the pair // - position on the board // - distance from opponent king // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.black_bishops; if (temp && (temp & WHITE_SQUARES) && (temp & BLACK_SQUARES)) score -= BONUS_BISHOP_PAIR; while (temp) { square = first_one(temp); score -= BISHOPPOS_B[square]; score -= BISHOP_DISTANCE[DISTANCE[square][whitekingsquare]]; temp ^= BITSET[square]; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate black rooks // - position on the board // - distance from opponent king // - on the same file as a passed pawn // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.black_rooks; while (temp) { square = first_one(temp); score -= ROOKPOS_B[square]; score -= ROOK_DISTANCE[DISTANCE[square][whitekingsquare]]; temp ^= BITSET[square]; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate black queens // - position on the board // - distance from opponent king // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ temp = board.black_queens; while (temp) { square = first_one(temp); score -= QUEENPOS_B[square]; score -= QUEEN_DISTANCE[DISTANCE[square][whitekingsquare]]; temp ^= BITSET[square]; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Evaluate the black king // - position on the board // - proximity to the pawns // - pawn shield (not in the endgame) // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (endgame) { score -= KINGPOS_ENDGAME_B[blackkingsquare]; } else { score -= KINGPOS_B[blackkingsquare]; score -= BONUS_PAWN_SHIELD_STRONG * bit_count(KINGSHIELD_STRONG_B[blackkingsquare] & board.black_pawns); score -= BONUS_PAWN_SHIELD_WEAK * bit_count(KINGSHIELD_WEAK_B[blackkingsquare] & board.black_pawns); } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Return the score // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ if (board.color) { score = -score; } hash_save(score); return score; }
Ipp32s best_codebooks_search(sEnc_individual_channel_stream* pStream, Ipp16s *px_quant_unsigned, Ipp16s *px_quant_signed, Ipp16s *px_quant_unsigned_pred, Ipp16s *px_quant_signed_pred) { Ipp32s *sfb_offset; Ipp32s *pred_flag; Ipp16s *p_sfb_cb; Ipp32u index; #if !defined(ANDROID) Ipp32s sfb_bit_len[MAX_SFB][12]; Ipp32s sfb_bit_len1[MAX_SFB][12]; Ipp32s cb_trace[MAX_SFB][12]; Ipp32s isPred[MAX_SFB][12]; #else static Ipp32s sfb_bit_len[MAX_SFB][12]; static Ipp32s sfb_bit_len1[MAX_SFB][12]; static Ipp32s cb_trace[MAX_SFB][12]; static Ipp32s isPred[MAX_SFB][12]; #endif Ipp32s min_value, min_value_pred; Ipp32s sect_bits; Ipp32s len_esc_value; Ipp32s pred, side_info, predPresent; Ipp32s bits_for_changes, win, sfb, i, j; side_info = predPresent = min_value_pred = min_value = 0; pred_flag = NULL; if (pStream->windows_sequence == EIGHT_SHORT_SEQUENCE) { len_esc_value = 3; } else { len_esc_value = 5; } pred = 0; if (px_quant_unsigned_pred) { pred = 1; if (pStream->audioObjectType == AOT_AAC_LTP) { Ipp32s max_sfb = pStream->max_sfb; if (max_sfb > MAX_LTP_SFB_LONG) max_sfb = MAX_LTP_SFB_LONG; pred_flag = pStream->ltp_long_used; side_info = 1 + 11 + 3 + max_sfb; } } sfb_offset = pStream->sfb_offset; p_sfb_cb = pStream->sfb_cb; bits_for_changes = 4 + len_esc_value; sect_bits = 0; for (win = 0; win < pStream->num_window_groups; win++) { predPresent = 0; #if 1 bit_count(pStream, px_quant_unsigned, px_quant_signed, sfb_offset, sfb_bit_len); #else if (px_quant_signed[0]>0){ px_quant_signed[0] = px_quant_signed[0]; } ippsVLCCountBits_AAC_16s32s(px_quant_unsigned, px_quant_signed, (const Ipp32u*)sfb_offset, (Ipp32s*)sfb_bit_len, pStream->max_sfb, (const IppsVLCEncodeSpec_32s**) pStream->pHuffTables); #endif if (pred) { #if 1 bit_count(pStream, px_quant_unsigned_pred, px_quant_signed_pred, sfb_offset, sfb_bit_len1); #else ippsVLCCountBits_AAC_16s32s(px_quant_unsigned_pred, px_quant_signed_pred, (const Ipp32u*)sfb_offset, (Ipp32s*)sfb_bit_len1, pStream->max_sfb, (const IppsVLCEncodeSpec_32s**) pStream->pHuffTables); #endif for (i = 0; i < pStream->max_sfb; i++) { for (j = 0; j < 12; j++) { if (sfb_bit_len[i][j] <= sfb_bit_len1[i][j]) { sfb_bit_len1[i][j] = sfb_bit_len[i][j]; isPred[i][j] = 0; } else { isPred[i][j] = 1; } } } tree_build(sfb_bit_len1, cb_trace, pStream->max_sfb, len_esc_value); #if 0 ippsMinIndx_32s(sfb_bit_len1[pStream->max_sfb - 1], 12, &min_value_pred, &index); #else min_value_pred = sfb_bit_len1[pStream->max_sfb - 1][0]; index = 0; for ( i = 1; i < 12; i++ ) { if ( sfb_bit_len1[pStream->max_sfb - 1][i] < min_value_pred ) { min_value_pred = sfb_bit_len1[pStream->max_sfb - 1][i]; index = i; } } #endif predPresent = 0; p_sfb_cb[pStream->max_sfb - 1] = (Ipp16s)index; pred_flag[pStream->max_sfb - 1] = isPred[pStream->max_sfb - 1][index]; predPresent |= pred_flag[pStream->max_sfb - 1]; for (sfb = pStream->max_sfb - 2; sfb >= 0; sfb--) { index = cb_trace[sfb][index]; p_sfb_cb[sfb] = (Ipp16s)index; pred_flag[sfb] = isPred[sfb][index]; predPresent |= pred_flag[sfb]; } if (predPresent == 0) { min_value = min_value_pred; } else { min_value_pred += side_info; } } if ((!pred) || predPresent) { tree_build(sfb_bit_len, cb_trace, pStream->max_sfb, len_esc_value); #if 0 ippsMinIndx_32s(sfb_bit_len[pStream->max_sfb - 1], 12, &min_value, &index); #else min_value = sfb_bit_len[pStream->max_sfb - 1][0]; index = 0; for ( i = 1; i < 12; i++ ) { if ( sfb_bit_len[pStream->max_sfb - 1][i] < min_value ) { min_value = sfb_bit_len[pStream->max_sfb - 1][i]; index = i; } } #endif if (pred) { if (min_value < min_value_pred) { predPresent = 0; p_sfb_cb[pStream->max_sfb - 1] = (Ipp16s)index; for (sfb = pStream->max_sfb - 2; sfb >= 0; sfb--) { index = cb_trace[sfb][index]; p_sfb_cb[sfb] = (Ipp16s)index; } } else { min_value = min_value_pred; } } else { p_sfb_cb[pStream->max_sfb - 1] = (Ipp16s)index; for (sfb = pStream->max_sfb - 2; sfb >= 0; sfb--) { index = cb_trace[sfb][index]; p_sfb_cb[sfb] = (Ipp16s)index; } } } sect_bits += min_value + bits_for_changes; sfb_offset += pStream->max_sfb; p_sfb_cb += pStream->max_sfb; } if (pred) { if (pStream->audioObjectType == AOT_AAC_LTP) { pStream->ltp_data_present = predPresent; } } return (sect_bits); }
inline void send_data(struct ir_remote *remote,ir_code data,int bits,int done) { int i; int all_bits = bit_count(remote); ir_code mask; if(is_rcmm(remote)) { data=reverse(data,bits); mask=1<<(all_bits-1-done); if(bits%2 || done%2) { logprintf(LOG_ERR,"invalid bit number."); return; } for(i=0;i<bits;i+=2,mask>>=2) { switch(data&3) { case 0: send_pulse(remote->pzero); send_space(remote->szero); break; /* 2 and 1 swapped due to reverse() */ case 2: send_pulse(remote->pone); send_space(remote->sone); break; case 1: send_pulse(remote->ptwo); send_space(remote->stwo); break; case 3: send_pulse(remote->pthree); send_space(remote->sthree); break; } data=data>>2; } return; } data=reverse(data,bits); mask=((ir_code) 1)<<(all_bits-1-done); for(i=0;i<bits;i++,mask>>=1) { if(has_toggle_bit_mask(remote) && mask&remote->toggle_bit_mask) { data &= ~((ir_code) 1); if(remote->toggle_bit_mask_state&mask) { data |= (ir_code) 1; } } if(has_toggle_mask(remote) && mask&remote->toggle_mask && remote->toggle_mask_state%2) { data ^= 1; } if(data&1) { if(is_biphase(remote)) { if(mask&remote->rc6_mask) { send_space(2*remote->sone); send_pulse(2*remote->pone); } else { send_space(remote->sone); send_pulse(remote->pone); } } else if(is_space_first(remote)) { send_space(remote->sone); send_pulse(remote->pone); } else { send_pulse(remote->pone); send_space(remote->sone); } } else { if(mask&remote->rc6_mask) { send_pulse(2*remote->pzero); send_space(2*remote->szero); } else if(is_space_first(remote)) { send_space(remote->szero); send_pulse(remote->pzero); } else { send_pulse(remote->pzero); send_space(remote->szero); } } data=data>>1; } }
/* sl == steps left */ int eval(int sl, BOARD_AS_PARAMETER) { int sum = 0, i,j; uint64_t figs[2][6] = {{gr, gc, gd, gh, gm, ge}, {sr, sc, sd, sh, sm, se}}; uint64_t whole[2] = {gr|gc|gd|gh|gm|ge, sr|sc|sd|sh|sm|se}; uint64_t tmpG, tmpS, tmpG2, tmpS2, tmp1, tmp2; const int trap_control[5] = {0, 60, 100, 50, 20}; /* Win or Loose */ if (player == GOLD) { if ((gr & UPPER_SIDE) || !sr) return INFINITY; if ((sr & BOTTOM_SIDE) || !gr) return -INFINITY; #ifndef noGoalCheck if (sl && goalCheck(player, sl, figs)) return INFINITY; #endif } else { if ((sr & BOTTOM_SIDE) || !gr) return -INFINITY; if ((gr & UPPER_SIDE) || !sr) return INFINITY; #ifndef noGoalCheck if (sl && goalCheck(player, sl, figs)) return -INFINITY; #endif } /* Material and position */ sum += material_and_position_g(gr,gc,gd,gh,gm,ge, RABBIT_WEIGHT(gr)) - material_and_position_s(sr,sc,sd,sh,sm,se, RABBIT_WEIGHT(sr)); /* Having the strongest & the second strongest piece advantage */ for (i=5, j=2; i>0 && j; i--) { /* Only two biggest */ j -= !!figs[GOLD][i] | !!figs[SILVER][i]; /* If one of them has big advantage */ if ((!!figs[GOLD][i]) ^ (!!figs[SILVER][i])) sum += (figs[GOLD][i] ? 1 : -1) * weight_table[i]; } /* Controling traps */ #define traps_quantity_advantage(n) \ ( trap_control[bit_count(AROUND_NW_TRAP & whole[n])] \ + trap_control[bit_count(AROUND_NE_TRAP & whole[n])] \ + trap_control[bit_count(AROUND_SW_TRAP & whole[n])] \ + trap_control[bit_count(AROUND_SE_TRAP & whole[n])]) sum += traps_quantity_advantage(GOLD) - traps_quantity_advantage(SILVER); /* TODO count in stronger piece advantage around traps */ tmpG = tmpS = 0; tmpG2 = whole[ GOLD]; tmpS2 = whole[SILVER]; for (i=0; i<6; i++) { tmpG2 ^= figs[ GOLD][i]; tmpS2 ^= figs[SILVER][i]; /* Possibility to be pushed/pulled */ sum -= bit_count(adjecent(figs[ GOLD][i]) & tmpS2) * weight_table[i]/15 - bit_count(adjecent(figs[SILVER][i]) & tmpG2) * weight_table[i]/15; /* Cannot move */ tmp1 = adjecent(tmpS2) & figs[ GOLD][i]; tmp2 = adjecent(tmpG2) & figs[SILVER][i]; while (tmp1) { sum -= (!(adjecentOne(tmp1 & (-tmp1)) & whole[GOLD])) * weight_table[i]/10; tmp1 ^= tmp1 & (-tmp1); } while (tmp2) { sum += (!(adjecentOne(tmp2 & (-tmp2)) & whole[SILVER])) * weight_table[i]/10; tmp2 ^= tmp2 & (-tmp2); } /* b & (-b) is right most bit */ tmpG |= figs[ GOLD][i]; tmpS |= figs[SILVER][i]; } return sum; }