/* Update checker's state */ void update_svr_checker_state(int alive, checker_id_t cid, virtual_server *vs, real_server *rs) { element e; list l = rs->failed_checkers; checker_id_t *id; /* Handle alive state. Depopulate failed_checkers and call * perform_svr_state() independently, letting the latter sort * things out itself. */ if (alive) { /* Remove the succeeded check from failed_checkers list. */ for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { id = ELEMENT_DATA(e); if (*id == cid) { free_list_element(l, e); /* If we don't break, the next iteration will trigger * a SIGSEGV. */ break; } } if (LIST_SIZE(l) == 0) perform_svr_state(alive, vs, rs); } /* Handle not alive state */ else { id = (checker_id_t *) MALLOC(sizeof(checker_id_t)); *id = cid; list_add(l, id); if (LIST_SIZE(l) == 1) perform_svr_state(alive, vs, rs); } }
void list_filter(list_t * list, board_t * board, move_test_t test, bool keep) { int pos; int i, move, value; ASSERT(list!=NULL); ASSERT(board!=NULL); ASSERT(test!=NULL); ASSERT(keep==true||keep==false); pos = 0; for (i = 0; i < LIST_SIZE(list); i++) { ASSERT(pos>=0&&pos<=i); move = LIST_MOVE(list,i); value = LIST_VALUE(list,i); if ((*test)(move,board) == keep) { list->move[pos] = move; list->value[pos] = value; pos++; } } ASSERT(pos>=0&&pos<=LIST_SIZE(list)); list->size = pos; // debug ASSERT(list_is_ok(list)); }
static bool get_dvbc_tune_params(uint16_t service_id, struct dvb_frontend_parameters *out) { char line[1024]; unsigned int freq; char inv[32]; unsigned int sr; char fec[32]; char mod[32]; unsigned int id; int len; while(!feof(_channels)) { if(fgets(line, sizeof(line), _channels) == NULL || sscanf(line, "%*[^:]:%u:%32[^:]:%u:%32[^:]:%32[^:]:%*[^:]:%*[^:]:%u", &freq, inv, &sr, fec, mod, &id) != 6 || id != service_id) continue; /* chop off trailing \n */ len = strlen(line) - 1; while(len >= 0 && line[len] == '\n') line[len--] = '\0'; verbose("%s", line); out->frequency = freq; out->inversion = str2enum(inv, inversion_list, LIST_SIZE(inversion_list)); out->u.qam.symbol_rate = sr; out->u.qam.fec_inner = str2enum(fec, fec_list, LIST_SIZE(fec_list)); out->u.qam.modulation = str2enum(mod, qam_list, LIST_SIZE(qam_list)); return true; } return false; }
static bool get_atsc_tune_params(uint16_t service_id, struct dvb_frontend_parameters *out) { char line[1024]; unsigned int freq; char mod[32]; unsigned int id; int len; while(!feof(_channels)) { if(fgets(line, sizeof(line), _channels) == NULL || sscanf(line, "%*[^:]:%u:%32[^:]:%*[^:]:%*[^:]:%u", &freq, mod, &id) != 3 || id != service_id) continue; /* chop off trailing \n */ len = strlen(line) - 1; while(len >= 0 && line[len] == '\n') line[len--] = '\0'; verbose("%s", line); out->frequency = freq; /* out->inversion is not set by azap */ out->u.vsb.modulation = str2enum(mod, qam_list, LIST_SIZE(qam_list)); return true; } return false; }
static void note_quiet_moves(list_t * list, const board_t * board, bool in_pv, int ThreadId) { int size; int i, move; int move_piece; ASSERT(list_is_ok(list)); ASSERT(board!=NULL); size = LIST_SIZE(list); if (size >= 2) { for (i = 0; i < size; i++) { move = LIST_MOVE(list,i); list->value[i] = quiet_move_value(move,board,ThreadId); if (TryQuietKingAttacks && in_pv) { move_piece = MOVE_PIECE(move,board); if (!(PIECE_IS_PAWN(move_piece) || PIECE_IS_KING(move_piece))) { if (narrow_piece_attack_king(board,move_piece,MOVE_TO(move),KING_POS(board,COLOUR_OPP(board->turn)))) { if (see_move(move,board) >= 0) { // if (1 == NumberThreadsInternal) print_board(board); list->value[i] += 16; } } } } } } }
vrrp_rt * vrrp_index_lookup(const int vrid, const int fd) { vrrp_rt *vrrp; element e; list l = &vrrp_data->vrrp_index[vrid]; /* return if list is empty */ if (LIST_ISEMPTY(l)) return NULL; /* * If list size's is 1 then no collisions. So * Test and return the singleton. */ if (LIST_SIZE(l) == 1) { vrrp = ELEMENT_DATA(LIST_HEAD(l)); return (vrrp->fd_in == fd) ? vrrp : NULL; } /* * List collision on the vrid bucket. The same * vrid is used on a different interface. We perform * a fd lookup as collisions solver. */ for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { vrrp = ELEMENT_DATA(e); if (vrrp->fd_in == fd) return vrrp; } /* No match */ return NULL; }
/** * @brief Delete a Node from single linked list * * @param list * @param node * * @return Status operation constants code */ int single_linked_list_delete_Node(SingleLinkedList* list, Node* node) { /* check is empty */ if(LIST_SIZE(list) == 0) { printf("ERROR the list is empty\n"); return STATUS_ERR; } if (node == list->head) { /* the list become empty */ if (list->head->next == NULL) { list->head = list->tail = NULL; } else { list->head = list->head->next; } } else { Node* tmp = list->head; while (tmp != NULL && tmp->next != node) { tmp = tmp->next; } if (tmp != NULL) { tmp->next = node->next; } } free(node); list->size--; return STATUS_OK; }
static void output_ligtable (tfm_char_type *tfm_chars) { unsigned code; for (code = 0; code <= MAX_CHARCODE; code++) { list_type kern_list, ligature_list; unsigned this_kern, this_lig; tfm_char_type c = tfm_chars[code]; boolean output_something = false; /* If this character didn't get output, or if we don't have TFM information for it, don't do anything. */ if (NO_CHAR_P (code)) continue; /* Output the kerns. */ kern_list = c.kern; for (this_kern = 0; this_kern < LIST_SIZE (kern_list); this_kern++) { tfm_kern_type *kern = LIST_ELT (kern_list, this_kern); if (NO_CHAR_P (kern->character)) continue; LIGTABLE_ENTRY (code); OUT2 ("hex\"%x\" kern %.4fpt#", kern->character, kern->kern); } /* Output the ligatures. */ ligature_list = c.ligature; for (this_lig = 0; this_lig < LIST_SIZE (ligature_list); this_lig++) { tfm_ligature_type *lig = LIST_ELT (ligature_list, this_lig); if (NO_CHAR_P (lig->character) || NO_CHAR_P (lig->ligature)) continue; LIGTABLE_ENTRY (code); OUT2 ("hex\"%x\" =: hex\"%x\"", lig->character, lig->ligature); } if (output_something) OUT_LINE (";"); } }
/* Update checker's state */ void update_svr_checker_state(int alive, checker_id_t cid, virtual_server_t *vs, real_server_t *rs) { element e; list l = rs->failed_checkers; checker_id_t *id; /* Handle alive state. Depopulate failed_checkers and call * perform_svr_state() independently, letting the latter sort * things out itself. */ if (alive) { for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { id = ELEMENT_DATA(e); if (*id == cid) break; } /* call the UP handler unless any more failed checks found */ if (LIST_SIZE(l) == 0 || (LIST_SIZE(l) == 1 && e)) { if (perform_svr_state(alive, vs, rs)) return; } /* Remove the succeeded check from failed_checkers */ if (e) free_list_element(l, e); } /* Handle not alive state */ else { if (LIST_SIZE(l) == 0) { if (perform_svr_state(alive, vs, rs)) return; } else { /* do not add failed check into list twice */ for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { id = ELEMENT_DATA(e); if (*id == cid) return; } } id = (checker_id_t *) MALLOC(sizeof(checker_id_t)); *id = cid; list_add(l, id); } }
void thread_init(L4_ThreadId_t tid) { L4_Word_t my_threadno, i; mutex_init(&thrlock); mutex_lock(&thrlock); slab_init(LIST_SIZE(sizeof(thread_t)), THREAD_SLAB_BUFFER_COUNT, &thrpool, thread_slab_buffer, kmalloc, THREAD_SLAB_BUFFER_COUNT); thread_list = NULL; memset(bitmap, 0, MAX_TASKS / 8); my_threadno = L4_ThreadNo(tid); for (i = 0; i <= my_threadno; i++) threadno_alloc(bitmap, i); mutex_unlock(&thrlock); }
static void note_mvv_lva(list_t * list, const board_t * board) { int size; int i, move; ASSERT(list_is_ok(list)); ASSERT(board!=NULL); size = LIST_SIZE(list); if (size >= 2) { for (i = 0; i < size; i++) { move = LIST_MOVE(list,i); list->value[i] = mvv_lva(move,board); } } }
static void note_moves_simple(list_t * list, const board_t * board, int trans_killer) { int size; int i, move; ASSERT(list_is_ok(list)); ASSERT(board!=NULL); ASSERT(trans_killer==MoveNone||move_is_ok(trans_killer)); size = LIST_SIZE(list); if (size >= 2) { for (i = 0; i < size; i++) { move = LIST_MOVE(list,i); list->value[i] = move_value_simple(move,board,trans_killer); } } }
static bool get_dvbt_tune_params(uint16_t service_id, struct dvb_frontend_parameters *out) { char line[1024]; unsigned int freq; char inv[32]; char bw[32]; char hp[32]; char lp[32]; char qam[32]; char trans[32]; char gi[32]; char hier[32]; unsigned int id; int len; while(!feof(_channels)) { if(fgets(line, sizeof(line), _channels) == NULL || sscanf(line, "%*[^:]:%u:%32[^:]:%32[^:]:%32[^:]:%32[^:]:%32[^:]:%32[^:]:%32[^:]:%32[^:]:%*[^:]:%*[^:]:%u", &freq, inv, bw, hp, lp, qam, trans, gi, hier, &id) != 10 || id != service_id) continue; /* chop off trailing \n */ len = strlen(line) - 1; while(len >= 0 && line[len] == '\n') line[len--] = '\0'; verbose("%s", line); out->frequency = freq; out->inversion = str2enum(inv, inversion_list, LIST_SIZE(inversion_list)); out->u.ofdm.bandwidth = str2enum(bw, bw_list, LIST_SIZE(bw_list)); out->u.ofdm.code_rate_HP = str2enum(hp, fec_list, LIST_SIZE(fec_list)); out->u.ofdm.code_rate_LP = str2enum(lp, fec_list, LIST_SIZE(fec_list)); out->u.ofdm.constellation = str2enum(qam, qam_list, LIST_SIZE(qam_list)); out->u.ofdm.transmission_mode = str2enum(trans, transmissionmode_list, LIST_SIZE(transmissionmode_list)); out->u.ofdm.guard_interval = str2enum(gi, guard_list, LIST_SIZE(guard_list)); out->u.ofdm.hierarchy_information = str2enum(hier, hierarchy_list, LIST_SIZE(hierarchy_list)); return true; } return false; }
void note_moves(list_t * list, const board_t * board, int height, int trans_killer, int ThreadId) { int size; int i, move; ASSERT(list_is_ok(list)); ASSERT(board!=NULL); ASSERT(height_is_ok(height)); ASSERT(trans_killer==MoveNone||move_is_ok(trans_killer)); size = LIST_SIZE(list); if (size >= 2) { for (i = 0; i < size; i++) { move = LIST_MOVE(list,i); list->value[i] = move_value(move,board,height,trans_killer,ThreadId); } } }
int parse(const char *fname, const char *channel, struct dvb_frontend_parameters *frontend, int *vpid, int *apid, int *sid) { int fd; int err; int tmp; if ((fd = open(fname, O_RDONLY | O_NONBLOCK)) < 0) { PERROR ("could not open file '%s'", fname); perror (""); return -1; } if (find_channel(fd, channel) < 0) { ERROR("could not find channel '%s' in channel list", channel); return -2; } if ((err = try_parse_int(fd, &tmp, "frequency"))) return -3; frontend->frequency = tmp; if ((err = try_parse_param(fd, modulation_list, LIST_SIZE(modulation_list), &tmp, "modulation"))) return -4; frontend->u.vsb.modulation = tmp; if ((err = try_parse_int(fd, vpid, "Video PID"))) return -5; if ((err = try_parse_int(fd, apid, "Audio PID"))) return -6; if ((err = try_parse_int(fd, sid, "Service ID"))) return -7; close(fd); return 0; }
/* All interface are UP in the same group */ int vrrp_sync_group_up(vrrp_sgroup * vgroup) { vrrp_rt *vrrp; element e; list l = vgroup->index_list; int is_up = 0; for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) { vrrp = ELEMENT_DATA(e); if (VRRP_ISUP(vrrp)) is_up++; } if (is_up == LIST_SIZE(vgroup->index_list)) { log_message(LOG_INFO, "Kernel is reporting: Group(%s) UP" , GROUP_NAME(vgroup)); return 1; } return 0; }
std::vector<MatShape> List_to_vector_MatShape(JNIEnv* env, jobject list) { static jclass juArrayList = ARRAYLIST(env); jmethodID m_size = LIST_SIZE(env, juArrayList); jmethodID m_get = LIST_GET(env, juArrayList); static jclass jMatOfInt = MATOFINT(env); jint len = env->CallIntMethod(list, m_size); std::vector<MatShape> result; result.reserve(len); for (jint i=0; i<len; i++) { jobject element = static_cast<jobject>(env->CallObjectMethod(list, m_get, i)); cv::Mat& mat = *((cv::Mat*) GETNATIVEOBJ(env, jMatOfInt, element) ); MatShape matshape = (MatShape) mat; result.push_back(matshape); env->DeleteLocalRef(element); } return result; }
std::vector<cv::Ptr<cv::dnn::Layer> > List_to_vector_Ptr_Layer(JNIEnv* env, jobject list) { static jclass juArrayList = ARRAYLIST(env); jmethodID m_size = LIST_SIZE(env, juArrayList); jmethodID m_get = LIST_GET(env, juArrayList); static jclass jLayerClass = LAYER(env); jint len = env->CallIntMethod(list, m_size); std::vector< cv::Ptr<cv::dnn::Layer> > result; result.reserve(len); for (jint i=0; i<len; i++) { jobject element = static_cast<jobject>(env->CallObjectMethod(list, m_get, i)); cv::Ptr<cv::dnn::Layer>* layer_ptr = (cv::Ptr<cv::dnn::Layer>*) GETNATIVEOBJ(env, jLayerClass, element) ; cv::Ptr<cv::dnn::Layer> layer = *(layer_ptr); result.push_back(layer); env->DeleteLocalRef(element); } return result; }
bool board_is_stalemate(board_t * board) { list_t list[1]; int i, move; ASSERT(board!=NULL); // init if (IS_IN_CHECK(board,board->turn)) return false; // in check => not stalemate // move loop gen_moves(list,board); for (i = 0; i < LIST_SIZE(list); i++) { move = LIST_MOVE(list,i); if (pseudo_is_legal(move,board)) return false; // legal move => not stalemate } return true; // in check and no legal move => mate }
/* Set instances group pointer */ void vrrp_sync_set_group(vrrp_sgroup_t *vgroup) { vrrp_t *vrrp; char *str; unsigned int i; vrrp_t *vrrp_last = NULL; /* Can't handle no members of the group */ if (!vgroup->iname) return; vgroup->index_list = alloc_list(NULL, NULL); for (i = 0; i < vector_size(vgroup->iname); i++) { str = vector_slot(vgroup->iname, i); vrrp = vrrp_get_instance(str); if (vrrp) { if (vrrp->sync) log_message(LOG_INFO, "Virtual router %s cannot exist in more than one sync group; ignoring %s", str, vgroup->gname); else { list_add(vgroup->index_list, vrrp); vrrp->sync = vgroup; vrrp_last = vrrp; } } else log_message(LOG_INFO, "Virtual router %s specified in sync group %s doesn't exist - ignoring", str, vgroup->gname); } if (LIST_SIZE(vgroup->index_list) <= 1) { /* The sync group will be removed by the calling function */ log_message(LOG_INFO, "Sync group %s has only %d virtual router(s) - removing", vgroup->gname, LIST_SIZE(vgroup->index_list)); /* If there is only one entry in the group, remove the group from the vrrp entry */ if (vrrp_last) vrrp_last->sync = NULL; } }
void search() { int move; int depth; int i; bool search_ready; for (i = 0; i < MultiPVMax; i++){ save_multipv[SearchCurrent->multipv].mate = 0; save_multipv[SearchCurrent->multipv].depth = 0; save_multipv[SearchCurrent->multipv].max_depth = 0; save_multipv[SearchCurrent->multipv].value = 0; save_multipv[SearchCurrent->multipv].time = 0; save_multipv[SearchCurrent->multipv].node_nb = 0; strcpy(save_multipv[SearchCurrent->multipv].pv_string,""); } SearchInput->multipv = option_get_int("MultiPV")-1; SearchCurrent->multipv = 0; ASSERT(board_is_ok(SearchInput->board)); // opening book if (option_get_bool("OwnBook") && !SearchInput->infinite) { move = book_move(SearchInput->board); if (move != MoveNone) { // play book move SearchBest[SearchCurrent->multipv].move = move; SearchBest[SearchCurrent->multipv].value = 1; SearchBest[SearchCurrent->multipv].flags = SearchExact; SearchBest[SearchCurrent->multipv].depth = 1; SearchBest[SearchCurrent->multipv].pv[0] = move; SearchBest[SearchCurrent->multipv].pv[1] = MoveNone; search_update_best(); return; } } // SearchInput gen_legal_moves(SearchInput->list,SearchInput->board); if (LIST_SIZE(SearchInput->list) < SearchInput->multipv+1){ SearchInput->multipv = LIST_SIZE(SearchInput->list)-1; } if (LIST_SIZE(SearchInput->list) <= 1) { SearchInput->depth_is_limited = true; SearchInput->depth_limit = 4; // was 1 } // SearchInfo if (setjmp(SearchInfo->buf) != 0) { ASSERT(SearchInfo->can_stop); ASSERT(SearchBest->move!=MoveNone); search_update_current(); return; } // SearchRoot list_copy(SearchRoot->list,SearchInput->list); // SearchCurrent board_copy(SearchCurrent->board,SearchInput->board); my_timer_reset(SearchCurrent->timer); my_timer_start(SearchCurrent->timer); // init trans_inc_date(Trans); sort_init(); search_full_init(SearchRoot->list,SearchCurrent->board); // analyze game for evaluation if (SearchCurrent->board->piece_size[White] < 3 && SearchCurrent->board->piece_size[Black] < 3){ trans_endgame = true; } else{ trans_endgame = false; } // iterative deepening search_ready = false; for (depth = 1; depth < DepthMax; depth++) { for (SearchCurrent->multipv = 0; SearchCurrent->multipv <= SearchInput->multipv; SearchCurrent->multipv++){ if (DispDepthStart && SearchCurrent->multipv == 0) send("info depth %d",depth); SearchCurrent->max_extensions = depth * 10; SearchRoot->bad_1 = false; SearchRoot->change = false; board_copy(SearchCurrent->board,SearchInput->board); if (UseShortSearch && depth <= ShortSearchDepth) { search_full_root(SearchRoot->list,SearchCurrent->board,depth,SearchShort); } else { search_full_root(SearchRoot->list,SearchCurrent->board,depth,SearchNormal); } search_update_current(); if (DispDepthEnd && SearchCurrent->multipv == SearchInput->multipv) { send("info depth %d seldepth %d time %.0f nodes " S64_FORMAT " nps %.0f",depth,SearchCurrent->max_depth,SearchCurrent->time*1000.0,SearchCurrent->node_nb,SearchCurrent->speed); } // update search info if (depth >= 1) SearchInfo->can_stop = true; if (depth == 1 && LIST_SIZE(SearchRoot->list) >= 2 && LIST_VALUE(SearchRoot->list,0) >= LIST_VALUE(SearchRoot->list,1) + EasyThreshold) { SearchRoot->easy = true; } if (depth > 1) { SearchRoot->bad_2 = SearchRoot->bad_1; SearchRoot->bad_1 = false; ASSERT(SearchRoot->bad_2==(SearchBest->value<=SearchRoot->last_value-BadThreshold)); } SearchRoot->last_value = SearchBest[SearchCurrent->multipv].value; // stop search? if (SearchInput->depth_is_limited && SearchCurrent->multipv >= SearchInput->multipv && depth >= SearchInput->depth_limit) { SearchRoot->flag = true; } if (SearchInput->time_is_limited && SearchCurrent->time * 2 >= SearchInput->time_limit_1 && !SearchRoot->bad_2) { SearchRoot->flag = true; } if (SearchInput->time_is_limited && SearchCurrent->time >= SearchInput->time_limit_1 * EasyRatio && SearchRoot->easy) { ASSERT(!SearchRoot->bad_2); ASSERT(!SearchRoot->change); SearchRoot->flag = true; } if (SearchInput->time_is_limited && SearchCurrent->time >= SearchInput->time_limit_1 * EarlyRatio && !SearchRoot->bad_2 && !SearchRoot->change) { SearchRoot->flag = true; } if (SearchInfo->can_stop && (SearchInfo->stop || (SearchRoot->flag && !SearchInput->infinite))) { search_ready = true; break; } } if (search_ready) break; } }
int parse(const char *fname, const char *channel, struct dvb_frontend_parameters *frontend, int *vpid, int *apid, int *sid) { int fd; int err; int tmp; if ((fd = open(fname, O_RDONLY | O_NONBLOCK)) < 0) { PERROR ("could not open file '%s'", fname); perror (""); return -1; } if (find_channel(fd, channel) < 0) { ERROR("could not find channel '%s' in channel list", channel); return -2; } if ((err = try_parse_int(fd, &tmp, "frequency"))) return -3; frontend->frequency = tmp; if ((err = try_parse_param(fd, inversion_list, LIST_SIZE(inversion_list), &tmp, "inversion"))) return -4; frontend->inversion = tmp; if ((err = try_parse_param(fd, bw_list, LIST_SIZE(bw_list), &tmp, "bandwidth"))) return -5; frontend->u.ofdm.bandwidth = tmp; if ((err = try_parse_param(fd, fec_list, LIST_SIZE(fec_list), &tmp, "code_rate_HP"))) return -6; frontend->u.ofdm.code_rate_HP = tmp; if (check_fec(&frontend->u.ofdm.code_rate_HP)) return -6; if ((err = try_parse_param(fd, fec_list, LIST_SIZE(fec_list), &tmp, "code_rate_LP"))) return -7; frontend->u.ofdm.code_rate_LP = tmp; if (check_fec(&frontend->u.ofdm.code_rate_LP)) return -7; if ((err = try_parse_param(fd, constellation_list, LIST_SIZE(constellation_list), &tmp, "constellation"))) return -8; frontend->u.ofdm.constellation = tmp; if ((err = try_parse_param(fd, transmissionmode_list, LIST_SIZE(transmissionmode_list), &tmp, "transmission_mode"))) return -9; frontend->u.ofdm.transmission_mode = tmp; if ((err = try_parse_param(fd, guard_list, LIST_SIZE(guard_list), &tmp, "guard_interval"))) return -10; frontend->u.ofdm.guard_interval = tmp; if ((err = try_parse_param(fd, hierarchy_list, LIST_SIZE(hierarchy_list), &tmp, "hierarchy_information"))) return -11; frontend->u.ofdm.hierarchy_information = tmp; if ((err = try_parse_int(fd, vpid, "Video PID"))) return -12; if ((err = try_parse_int(fd, apid, "Audio PID"))) return -13; if ((err = try_parse_int(fd, sid, "Service ID"))) return -14; close(fd); return 0; }
void vrrp_print(FILE *file, void *data) { vrrp_t *vrrp = data; char auth_data[sizeof(vrrp->auth_data) + 1]; fprintf(file, " VRRP Instance = %s\n", vrrp->iname); fprintf(file, " VRRP Version = %d\n", vrrp->version); if (vrrp->family == AF_INET6) fprintf(file, " Using Native IPv6\n"); if (vrrp->state == VRRP_STATE_BACK) { fprintf(file, " State = BACKUP\n"); fprintf(file, " Master router = %s\n", inet_sockaddrtos(&vrrp->master_saddr)); fprintf(file, " Master priority = %d\n", vrrp->master_priority); } else if (vrrp->state == VRRP_STATE_FAULT) fprintf(file, " State = FAULT\n"); else if (vrrp->state == VRRP_STATE_MAST) fprintf(file, " State = MASTER\n"); else fprintf(file, " State = %d\n", vrrp->state); fprintf(file, " Last transition = %ld\n", vrrp->last_transition.tv_sec); fprintf(file, " Listening device = %s\n", IF_NAME(vrrp->ifp)); if (vrrp->dont_track_primary) fprintf(file, " VRRP interface tracking disabled\n"); fprintf(file, " Using src_ip = %s\n", inet_sockaddrtos(&vrrp->saddr)); if (vrrp->lvs_syncd_if) fprintf(file, " Runing LVS sync daemon on interface = %s\n", vrrp->lvs_syncd_if); if (vrrp->garp_delay) fprintf(file, " Gratuitous ARP delay = %d\n", vrrp->garp_delay/TIMER_HZ); fprintf(file, " Virtual Router ID = %d\n", vrrp->vrid); fprintf(file, " Priority = %d\n", vrrp->base_priority); fprintf(file, " Advert interval = %d %s\n", (vrrp->version == VRRP_VERSION_2) ? (vrrp->adver_int / TIMER_HZ) : (vrrp->adver_int * 1000 / TIMER_HZ), (vrrp->version == VRRP_VERSION_2) ? "sec" : "milli-sec"); fprintf(file, " Accept = %s\n", ((vrrp->accept) ? "enabled" : "disabled")); if (vrrp->nopreempt) fprintf(file, " Preempt = disabled\n"); else fprintf(file, " Preempt = enabled\n"); if (vrrp->preempt_delay) fprintf(file, " Preempt delay = %ld secs\n", vrrp->preempt_delay / TIMER_HZ); if (vrrp->auth_type) { fprintf(file, " Authentication type = %s\n", (vrrp->auth_type == VRRP_AUTH_AH) ? "IPSEC_AH" : "SIMPLE_PASSWORD"); if (vrrp->auth_type != VRRP_AUTH_AH) { /* vrrp->auth_data is not \0 terminated */ memcpy(auth_data, vrrp->auth_data, sizeof(vrrp->auth_data)); auth_data[sizeof(vrrp->auth_data)] = '\0'; fprintf(file, " Password = %s\n", auth_data); } } else fprintf(file, " Authentication type = none\n"); if (!LIST_ISEMPTY(vrrp->track_ifp)) { fprintf(file, " Tracked interfaces = %d\n", LIST_SIZE(vrrp->track_ifp)); vrrp_print_list(file, vrrp->track_ifp, &if_print); } if (!LIST_ISEMPTY(vrrp->track_script)) { fprintf(file, " Tracked scripts = %d\n", LIST_SIZE(vrrp->track_script)); vrrp_print_list(file, vrrp->track_script, &vscript_print); } if (!LIST_ISEMPTY(vrrp->vip)) { fprintf(file, " Virtual IP = %d\n", LIST_SIZE(vrrp->vip)); vrrp_print_list(file, vrrp->vip, &address_print); } if (!LIST_ISEMPTY(vrrp->evip)) { fprintf(file, " Virtual IP Excluded = %d\n", LIST_SIZE(vrrp->evip)); vrrp_print_list(file, vrrp->evip, &address_print); } if (!LIST_ISEMPTY(vrrp->vroutes)) { fprintf(file, " Virtual Routes = %d\n", LIST_SIZE(vrrp->vroutes)); vrrp_print_list(file, vrrp->vroutes, &route_print); } if (!LIST_ISEMPTY(vrrp->vrules)) { fprintf(file, " Virtual Rules = %d\n", LIST_SIZE(vrrp->vrules)); vrrp_print_list(file, vrrp->vrules, &rule_print); } if (vrrp->script_backup) fprintf(file, " Backup state transition script = %s\n", vrrp->script_backup); if (vrrp->script_master) fprintf(file, " Master state transition script = %s\n", vrrp->script_master); if (vrrp->script_fault) fprintf(file, " Fault state transition script = %s\n", vrrp->script_fault); if (vrrp->script_stop) fprintf(file, " Stop state transition script = %s\n", vrrp->script_stop); if (vrrp->script) fprintf(file, " Generic state transition script = '%s'\n", vrrp->script); if (vrrp->smtp_alert) fprintf(file, " Using smtp notification\n"); }
int sort_next(sort_t * sort) { int move; int gen; ASSERT(sort!=NULL); while (true) { while (sort->pos < LIST_SIZE(sort->list)) { // next move move = LIST_MOVE(sort->list,sort->pos); sort->value = 65536; // default score sort->pos++; ASSERT(move!=MoveNone); // test if (false) { } else if (sort->test == TEST_NONE) { // Evasion (no-op) } else if (sort->test == TEST_TRANS_KILLER) { if (!move_is_pseudo(move,sort->board)) continue; if (!pseudo_is_legal(move,sort->board)) continue; } else if (sort->test == TEST_CAPTURE) { ASSERT(MOVE_IS_TACTICAL(move,sort->board)); if (move == sort->trans_killer) continue; if (!capture_is_good(move,sort->board)) { LIST_ADD(sort->bad,move); continue; } if (!pseudo_is_legal(move,sort->board)) continue; } else if (sort->test == TEST_KILLER) { if (move == sort->trans_killer) continue; if (!quiet_is_pseudo(move,sort->board)) continue; if (!pseudo_is_legal(move,sort->board)) continue; ASSERT(!MOVE_IS_TACTICAL(move,sort->board)); sort->value = 32768; } else if (sort->test == TEST_QUIET) { ASSERT(!MOVE_IS_TACTICAL(move,sort->board)); if (move == sort->trans_killer) continue; if (move == sort->killer_1) continue; if (move == sort->killer_2) continue; if (!pseudo_is_legal(move,sort->board)) continue; sort->value = history_prob(move,sort->board); } else if (sort->test == TEST_BAD) { ASSERT(MOVE_IS_TACTICAL(move,sort->board)); ASSERT(!capture_is_good(move,sort->board)); ASSERT(move!=sort->trans_killer); if (!pseudo_is_legal(move,sort->board)) continue; } else { ASSERT(false); return MoveNone; } ASSERT(pseudo_is_legal(move,sort->board)); return move; } // next stage gen = Code[sort->gen++]; if (false) { } else if (gen == GEN_TRANS) { LIST_CLEAR(sort->list); if (sort->trans_killer != MoveNone) LIST_ADD(sort->list,sort->trans_killer); sort->test = TEST_TRANS_KILLER; } else if (gen == GEN_CAPTURE) { gen_captures(sort->list,sort->board); note_mvv_lva(sort->list,sort->board); list_sort(sort->list); LIST_CLEAR(sort->bad); sort->test = TEST_CAPTURE; } else if (gen == GEN_KILLER) { LIST_CLEAR(sort->list); if (sort->killer_1 != MoveNone) LIST_ADD(sort->list,sort->killer_1); if (sort->killer_2 != MoveNone) LIST_ADD(sort->list,sort->killer_2); sort->test = TEST_KILLER; } else if (gen == GEN_QUIET) { gen_quiet_moves(sort->list,sort->board); note_quiet_moves(sort->list,sort->board); list_sort(sort->list); sort->test = TEST_QUIET; } else if (gen == GEN_BAD) { list_copy(sort->list,sort->bad); sort->test = TEST_BAD; } else { ASSERT(gen==GEN_END); return MoveNone; } sort->pos = 0; } }
int sort_next_qs(sort_t * sort) { int move; int gen; ASSERT(sort!=NULL); while (true) { while (sort->pos < LIST_SIZE(sort->list)) { // next move move = LIST_MOVE(sort->list,sort->pos); sort->pos++; ASSERT(move!=MoveNone); // test if (false) { } else if (sort->test == TEST_LEGAL) { if (!pseudo_is_legal(move,sort->board)) continue; } else if (sort->test == TEST_CAPTURE_QS) { ASSERT(move_is_tactical(move,sort->board)); if (!capture_is_good(move,sort->board,false)) continue; if (!pseudo_is_legal(move,sort->board)) continue; } else if (sort->test == TEST_CHECK_QS) { ASSERT(!move_is_tactical(move,sort->board)); ASSERT(move_is_check(move,sort->board)); if (see_move(move,sort->board) < 0) continue; if (!pseudo_is_legal(move,sort->board)) continue; } else { ASSERT(false); return MoveNone; } ASSERT(pseudo_is_legal(move,sort->board)); return move; } // next stage gen = Code[sort->gen++]; if (false) { } else if (gen == GEN_EVASION_QS) { gen_pseudo_evasions(sort->list,sort->board,sort->attack); note_moves_simple(sort->list,sort->board); list_sort(sort->list); sort->test = TEST_LEGAL; } else if (gen == GEN_CAPTURE_QS) { gen_captures(sort->list,sort->board); note_mvv_lva(sort->list,sort->board); list_sort(sort->list); sort->test = TEST_CAPTURE_QS; } else if (gen == GEN_CHECK_QS) { gen_quiet_checks(sort->list,sort->board); sort->test = TEST_CHECK_QS; } else { ASSERT(gen==GEN_END); return MoveNone; } sort->pos = 0; } }
int sort_next(sort_t * sort, int ThreadId) { int move; int gen; ASSERT(sort!=NULL); while (true) { while (sort->pos < LIST_SIZE(sort->list)) { // next move move = LIST_MOVE(sort->list,sort->pos); sort->value = HistoryMax; // default score, HistoryMax instead of 16384 sort->pos++; ASSERT(move!=MoveNone); // test if (false) { } else if (sort->test == TEST_NONE) { // no-op } else if (sort->test == TEST_TRANS_KILLER) { if (!move_is_pseudo(move,sort->board)) continue; if (!pseudo_is_legal(move,sort->board)) continue; } else if (sort->test == TEST_GOOD_CAPTURE) { ASSERT(move_is_tactical(move,sort->board)); if (move == sort->trans_killer) continue; if (!capture_is_good(move,sort->board,sort->in_pv)) { LIST_ADD(sort->bad,move); continue; } if (!pseudo_is_legal(move,sort->board)) continue; } else if (sort->test == TEST_BAD_CAPTURE) { ASSERT(move_is_tactical(move,sort->board)); ASSERT(!capture_is_good(move,sort->board,sort->in_pv)); ASSERT(move!=sort->trans_killer); if (!pseudo_is_legal(move,sort->board)) continue; sort->value = HistoryBadCap; // WHM(31) } else if (sort->test == TEST_KILLER) { if (move == sort->trans_killer) continue; if (!quiet_is_pseudo(move,sort->board)) continue; if (!pseudo_is_legal(move,sort->board)) continue; ASSERT(!move_is_tactical(move,sort->board)); sort->value = HistoryKiller; // WHM(31) } else if (sort->test == TEST_QUIET) { ASSERT(!move_is_tactical(move,sort->board)); if (move == sort->trans_killer) continue; if (move == sort->killer_1) continue; if (move == sort->killer_2) continue; if (move == sort->killer_3) continue; if (move == sort->killer_4) continue; if (!pseudo_is_legal(move,sort->board)) continue; sort->value = history_prob(move,sort->board,ThreadId); } else { ASSERT(false); return MoveNone; } ASSERT(pseudo_is_legal(move,sort->board)); return move; } // next stage gen = Code[sort->gen++]; if (false) { } else if (gen == GEN_TRANS) { LIST_CLEAR(sort->list); if (sort->trans_killer != MoveNone) LIST_ADD(sort->list,sort->trans_killer); sort->test = TEST_TRANS_KILLER; } else if (gen == GEN_GOOD_CAPTURE) { gen_captures(sort->list,sort->board); note_mvv_lva(sort->list,sort->board); list_sort(sort->list); LIST_CLEAR(sort->bad); sort->test = TEST_GOOD_CAPTURE; } else if (gen == GEN_BAD_CAPTURE) { list_copy(sort->list,sort->bad); sort->test = TEST_BAD_CAPTURE; } else if (gen == GEN_KILLER) { LIST_CLEAR(sort->list); if (sort->killer_1 != MoveNone) LIST_ADD(sort->list,sort->killer_1); if (sort->killer_2 != MoveNone) LIST_ADD(sort->list,sort->killer_2); if (sort->killer_3 != MoveNone) LIST_ADD(sort->list,sort->killer_3); if (sort->killer_4 != MoveNone) LIST_ADD(sort->list,sort->killer_4); sort->test = TEST_KILLER; } else if (gen == GEN_QUIET) { gen_quiet_moves(sort->list,sort->board); note_quiet_moves(sort->list,sort->board,sort->in_pv,ThreadId); list_sort(sort->list); sort->test = TEST_QUIET; } else { ASSERT(gen==GEN_END); return MoveNone; } sort->pos = 0; } }
#include <mutex/mutex.h> #include <string.h> #include <memory.h> #include <list.h> #include <slab.h> #include <thread.h> #include <capability.h> #include <assert.h> #include <debug.h> static list_t *thread_list; static uint8_t bitmap[MAX_TASKS / 8]; #define THREAD_SLAB_BUFFER_COUNT 1024 static uint8_t thread_slab_buffer[THREAD_SLAB_BUFFER_COUNT * SLAB_SIZE(LIST_SIZE(sizeof(thread_t)))]; static slab_pool_t thrpool; mutex_t thrlock; static L4_Word_t thread_prepare_stack(AddrSpace_t *as, L4_Word_t sp, char *cmdline, int n, char **paths, HpfCapability *caps); static void threadno_alloc(uint8_t *bmp, L4_Word_t tno) { assert (bmp != NULL); L4_Word_t byte = tno / 8; uint8_t bit = 1 << (tno % 8); bmp[byte] |= bit; }
int sort_next_qs(sort_t * sort) { int move; int gen; ASSERT(sort!=NULL); while (true) { while (sort->pos < LIST_SIZE(sort->list)) { // next move move = LIST_MOVE(sort->list,sort->pos); sort->pos++; ASSERT(move!=MoveNone); // test if (false) { } else if (sort->test == TEST_LEGAL) { if (!pseudo_is_legal(move,sort->board)) continue; } else if (sort->test == TEST_TRANS_KILLER) { if (!move_is_pseudo(move,sort->board)) continue; if (!pseudo_is_legal(move,sort->board)) continue; // check if (!MOVE_IS_TACTICAL(move,sort->board) && (!move_is_check(move,sort->board) || sort->depth < 0)) continue; } else if (sort->test == TEST_CAPTURE_QS) { ASSERT(MOVE_IS_TACTICAL(move,sort->board)); ASSERT(sort->value==NodePV||sort->value==NodeCut||sort->value==NodeAll); if (move == sort->trans_killer) continue; if (sort->value != NodePV && !capture_is_good(move,sort->board)) continue; if (!pseudo_is_legal(move,sort->board)) continue; } else if (sort->test == TEST_CHECK_QS) { ASSERT(!MOVE_IS_TACTICAL(move,sort->board)); ASSERT(move_is_check(move,sort->board)); if (move == sort->trans_killer) continue; if (see_move(move,sort->board,0) < 0) continue; if (!pseudo_is_legal(move,sort->board)) continue; } else { ASSERT(false); return MoveNone; } ASSERT(pseudo_is_legal(move,sort->board)); return move; } // next stage gen = Code[sort->gen++]; if (false) { } else if (gen == GEN_EVASION_QS) { gen_pseudo_evasions(sort->list,sort->board,sort->attack); note_moves_simple(sort->list,sort->board,sort->trans_killer); list_sort(sort->list); sort->test = TEST_LEGAL; } else if (gen == GEN_TRANS) { LIST_CLEAR(sort->list); if (sort->trans_killer != MoveNone) LIST_ADD(sort->list,sort->trans_killer); sort->test = TEST_TRANS_KILLER; } else if (gen == GEN_CAPTURE_QS) { gen_captures(sort->list,sort->board); note_mvv_lva(sort->list,sort->board); list_sort(sort->list); sort->test = TEST_CAPTURE_QS; } else if (gen == GEN_CHECK_QS) { gen_quiet_checks(sort->list,sort->board); sort->test = TEST_CHECK_QS; } else { ASSERT(gen==GEN_END); return MoveNone; } sort->pos = 0; } }
static int full_search(board_t * board, int alpha, int beta, int depth, int height, mv_t pv[], int node_type) { bool in_check; bool single_reply; bool mate_threat; int trans_move, trans_depth, trans_min_depth, trans_max_depth, trans_min_value, trans_max_value; int min_value, max_value; int old_alpha; int value, best_value; int move, best_move; int new_depth; int played_nb; int i; int opt_value; bool reduced; int mb; attack_t attack[1]; sort_t sort[1]; undo_t undo[1]; mv_t new_pv[HeightMax]; mv_t played[256]; int FutilityMargin; ASSERT(board!=NULL); ASSERT(range_is_ok(alpha,beta)); ASSERT(depth_is_ok(depth)); ASSERT(height_is_ok(height)); ASSERT(pv!=NULL); ASSERT(node_type==NodePV||node_type==NodeCut||node_type==NodeAll); ASSERT(board_is_legal(board)); // horizon? if (depth <= 0){ if (node_type == NodePV) CheckDepth = 1 - CheckNb - 1; else CheckDepth = 1 - CheckNb; return full_quiescence(board,alpha,beta,0,height,pv); } // init SearchStack[height].best_move = MoveNone; SearchStack[height].move = MoveNone; SearchStack[height].threat_move = MoveNone; SearchStack[height].reduced = false; mate_threat = false; SearchCurrent->node_nb++; SearchInfo->check_nb--; PV_CLEAR(pv); if (height > SearchCurrent->max_depth) SearchCurrent->max_depth = height; if (SearchInfo->check_nb <= 0) { SearchInfo->check_nb += SearchInfo->check_inc; search_check(); } // draw? if (board_is_repetition(board) || recog_draw(board)) return ValueDraw; // mate-distance pruning if (UseDistancePruning) { // lower bound value = VALUE_MATE(height+2); // does not work if the current position is mate if (value > alpha && board_is_mate(board)) value = VALUE_MATE(height); if (value > alpha) { alpha = value; if (value >= beta) return value; } // upper bound value = -VALUE_MATE(height+1); if (value < beta) { beta = value; if (value <= alpha) return value; } } // transposition table trans_move = MoveNone; if (UseTrans && depth >= TransDepth) { if (trans_retrieve(Trans,board->key,&trans_move,&trans_min_depth,&trans_max_depth,&trans_min_value,&trans_max_value)) { // trans_move is now updated if (node_type != NodePV) { if (UseMateValues) { if (trans_min_value > +ValueEvalInf && trans_min_depth < depth) { trans_min_depth = depth; } if (trans_max_value < -ValueEvalInf && trans_max_depth < depth) { trans_max_depth = depth; } } min_value = -ValueInf; if (DEPTH_MATCH(trans_min_depth,depth)) { min_value = value_from_trans(trans_min_value,height); if (min_value >= beta) return min_value; } max_value = +ValueInf; if (DEPTH_MATCH(trans_max_depth,depth)) { max_value = value_from_trans(trans_max_value,height); if (max_value <= alpha) return max_value; } if (min_value == max_value) return min_value; // exact match } } } // height limit if (height >= HeightMax-1) return eval(board, alpha, beta); // more init old_alpha = alpha; best_value = ValueNone; best_move = MoveNone; played_nb = 0; attack_set(attack,board); in_check = ATTACK_IN_CHECK(attack); // null-move pruning if (UseNull && depth >= NullDepth && node_type != NodePV) { if (!in_check && !value_is_mate(beta) && do_null(board) && (!UseNullEval || depth <= NullReduction+1 || eval(board,alpha, beta) >= beta)) { // null-move search new_depth = depth - NullReduction - 1; //new_depth = depth - R_adpt(board->piece_size[board->turn]+board->pawn_size[board->turn],depth,NullReduction) - 1; move_do_null(board,undo); value = -full_search(board,-beta,-beta+1,new_depth,height+1,new_pv,NODE_OPP(node_type)); move_undo_null(board,undo); // verification search if (UseVer && depth > VerReduction) { if (value >= beta && (!UseVerEndgame || do_ver(board))) { new_depth = depth - VerReduction; ASSERT(new_depth>0); value = full_no_null(board,alpha,beta,new_depth,height,new_pv,NodeCut,trans_move,&move); if (value >= beta) { ASSERT(move==new_pv[0]); played[played_nb++] = move; best_move = move; SearchStack[height].move = move; SearchStack[height].best_move = move; best_value = value; pv_copy(pv,new_pv); goto cut; } } } // pruning if (value >= beta) { if (value > +ValueEvalInf) value = +ValueEvalInf; // do not return unproven mates ASSERT(!value_is_mate(value)); // pv_cat(pv,new_pv,MoveNull); best_move = MoveNone; best_value = value; goto cut; } SearchStack[height].threat_move = SearchStack[height+1].best_move; /* if (SearchStack[height-1].reduced){ // Idea by Tord Romstad if (MOVE_FROM(SearchStack[height+1].best_move) == MOVE_TO(SearchStack[height-1].move)) return alpha-1; */ /* if(((MOVE_TO(SearchStack[height - 2].threat_move) == MOVE_FROM(SearchStack[height - 2].move)) && (MOVE_TO(SearchStack[height].threat_move) == MOVE_TO(SearchStack[height - 2].move))) || ((MOVE_TO(SearchStack[height - 2].threat_move) != MOVE_FROM(SearchStack[height - 2].move)) && (MOVE_TO(SearchStack[height].threat_move) == MOVE_TO(SearchStack[height - 2].threat_move)))) return alpha-1; */ // } } } // mate threat /* mate_threat = false; if (value <= VALUE_MATE(height+2)){ mate_threat = true; } */ // Internal Iterative Deepening if (UseIID && depth >= IIDDepth && node_type == NodePV && trans_move == MoveNone) { // new_depth = depth - IIDReduction; new_depth = MIN(depth - IIDReduction,depth/2); ASSERT(new_depth>0); value = full_search(board,alpha,beta,new_depth,height,new_pv,node_type); if (value <= alpha) value = full_search(board,-ValueInf,beta,new_depth,height,new_pv,node_type); trans_move = new_pv[0]; } // move generation sort_init(sort,board,attack,depth,height,trans_move); single_reply = false; if (in_check && LIST_SIZE(sort->list) == 1) single_reply = true; // HACK // move loop opt_value = +ValueInf; while ((move=sort_next(sort)) != MoveNone) { SearchStack[height].move = move; // history_tried(move,board); // extensions new_depth = full_new_depth(depth,move,board,single_reply,mate_threat,node_type==NodePV, height); // futility pruning if (UseFutility && depth <= 2 && node_type != NodePV) { if (!in_check && new_depth < depth && !move_is_tactical(move,board) && !move_is_dangerous(move,board)) { ASSERT(!move_is_check(move,board)); // optimistic evaluation if (opt_value == +ValueInf) { if (depth==2){ FutilityMargin = FutilityMargin2; } else{ FutilityMargin = FutilityMargin1; } opt_value = eval(board,alpha,beta) + FutilityMargin; ASSERT(opt_value<+ValueInf); } value = opt_value; // pruning if (value <= alpha) { if (value > best_value) { best_value = value; PV_CLEAR(pv); } continue; } } } // history pruning /* reduced = false; if (UseHistory && depth >= HistoryDepth && node_type != NodePV) { if (!in_check && played_nb >= HistoryMoveNb && new_depth < depth) { ASSERT(best_value!=ValueNone); ASSERT(played_nb>0); ASSERT(sort->pos>0&&move==LIST_MOVE(sort->list,sort->pos-1)); if (history_reduction(move,board) == true) { ASSERT(value>=0&&value<16384); ASSERT(move!=trans_move); ASSERT(!move_is_tactical(move,board)); ASSERT(!move_is_check(move,board)); new_depth--; reduced = true; } } } */ // history pruning reduced = false; value = sort->value; // history score if (!in_check && depth < SearchCurrent->max_extensions / 2 && node_type != NodePV && new_depth < depth && value < HistoryValue / depth) continue; if (UseHistory && depth >= HistoryDepth && node_type != NodePV) { if (!in_check && played_nb >= HistoryMoveNb && new_depth < depth) { ASSERT(best_value!=ValueNone); ASSERT(played_nb>0); ASSERT(sort->pos>0&&move==LIST_MOVE(sort->list,sort->pos-1)); value = sort->value; // history score if (value < HistoryValue) { ASSERT(value>=0&&value<16384); ASSERT(move!=trans_move); ASSERT(!move_is_tactical(move,board)); ASSERT(!move_is_check(move,board)); new_depth--; reduced = true; if (UseExtendedHistory && value < HistoryValue / 2 && depth >= 8){ new_depth--; } } } } SearchStack[height].reduced = reduced; // recursive search move_do(board,move,undo); if (node_type != NodePV || best_value == ValueNone) { // first move value = -full_search(board,-beta,-alpha,new_depth,height+1,new_pv,NODE_OPP(node_type)); } else { // other moves value = -full_search(board,-alpha-1,-alpha,new_depth,height+1,new_pv,NodeCut); if (value > alpha) { // && value < beta value = -full_search(board,-beta,-alpha,new_depth,height+1,new_pv,NodePV); } } // history-pruning re-search if (HistoryReSearch && reduced && value > alpha /* was >= beta */) { ASSERT(node_type!=NodePV); //history_very_bad(move,board); SearchStack[height].reduced = false; new_depth++; ASSERT(new_depth==depth-1); value = -full_search(board,-beta,-alpha,new_depth,height+1,new_pv,NODE_OPP(node_type)); } move_undo(board,move,undo); played[played_nb++] = move; if (value > best_value) { best_value = value; pv_cat(pv,new_pv,move); if (value > alpha) { alpha = value; best_move = move; SearchStack[height].best_move = move; if (value >= beta){ // history_success(move,board); goto cut; } } } if (node_type == NodeCut) node_type = NodeAll; } // ALL node if (best_value == ValueNone) { // no legal move if (in_check) { ASSERT(board_is_mate(board)); return VALUE_MATE(height); } else { ASSERT(board_is_stalemate(board)); return ValueDraw; } } cut: ASSERT(value_is_ok(best_value)); // move ordering if (best_move != MoveNone) { good_move(best_move,board,depth,height); if (best_value >= beta && !move_is_tactical(best_move,board)) { ASSERT(played_nb>0&&played[played_nb-1]==best_move); for (i = 0; i < played_nb-1; i++) { move = played[i]; ASSERT(move!=best_move); history_bad(move,board); } history_good(best_move,board); } } // transposition table if (UseTrans && depth >= TransDepth) { trans_move = best_move; trans_depth = depth; trans_min_value = (best_value > old_alpha) ? value_to_trans(best_value,height) : -ValueInf; trans_max_value = (best_value < beta) ? value_to_trans(best_value,height) : +ValueInf; trans_store(Trans,board->key,trans_move,trans_depth,trans_min_value,trans_max_value); } return best_value; }
bool TEngine::SearchPos(board_t * Board, TFindPos * fp, mv_t pv[], bool full) { //------------------------ if (Eval(Board,fp)) { pv[0] = 0; return true; } //----------------------- if (LastMove) { undo_t undo; move_do(Board,LastMove,&undo); bool eval = Eval(Board,fp); if (Eval(Board,fp)) { move_undo(Board,LastMove, &undo); pv[0] = LastMove; pv[1] = 0; return true; } list_t list; gen_legal_moves(&list,Board); for (int i=0; i<LIST_SIZE(&list); i++) { undo_t undo2; mv_t move2 = LIST_MOVE(&list,i); move_do(Board,move2,&undo2); bool eval = Eval(Board,fp); move_undo(Board,move2, &undo2); if (eval) { move_undo(Board,LastMove, &undo); pv[0] = LastMove; pv[1] = move2; pv[2] = 0; return true;; } } move_undo(Board,LastMove,&undo); } //---------------------------------------------------- list_t list; gen_legal_moves(&list,Board); //---------------------------------------------------- for (int i=0; i<LIST_SIZE(&list); i++) { undo_t undo; mv_t move = LIST_MOVE(&list,i); move_do(Board,move,&undo); bool eval = Eval(Board,fp); move_undo(Board,move,&undo); if (eval) { pv[0] = move; pv[1] = 0; return true; } } //------------------------------------------------------ if (full) { for (int i=0; i<LIST_SIZE(&list); i++) { undo_t undo; mv_t move = LIST_MOVE(&list,i); move_do(Board,move,&undo); list_t list2; gen_legal_moves(&list2,Board); for (int j=0; j<LIST_SIZE(&list2); j++) { undo_t undo2; mv_t move2 = LIST_MOVE(&list2,j); move_do(Board,move2,&undo2); /* char s_move[6], s_move2[6]; move_to_string(move,s_move,6); move_to_string(move2,s_move2,6); */ bool eval = Eval(Board,fp); move_undo(Board,move2,&undo2); if (eval) { pv[0] = move; pv[1] = move2; pv[2] = 0; move_undo(Board,move,&undo); return true; } } move_undo(Board,move,&undo); } } //------------------------------------------------------- return false; }