/*===========================================================================*/ int * ghmm_dpmodel_viterbi_propagate_segment (ghmm_dpmodel *mo, ghmm_dpseq * X, ghmm_dpseq * Y, double *log_p, int *path_length, double max_size, int start_x, int start_y, int stop_x, int stop_y, int start_state, int stop_state, double start_log_p, double stop_log_p) { #define CUR_PROC "ghmm_dpmodel_viterbi_propagate_segment" int * path_seq = NULL; cell * start, * stop; plocal_propagate_store_t * pv = pviterbi_propagate_alloc(mo, Y->length); /* Precomputing the log(a_ij) and log(bj(ot)) */ pviterbi_prop_precompute(mo, pv); /* init start and stop */ start = init_cell (start_x, start_y, start_state, -1, start_log_p, 0); stop = init_cell (stop_x, stop_y, stop_state, stop_state, stop_log_p, 0); /* Launch the recursion */ path_seq = pviterbi_propagate_recursion (mo, X, Y, log_p, path_length, start, stop, max_size, pv); pviterbi_propagate_free (&pv, mo->N, mo->max_offset_x, mo->max_offset_y, Y->length); return path_seq; #undef CUR_PROC }
QStandardItem *TraitColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); item->setData(CT_TRAIT, DwarfModel::DR_COL_TYPE); item->setData(0, DwarfModel::DR_SPECIAL_FLAG); //default, special flag stores the alpha for the border short raw_value = d->trait(m_trait_id); short rating = raw_value; QStringList infos; if (m_trait){ infos << m_trait->level_message(raw_value).append(m_trait->belief_conficts_msgs(raw_value,d->trait_conflicts(m_trait_id))); }else{ infos << tr("Unknown trait"); } if(raw_value < 0){ infos << tr("This unit doesn't have this trait!"); } if (d->trait_is_active(m_trait_id)==false) infos << tr("Not an active trait for this dwarf."); int conflicting_belief_count = 0; if (m_trait){ infos << m_trait->skill_conflicts_msgs(raw_value); infos << m_trait->special_messages(raw_value); conflicting_belief_count = m_trait->get_conflicting_beliefs().count(); if(conflicting_belief_count > 0){ infos << tr("<br/>This trait can conflict with %1").arg(m_trait->belief_conflicts_names()); } if(m_trait->valued_inversely()){ infos << Trait::inverted_message; if(raw_value != -1) rating = 100 - raw_value; } } infos.removeAll(""); if(d->trait_is_conflicted(m_trait_id) && conflicting_belief_count > 0){ int alpha = 255 * ((float)d->trait_conflicts(m_trait_id).count() / (float)conflicting_belief_count); item->setData(alpha, DwarfModel::DR_SPECIAL_FLAG); } item->setText(QString::number(raw_value)); item->setData(rating, DwarfModel::DR_SORT_VALUE); item->setData(rating, DwarfModel::DR_RATING); item->setData(rating, DwarfModel::DR_DISPLAY_RATING); item->setData(raw_value, DwarfModel::DR_EXPORT); set_export_role(DwarfModel::DR_EXPORT); QString tooltip = QString("<center><h3>%1</h3> %2</center><br/>%3<br/>%4") .arg(m_title) .arg(tr("<b>Raw Value: %1</b>").arg(raw_value)) .arg(infos.join("<br/>")) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
void test_cell_add_neighbour(void) { printf("\ntest_cell_add_neighbour\n"); s_cell cells[4]; int c, result; uint8_t nb_cells; nb_cells = 3; for (c = 0; c < 4; c++) { init_cell(&cells[c], c, nb_cells); } result = cell_add_neighbour(&cells[0], &cells[1]); assert_int_equals(result, CELL_ADD_NEIGHBOUR_OK); assert_int_equals(cells[0].nb_neighbours, 1); assert_int_equals(cells[1].nb_neighbours, 1); result = cell_add_neighbour(&cells[0], &cells[1]); assert_int_equals(result, CELL_ERROR_ALREADY_NEIGHBOUR); assert_int_equals(cells[0].nb_neighbours, 1); assert_int_equals(cells[1].nb_neighbours, 1); cell_add_neighbour(&cells[0], &cells[2]); result = cell_add_neighbour(&cells[0], &cells[3]); assert_int_equals(result, CELL_ERROR_MAX_NEIGHBOURS_REACHED); assert_int_equals(cells[0].nb_neighbours, nb_cells - 1); assert_int_equals(cells[3].nb_neighbours, 0); for (c = 0; c < 4; c++) { free_cell(&cells[c]); } }
void test_cell_set_nb_pawns(void) { printf("\ntest_cell_set_nb_pawns\n"); s_cell c; s_player p; int result; init_cell(&c, 1, 4); init_player(&p, 1, "test", 1, STRATEGY_NONE, 10); result = cell_set_nb_pawns(&c, 13); assert_int_equals(result, CELL_ERROR_SET_PAWNS_NO_OWNER); assert_int_equals(c.nb_pawns, 0); cell_set_owner(&c, &p); result = cell_set_nb_pawns(&c, 13); assert_int_equals(result, CELL_ERROR_SET_PAWNS_NOT_ENOUGH_PAWNS); assert_int_equals(c.nb_pawns, 0); result = cell_set_nb_pawns(&c, 10); assert_int_equals(result, CELL_SET_PAWNS_OK); assert_int_equals(c.nb_pawns, 10); free_cell(&c); }
/** * Function to initalise the board. * * @param s_board *b The board to initialise * @param uint8_t nb_cells The board's number of cells * @param uint8_t nb_players The number of players * * @return int 1 if the board is correctly initialised, * ERROR_INIT_BOARD_INVALID_CELLS_NUMBER if the cells number is lower than * 1, ERROR_INIT_BOARD_INVALID_PLAYERS_NUMBER if the players number is * lower than 1. */ int init_board(s_board *b, uint8_t nb_cells, uint8_t nb_players) { int c; if (nb_cells < 1) { return ERROR_INIT_BOARD_INVALID_CELLS_NUMBER; } if (nb_players < 1) { return ERROR_INIT_BOARD_INVALID_PLAYERS_NUMBER; } b->nb_cells = nb_cells; b->cells = (s_cell*) calloc((size_t) nb_cells, sizeof(s_cell)); b->nb_total_players = nb_players; b->nb_players = 0; b->players = (s_player **) calloc((size_t) nb_players, sizeof(s_player *)); for (c = 0; c < nb_cells; c++) { init_cell(&b->cells[c], c + 1, nb_cells); } return INIT_BOARD_OK; }
QStandardItem *FlagColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); item->setData(CT_FLAGS, DwarfModel::DR_COL_TYPE); item->setData(false,DwarfModel::DR_SPECIAL_FLAG); //default short rating = 0; if(d->get_flag_value(m_bit_pos)) rating = 1; //check to fix butchering pets. currently this will cause the butchered parts to still be recognized as a pet //and they'll put them into a burial recepticle, but won't use them as a food source if(m_bit_pos == 49){ if(d->is_pet()){ item->setToolTip(tr("<b>Please turn off pet availability first.</b><br/><br/>Sorry, pets cannot be butchered due to technical limitations!")); item->setData(QBrush(QColor(187,34,34,200)),Qt::BackgroundColorRole); item->setData(true,DwarfModel::DR_SPECIAL_FLAG); //indicates that the cell is disabled rating = -1; }else if(!d->get_caste()->can_butcher()){ item->setToolTip(tr("<b>This creature cannot be butchered!</b>")); item->setData(QBrush(QColor(187,34,34,200)),Qt::BackgroundColorRole); item->setData(true,DwarfModel::DR_SPECIAL_FLAG); //indicates that the cell is disabled rating = -1; } } item->setData(rating, DwarfModel::DR_SORT_VALUE); item->setData(m_bit_pos, DwarfModel::DR_LABOR_ID); item->setData(m_set->name(), DwarfModel::DR_SET_NAME); return item; }
QStandardItem *HappinessColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); QString pixmap_name = QString(":status/img/%1.png").arg(Dwarf::happiness_name(d->get_happiness())); if(pixmap_name=="") pixmap_name = ":img/question-frame.png"; item->setData(QIcon(pixmap_name), Qt::DecorationRole); item->setData(CT_HAPPINESS, DwarfModel::DR_COL_TYPE); item->setData(d->get_raw_happiness(), DwarfModel::DR_SORT_VALUE); QString tooltip = QString("<center><h3>%1</h3><h4>%2 (%3)</h4></center><p>%4</p>%5") .arg(m_title) .arg(Dwarf::happiness_name(d->get_happiness())) .arg(d->get_raw_happiness()) .arg(d->get_thought_desc()) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); QColor bg = m_colors[d->get_happiness()]; // item->setBackground(QBrush(bg)); item->setData(bg,Qt::BackgroundColorRole); return item; }
static int resize_line(struct line *line, unsigned int width) { struct cell *tmp; int ret; if (!line) return -EINVAL; if (!width) width = DEFAULT_WIDTH; if (line->size < width) { tmp = realloc(line->cells, width * sizeof(struct cell)); if (!tmp) return -ENOMEM; line->cells = tmp; while (line->size < width) { ret = init_cell(&line->cells[line->size]); if (ret) return ret; line->size++; } } else if (line->size > width) { while (line->size > width) { line->size--; destroy_cell(&line->cells[line->size]); } } return 0; }
QStandardItem *EquipmentColumn::build_cell(Dwarf *d){ QStandardItem *item = init_cell(d); QColor rating_color = QColor(69,148,21); float rating = d->get_uniform_rating(); float coverage = d->get_coverage_rating(); if(coverage < 100){ //prioritize coverage rating = coverage; rating_color = Item::color_uncovered(); }else{ if(rating < 100) //missing uniform items rating_color = Item::color_missing(); } float sort_val = rating - d->get_inventory_wear(); item->setData(d->get_inventory_wear(),DwarfModel::DR_SPECIAL_FLAG); item->setBackground(QBrush(rating_color)); item->setData(CT_EQUIPMENT, DwarfModel::DR_COL_TYPE); item->setData(rating, DwarfModel::DR_RATING); //other drawing 0-100 item->setData(sort_val, DwarfModel::DR_SORT_VALUE); set_export_role(DwarfModel::DR_RATING); QString tooltip = QString("<center><h3>%1</h3></center>%2%3") .arg(m_title) .arg(build_tooltip_desc(d)) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *TrainedColumn::build_cell(Dwarf *d){ QStandardItem *item = init_cell(d); QString desc = get_animal_trained_descriptor(d->trained_level()); float rating = (float)d->trained_level(); float sort_val = rating; QString draw_rating = QString::number(rating); QChar sym_master(0x263C); //masterwork symbol in df QChar sym_exceptional(0x2261); //3 horizontal lines QFontMetrics fm(DT->user_settings()->value("options/grid/font", QFont(DefaultFonts::getRowFontName(), DefaultFonts::getRowFontSize())).value<QFont>()); bool symbols_ok = false; if(fm.inFont(sym_master) && fm.inFont(sym_exceptional)){ symbols_ok = true; } if(rating == 7){ //tame rating = 50.0f; //don't draw tame animals, this has to be within the uberdelegate's ignore range sort_val = -1; draw_rating = tr(""); }else if(rating >= 1 && rating <= 6){ //trained levels if(symbols_ok){ if(rating == 1) draw_rating = tr("T"); else if(rating == 2) draw_rating = tr("-"); else if(rating == 3) draw_rating = tr("+"); else if(rating == 4) draw_rating = tr("*"); else if(rating == 5) draw_rating = sym_exceptional; else if(rating == 6) draw_rating = sym_master; } rating = (rating / 6.0f * 100.0f / 2.0f) + 50.0f; //scale from 50 to 100 }else if(rating == 0){ //semi-wild (medium red square) rating = 30.0f; draw_rating = tr("Sw"); }else{ //wild, unknown (large red square) rating = 5.0f; sort_val = -2; draw_rating = tr("W"); } // item->setBackground(QBrush(QColor(225,225,225))); item->setData(CT_TRAINED, DwarfModel::DR_COL_TYPE); item->setData(draw_rating, DwarfModel::DR_DISPLAY_RATING); //numeric drawing, single digits item->setData(rating, DwarfModel::DR_RATING); //other drawing 0-100 item->setData(sort_val, DwarfModel::DR_SORT_VALUE); set_export_role(DwarfModel::DR_RATING); QString tooltip = QString("<center><h3>%1</h3></center>%2") .arg(desc) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
cell* init_row(int width) { cell* cells = malloc(sizeof(cell)*width); int i; for(i = 0; i < width; i++) { cells[i] = init_cell(); } return cells; }
void System:: reset() { now_ = 0; init_cell(); init_outer_limit(); init_particles(); }
void test_free_cell(void) { printf("\ntest_free_cell\n"); s_cell c; init_cell(&c, 1, 4); free_cell(&c); assert_null(c.neighbours); }
void graph::init_graph() { init_dir32(); init_cell(); init_font(); image::register_image_file("png",create_image_png); image::register_image_file("jpg",create_image_jpg); get_map()->init_map(); //image::register_image_file("zgp",create_image_zgp); //简单的文件可以用register_image_file //复杂的多帧文件必须用regist_file_source }
void test_cell_set_owner(void) { printf("\ntest_cell_set_owner\n"); s_cell c; s_player p; init_cell(&c, 1, 4); init_player(&p, 1, "test", 1, STRATEGY_NONE, 10); assert_null(c.owner); cell_set_owner(&c, &p); assert_str_equals(c.owner->name, "test"); assert_int_equals(c.owner->nb_cells, 1); free_cell(&c); }
void test_init_cell(void) { printf("\ntest_init_cell\n"); s_cell c; int result; result = init_cell(&c, 1, 4); assert_null(c.owner); assert_int_equals(result, 1); assert_int_equals(c.id, 1); assert_int_equals(c.nb_pawns, 0); assert_int_equals(c.nb_neighbours, 0); assert_int_equals(c.nb_max_neighbours, 3); free_cell(&c); }
QStandardItem *AttributeColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); Attribute a = d->get_attribute(m_attribute_type); QString descriptor = a.get_descriptor(); float rating = a.rating() * 100.0f; //if this is an animal, we won't have any caste balanced ratings, so just take a rating out of an arbitrary absolute of 2250 //that means any rating over 2250 will essentially be 100%, which is pretty reasonable, since //scaling to 0-5000 makes the drawn squares fairly small if(d->is_animal()) rating = (float)(a.get_value() / 2250.0f * 100.0f); //the rating is used for drawing, should be between 0-100 for attributes item->setData(rating, DwarfModel::DR_RATING); item->setData(roundf(rating), DwarfModel::DR_DISPLAY_RATING); //flag so we know if we need to draw a border or not item->setData(a.syndrome_names().count(),DwarfModel::DR_SPECIAL_FLAG); if(DT->multiple_castes()){ descriptor != "" ? descriptor = "(" + descriptor + ")" : ""; } item->setData(CT_ATTRIBUTE, DwarfModel::DR_COL_TYPE); refresh_sort(d,m_current_sort); if(!descriptor.isEmpty()){ descriptor = QString("%1%2").arg("<br/>").arg(descriptor); } QString syn_desc = a.get_syndrome_desc(); if(!syn_desc.isEmpty()){ syn_desc = QString("%1%1%2").arg("<br/>").arg(syn_desc); } QString tooltip = QString("<center><h3>%1</h3><b>%2</b>%3%4%5</center>") .arg(m_title) .arg(a.get_value_display()) .arg(descriptor) .arg(syn_desc) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *AttributeColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); Attribute a = d->get_attribute((int)m_attribute_type); short rawVal = a.value(); QString descriptor = a.get_descriptor(); float rating = a.rating() * 100.0f; //if this is an animal, we won't have any caste balanced ratings, so just take a rating out of an arbitrary absolute of 2250 //that means any rating over 2250 will essentially be 100%, which is pretty reasonable, since //scaling to 0-5000 makes the drawn squares fairly small if(d->is_animal()) rating = (float)(a.value() / 2250.0f * 100.0f); //the rating is used for drawing, should be between 0-100 for attributes item->setData(rating, DwarfModel::DR_RATING); item->setData(roundf(rating), DwarfModel::DR_DISPLAY_RATING); //if no descriptor (middle ranges) then set the rating to a middle (hidden) value //this is primarily for vanilla, as the mid ranges don't have a description and are hidden in game //for multiple castes, we may as well draw everything as the descriptors can be different for each caste //since multiple castes append 'for a <caste name>' to the descriptor, this will only ever affect vanilla for now if(!DT->multiple_castes && a.get_descriptor_rank() == 4){ item->setData(50.0f, DwarfModel::DR_RATING); //49-51 aren't drawn for attributes }else{ descriptor != "" ? descriptor = "(" + descriptor + ")" : ""; } //sort on the raw value item->setData(rawVal, DwarfModel::DR_SORT_VALUE); item->setData(CT_ATTRIBUTE, DwarfModel::DR_COL_TYPE); QString tooltip = QString("<center><h3>%1</h3></center><b>%2</b> %3%4") .arg(m_title) .arg(a.get_value_display()) .arg(descriptor) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
QStandardItem *TraitColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); item->setData(CT_TRAIT, DwarfModel::DR_COL_TYPE); short score = d->trait(m_trait_id); QString msg = "???"; if (m_trait) msg = tr("%1 (Raw: %2)").arg(m_trait->level_message(score)).arg(score); if (d->trait_is_active(m_trait_id)==false) msg += tr("<br/><br/>Not an active trait for this dwarf."); QString temp = m_trait->conflicts_messages(score); if(!temp.isEmpty()) msg += tr("<br/><br/>%1").arg(temp); temp = m_trait->special_messages(score); if(!temp.isEmpty()) msg += tr("<br/><br/>%1").arg(temp); int rating = score; QString warning = ""; if(GameDataReader::ptr()->get_trait(m_trait_id)->inverted){ warning = tr("<br/><h5 style=\"margin:0;\"><font color=red>*This trait's score should be valued inversely!</font></h5>"); rating = 100 - score; } item->setText(QString::number(score)); item->setData(rating, DwarfModel::DR_SORT_VALUE); item->setData(rating, DwarfModel::DR_RATING); item->setData(rating, DwarfModel::DR_DISPLAY_RATING); QString tooltip = QString("<center><h3>%1</h3></center>%2<br>%3%4") .arg(m_title) .arg(msg) .arg(warning) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
void test_cell_are_neighbours(void) { printf("\ntest_cell_are_neighbours\n"); s_cell cells[3]; int c; uint8_t nb_cells; nb_cells = 3; for (c = 0; c < 4; c++) { init_cell(&cells[c], c, nb_cells); } cell_add_neighbour(&cells[0], &cells[1]); cell_add_neighbour(&cells[1], &cells[2]); assert_int_equals(cell_are_neighbours(&cells[0], &cells[1]), 1); assert_int_equals(cell_are_neighbours(&cells[1], &cells[2]), 1); assert_int_equals(cell_are_neighbours(&cells[0], &cells[2]), 0); for (c = 0; c < 3; c++) { free_cell(&cells[c]); } }
QStandardItem *CurrentJobColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); short job_id = d->current_job_id(); QString pixmap_name(":img/question-frame.png"); DwarfJob *job = GameDataReader::ptr()->get_job(job_id); if (job) { int pref_id = -1; if(!job->reactionClass.isEmpty() && !d->current_sub_job_id().isEmpty()) { Reaction* reaction = d->get_reaction(); if(reaction!=0) { //job_type = DwarfJob::get_type(reaction->skill()); pref_id = GameDataReader::ptr()->get_pref_from_skill(reaction->skill_id()); } } if(pref_id != -1) { pixmap_name = ":/profession/img/profession icons/prof_" + QString::number(pref_id+1) + ".png"; //offset for the image name item->setData(QColor(50,50,50), DwarfModel::DR_DEFAULT_BG_COLOR); //shade the background } else { DwarfJob::DWARF_JOB_TYPE job_type = job->type; TRACE << "Dwarf: " << d->nice_name() << " job -" << job_id << ": (" << job->description << "," << job_type << ")"; switch (job_type) { case DwarfJob::DJT_IDLE: pixmap_name = ":status/img/cross-small.png"; break; case DwarfJob::DJT_ON_BREAK: pixmap_name = ":status/img/hourglass.png"; break; case DwarfJob::DJT_SOLDIER: pixmap_name = ":status/img/exclamation-shield-frame.png"; break; case DwarfJob::DJT_DIG: pixmap_name = ":status/img/shovel.png"; break; case DwarfJob::DJT_CUT: pixmap_name = ":status/img/tree--minus.png"; break; case DwarfJob::DJT_SLEEP: pixmap_name = ":status/img/moon.png"; break; case DwarfJob::DJT_DRINK: pixmap_name = ":status/img/ale.png"; break; case DwarfJob::DJT_FOOD: pixmap_name = ":status/img/cutlery.png"; break; case DwarfJob::DJT_BUILD: pixmap_name = ":status/img/hammer--plain.png"; break; case DwarfJob::DJT_HAUL: pixmap_name = ":status/img/cart-box.png"; break; case DwarfJob::DJT_FIGHT: pixmap_name = ":status/img/crossed-swords.png"; break; case DwarfJob::DJT_MOOD: pixmap_name = ":img/exclamation-red-frame.png"; break; case DwarfJob::DJT_FORGE: pixmap_name = ":status/img/status_forge.png"; break; case DwarfJob::DJT_MEDICAL: pixmap_name = ":status/img/first_aid_kit.png"; break; case DwarfJob::DJT_WAX_WORKING: pixmap_name = ":status/img/lump.png"; break; case DwarfJob::DJT_POTTERY: pixmap_name = ":status/img/pot.png"; break; case DwarfJob::DJT_PRESSING: pixmap_name = ":status/img/cup2.png"; break; case DwarfJob::DJT_SPINNING: pixmap_name = ":status/img/spinning.png"; break; case DwarfJob::DJT_BEE_KEEPING: pixmap_name = ":status/img/bee_i_guess.png"; break; case DwarfJob::DJT_STAIRS: pixmap_name = ":status/img/stairs.png"; break; case DwarfJob::DJT_FORTIFICATION: pixmap_name = ":status/img/wall-brick.png"; break; case DwarfJob::DJT_ENGRAVE: pixmap_name = ":status/img/paint-brush.png"; break; case DwarfJob::DJT_LEAF: pixmap_name = ":status/img/leaf.png"; break; case DwarfJob::DJT_BUILD_REMOVE: pixmap_name = ":status/img/hammer--minus.png"; break; case DwarfJob::DJT_BAG_ADD: pixmap_name = ":status/img/paper-bag--plus.png"; break; case DwarfJob::DJT_MONEY: pixmap_name = ":status/img/money-coin.png"; break; case DwarfJob::DJT_TAX: pixmap_name = ":status/img/money--arrow.png"; break; case DwarfJob::DJT_RETURN: pixmap_name = ":status/img/arrow-return.png"; break; case DwarfJob::DJT_PARTY: pixmap_name = ":status/img/rubber-balloons.png"; break; case DwarfJob::DJT_SOAP: pixmap_name = ":status/img/soap.png"; break; case DwarfJob::DJT_SEEK: pixmap_name = ":status/img/eye--arrow.png"; break; case DwarfJob::DJT_GEM_CUT: pixmap_name = ":status/img/diamond.png"; break; case DwarfJob::DJT_GEM_ENCRUST: pixmap_name = ":status/img/ruby.png"; break; case DwarfJob::DJT_SEEDS: pixmap_name = ":status/img/beans.png"; break; case DwarfJob::DJT_LEAF_ARROW: pixmap_name = ":status/img/leaf--arrow.png"; break; case DwarfJob::DJT_WATER_ARROW: pixmap_name = ":status/img/water--arrow.png"; break; case DwarfJob::DJT_TOMBSTONE: pixmap_name = ":status/img/headstone-rip.png"; break; case DwarfJob::DJT_ANIMAL: pixmap_name = ":status/img/animal.png"; break; case DwarfJob::DJT_BOOK_OPEN: pixmap_name = ":status/img/book-open-list.png"; break; case DwarfJob::DJT_HANDSHAKE: pixmap_name = ":status/img/hand-shake.png"; break; case DwarfJob::DJT_CONSTRUCT: pixmap_name = ":status/img/hammer-screwdriver.png"; break; case DwarfJob::DJT_ABACUS: pixmap_name = ":status/img/abacus.png"; break; case DwarfJob::DJT_FURNACE: pixmap_name = ":status/img/fire.png"; break; case DwarfJob::DJT_REPORT: pixmap_name = ":status/img/balloon-prohibition.png"; break; case DwarfJob::DJT_JUSTICE: pixmap_name = ":status/img/balance.png"; break; case DwarfJob::DJT_SHIELD: pixmap_name = ":status/img/shield.png"; break; case DwarfJob::DJT_DEPOT: pixmap_name = ":status/img/wooden-box--arrow.png"; break; case DwarfJob::DJT_BROOM: pixmap_name = ":status/img/broom.png"; break; case DwarfJob::DJT_SWITCH: pixmap_name = ":status/img/switch.png"; break; case DwarfJob::DJT_CHAIN: pixmap_name = ":status/img/chain.png"; break; case DwarfJob::DJT_UNCHAIN: pixmap_name = ":status/img/chain-unchain.png"; break; case DwarfJob::DJT_FILL_WATER: pixmap_name = ":status/img/water--plus.png"; break; case DwarfJob::DJT_MARKET: pixmap_name = ":status/img/store-market-stall.png"; break; case DwarfJob::DJT_KNIFE: pixmap_name = ":status/img/knife_bloody.png"; break; case DwarfJob::DJT_BOW: pixmap_name = ":status/img/bow.png"; break; case DwarfJob::DJT_CHEESE: pixmap_name = ":status/img/cheese.png"; break; case DwarfJob::DJT_HELM: pixmap_name = ":status/img/helm.png"; break; case DwarfJob::DJT_GLOVE: pixmap_name = ":status/img/glove.png"; break; case DwarfJob::DJT_BOOT: pixmap_name = ":status/img/boot.png"; break; case DwarfJob::DJT_ARMOR: pixmap_name = ":status/img/armor.png"; break; case DwarfJob::DJT_FISH: pixmap_name = ":status/img/carp.png"; break; case DwarfJob::DJT_RAW_FISH: pixmap_name = ":status/img/fish.png"; break; case DwarfJob::DJT_MILK: pixmap_name = ":status/img/milk.png"; break; case DwarfJob::DJT_REST: pixmap_name = ":status/img/bandaid--exclamation.png"; break; case DwarfJob::DJT_COOKING: pixmap_name = ":status/img/meat.png"; break; case DwarfJob::DJT_BUCKET_POUR: pixmap_name = ":status/img/paint-can--arrow.png"; break; case DwarfJob::DJT_GIVE_LOVE: pixmap_name = ":status/img/heart--arrow.png"; break; case DwarfJob::DJT_DYE: pixmap_name = ":status/img/color--plus.png"; break; case DwarfJob::DJT_WEAPON: pixmap_name = ":status/img/weapon.png"; break; case DwarfJob::DJT_SWITCH_CONNECT: pixmap_name = ":status/img/switch-network.png"; break; case DwarfJob::DJT_ZONE_ADD: pixmap_name = ":status/img/zone--plus.png"; break; case DwarfJob::DJT_CRAFTS: pixmap_name = ":status/img/crown.png"; break; case DwarfJob::DJT_GEAR: pixmap_name = ":status/img/gear-small.png"; break; case DwarfJob::DJT_TROUBLE: pixmap_name = ":status/img/hand-finger.png"; break; case DwarfJob::DJT_STORAGE: pixmap_name = ":status/img/box--plus.png"; break; case DwarfJob::DJT_STORE_OWNED: pixmap_name = ":status/img/safe--plus.png"; break; case DwarfJob::DJT_CABINET_MAKE: pixmap_name = ":status/img/drawer--plus.png"; break; case DwarfJob::DJT_CABINET_STORE: pixmap_name = ":status/img/drawer-open.png"; break; case DwarfJob::DJT_DOOR_MAKE: pixmap_name = ":status/img/door--plus.png"; break; case DwarfJob::DJT_CHAIR_MAKE: pixmap_name = ":status/img/chair--plus.png"; break; case DwarfJob::DJT_BREW: pixmap_name = ":status/img/ale--plus.png"; break; default: case DwarfJob::DJT_DEFAULT: pixmap_name = ":status/img/control_play_blue.png"; break; } } } item->setData(QIcon(pixmap_name), Qt::DecorationRole); item->setData(CT_IDLE, DwarfModel::DR_COL_TYPE); item->setData(d->current_job_id(), DwarfModel::DR_SORT_VALUE); // QColor bg = QColor(175,175,175); // if(DT->user_settings()->value("options/grid/shade_cells",true)==false) // bg = QColor(255,255,255); // item->setData(bg,Qt::BackgroundColorRole); QString tooltip = QString("<center><h3>%1</h3>%2 (%3)%4</center>") .arg(m_title) .arg(d->current_job()) .arg(d->current_job_id()) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
/*============================================================================*/ static cell * pviterbi_propagate_step (ghmm_dpmodel *mo, ghmm_dpseq * X, ghmm_dpseq * Y, cell * start, cell * stop, double * log_p, plocal_propagate_store_t * pv) { #define CUR_PROC "pviterbi_step" /* printf("---- propagate step -----\n"); */ int u, v, j, i; double value, max_value, previous_prob; /* int len_path = mo->N*len; the length of the path is not known apriori */ int start_x, start_y, stop_x, stop_y; double log_b_i, log_in_a_ij; cell * middle = NULL; int middle_x; double (*log_in_a)(plocal_propagate_store_t*, int, int, ghmm_dpseq*, ghmm_dpseq*, int, int); log_in_a = &sget_log_in_a_prop; init_start_stop(start, stop, X, Y, &start_x, &start_y, &stop_x, &stop_y); middle_x = start_x + (stop_x - start_x) / 2; /* if (mo->model_type & kSilentStates && */ /* mo->silent != NULL && */ /* mo->topo_order == NULL) { */ /* ghmm_dmodel_topo_order( mo ); */ /* } */ init_phi_prop(pv, X, Y, start, stop); #ifdef DEBUG if (start != NULL && mo->s[start->state].offset_y == 0) { for (u = 0; u<=mo->max_offset_x; u++) { printf("row %i of phi\n", u); for (v = start_y - 1; v < stop_y; v++) { printf("phi(0, %i, %i): %f, ", v, start->state, get_phi_prop(pv, 0, v, 0, 0, start->state)); } printf("\n\n"); } } #endif /* u, v > 0 */ /** THIS IS THE MAIN RECURRENCE **/ /* printf("Main loop x from %i to %i and y from %i to %i\n", start_x + mo->max_offset_x + 1, stop_x, start_y, stop_y);*/ for (u = start_x + mo->max_offset_x + 1; u < stop_x; u++) { for (v = start_y - mo->max_offset_y; v < stop_y; v++) { for (j = 0; j < mo->N; j++) { /** initialization of phi (lookback matrix) **/ set_phi_prop(pv, u, v, j, +1); set_end_of_first(pv, 0, v, j, NULL); } for (i = 0; i < mo->N; i++) { /* Determine the maximum */ /* max_phi = phi[i] + log_in_a[j][i] ... */ if (!(mo->model_type & GHMM_kSilentStates) || !mo->silent[i]) { max_value = -DBL_MAX; set_end_of_first(pv, 0, v, i, NULL); for (j = 0; j < mo->s[i].in_states; j++) { /* look back in the phi matrix at the offsets */ previous_prob = get_phi_prop(pv, u, v, mo->s[i].offset_x, mo->s[i].offset_y, mo->s[i].in_id[j]); log_in_a_ij = (*log_in_a)(pv, i, j, X, Y, u, v); if ( previous_prob != +1 && log_in_a_ij != +1) { value = previous_prob + log_in_a_ij; if (value > max_value) { max_value = value; /* Critical point for the propagate algorithm if we are at the middle point of sequence X store this at the end point of the first alignment */ if (u - middle_x < mo->s[i].offset_x && u - middle_x >= 0) { cell * end_of_first = init_cell(u - (mo->s[i].offset_x - 1), v - (mo->s[i].offset_y - 1), i, mo->s[i].in_id[j], previous_prob, log_in_a_ij); if (get_end_of_first(pv, u, v, 0, 0, i) != NULL) { cell * old = get_end_of_first(pv, u, v, 0, 0, i); m_free(old); } set_end_of_first(pv, u, v, i, end_of_first); } else { /* at all other points simply propagate the values on */ set_end_of_first(pv, u, v, i, get_end_of_first(pv, u, v, mo->s[i].offset_x, mo->s[i].offset_y, mo->s[i].in_id[j])); } } } else {;} /* fprintf(stderr, " %d --> %d = %f, \n", i,i,v->log_in_a[i][i]); */ } #ifdef DEBUG int emission = ghmm_dpmodel_pair(ghmm_dpseq_get_char(X, mo->s[i].alphabet, u), ghmm_dpseq_get_char(Y, mo->s[i].alphabet, v), mo->size_of_alphabet[mo->s[i].alphabet], mo->s[i].offset_x, mo->s[i].offset_y); if (emission > ghmm_dpmodel_emission_table_size(mo, i)){ printf("State %i\n", i); ghmm_dpmodel_state_print(&(mo->s[i])); printf("charX: %i charY: %i alphabet size: %i emission table: %i emission index: %i\n", ghmm_dpseq_get_char(X, mo->s[i].alphabet, u), ghmm_dpseq_get_char(Y, mo->s[i].alphabet, v), mo->size_of_alphabet[mo->s[i].alphabet], ghmm_dpmodel_emission_table_size(mo, i), emission); } #endif log_b_i = log_b_prop(pv, i, ghmm_dpmodel_pair(ghmm_dpseq_get_char(X, mo->s[i].alphabet, u), ghmm_dpseq_get_char(Y, mo->s[i].alphabet, v), mo->size_of_alphabet[mo->s[i].alphabet], mo->s[i].offset_x, mo->s[i].offset_y)); /* No maximum found (that is, state never reached) or the output O[t] = 0.0: */ if (max_value == -DBL_MAX ||/* and then also: (v->psi[t][j] == -1) */ log_b_i == +1 ) { set_phi_prop(pv, u, v, i, 1); } else set_phi_prop(pv, u, v, i, max_value + log_b_i); } } /* complete time step for emitting states */ /* last_osc = osc; */ /* save last transition class */ /*if (mo->model_type & kSilentStates) { p__viterbi_silent( mo, t, v ); }*/ /* complete time step for silent states */ /************** for (j = 0; j < mo->N; j++) { printf("\npsi[%d],in:%d, phi=%f\n", t, v->psi[t][j], v->phi[j]); } for (i = 0; i < mo->N; i++){ printf("%d\t", former_matchcount[i]); } for (i = 0; i < mo->N; i++){ printf("%d\t", recent_matchcount[i]); } ****************/ } /* End for v in Y */ /* Next character in X */ /* push back the old phi values */ push_back_phi_prop(pv, Y->length); } /* End for u in X */ /* Termination */ max_value = -DBL_MAX; /* for the last segment search for the maximum probability at the end of the two sequences */ if (stop == NULL){ for (j = 0; j < mo->N; j++){ #ifdef DEBUG /* printf("phi(len_x)(len_y)(%i)=%f\n", j, pv->phi[0][stop_y-1][j]); ghmm_dpmodel_print_cell(pv->end_of_first[0][stop_y - 1][j]); */ #endif if ( get_phi_prop(pv, stop_x - 1, stop_y - 1, 0, 0, j) != +1 && get_phi_prop(pv, stop_x - 1, stop_y - 1, 0, 0, j) > max_value) { max_value = get_phi_prop(pv, stop_x - 1, stop_y - 1, 0, 0, j); middle = get_end_of_first(pv, stop_x - 1, stop_y - 1, 0, 0, j); } } } /* traceback for the interior segments have to start with the previous state of the middle beacuse the path has to be connected */ else { if ( get_phi_prop(pv, stop_x - 1, stop_y - 1, 0, 0, stop->previous_state) != +1 ) { max_value = get_phi_prop(pv, stop_x - 1, stop_y - 1, 0, 0, stop->previous_state); middle = get_end_of_first(pv, stop_x - 1, stop_y - 1, 0, 0, stop->previous_state); } } if (max_value == -DBL_MAX) { /* Sequence can't be generated from the model! */ *log_p = +1; } else { *log_p = max_value; } return middle; #undef CUR_PROC }
/*============================================================================*/ static void init_phi_prop (plocal_propagate_store_t * pv, ghmm_dpseq * X, ghmm_dpseq * Y, cell * start, cell * stop) { #define CUR_PROC "init_phi_prop" int u, v, j, i, off_x, y; double value, max_value, previous_prob, log_b_i, log_in_a_ij ; int start_x, start_y, stop_x, stop_y, middle_x; ghmm_dpmodel * mo = pv->mo; double (*log_in_a)(plocal_propagate_store_t*, int, int, ghmm_dpseq*, ghmm_dpseq*, int, int); log_in_a = &sget_log_in_a_prop; init_start_stop(start, stop, X, Y, &start_x, &start_y, &stop_x, &stop_y); pv->start_x = start_x; pv->start_y = start_y; middle_x = start_x + (stop_x - start_x) / 2; /* to be sure that we do not look up something out of the bounds set the whole matrix to 1 */ /* Initialize the lookback matrix (for positions [-offsetX,0], [0, len_y]*/ for (off_x=0; off_x<mo->max_offset_x + 1; off_x++) for (y=0; y<Y->length + mo->max_offset_y + 1; y++) for (j=0; j<mo->N; j++) { pv->phi[off_x][y][j] = +1; } /* Inititalize the end_of_first matrix */ for (off_x=0; off_x<mo->max_offset_x + 1; off_x++) for (y=0; y<Y->length + mo->max_offset_y + 1; y++) for (j=0; j<mo->N; j++) if (pv->end_of_first[off_x][y][j]) { /* m_free(pv->end_of_first[off_x][y][j]); */ pv->end_of_first[off_x][y][j] = NULL; } if (mo->model_type & GHMM_kSilentStates) { /* could go into silent state at t=0 */ /*p__viterbi_silent( mo, t=0, v);*/ } /*for (j = 0; j < mo->N; j++) { printf("\npsi[%d],in:%d, phi=%f\n", t, v->psi[t][j], v->phi[j]); } for( i = 0; i < mo->N; i++){ printf("%d\t", former_matchcount[i]); } for (i = 0; i < mo->N; i++){ printf("%d\t", recent_matchcount[i]); }*/ /* initialize for offsets > 1 (u < max_offset_x, v < max_offset_y) */ /* this is in principle the same as the main recurrence but adds initial probabilities to states that cannot be inhabitated at u=0, v=0 because of greater offsets than one */ /* u, v <= max offsets */ for (u = -1; u <= mo->max_offset_x; u++) { for (v = start_y - mo->max_offset_y; v < stop_y; v++) { for (j = 0; j < mo->N; j++) { /** initialization of phi (lookback matrix) **/ set_phi_prop(pv, u, v, j, 1); /** traceback for the propagate algorithm **/ set_end_of_first(pv, u, v, j, NULL); } for (i = 0; i < mo->N; i++) { /* Determine the maximum */ /* max_phi = phi[i] + log_in_a[j][i] ... */ if (!(mo->model_type & GHMM_kSilentStates) || !mo->silent[i] ) { max_value = -DBL_MAX; set_end_of_first(pv, u, v, i, NULL); for (j = 0; j < mo->s[i].in_states; j++) { /* look back in the phi matrix at the offsets */ previous_prob = get_phi_prop(pv, u, v, mo->s[i].offset_x, mo->s[i].offset_y, mo->s[i].in_id[j]); log_in_a_ij = (*log_in_a)(pv, i, j, X, Y, u, v); if ( previous_prob != +1 && log_in_a_ij != +1) { value = previous_prob + log_in_a_ij; if (value > max_value) { max_value = value; /* Critical point for the propagate algorithm if we are at the middle point of sequence X store this at the end point of the first alignment */ if (u - middle_x < mo->s[i].offset_x && u - middle_x >= 0) { cell * end_of_first = init_cell(u - (mo->s[i].offset_x - 1), v - (mo->s[i].offset_y - 1), i, mo->s[i].in_id[j], previous_prob, log_in_a_ij); if (get_end_of_first(pv, u, v, 0, 0, i) != NULL) { cell * old = get_end_of_first(pv, u, v, 0, 0, i); m_free(old); } set_end_of_first(pv, u, v, i, end_of_first); } else { /* at all other points simply propagate the values on */ set_end_of_first(pv, u, v, i, get_end_of_first(pv, u, v, mo->s[i].offset_x, mo->s[i].offset_y, mo->s[i].in_id[j])); } } } else {;} /* fprintf(stderr, " %d --> %d = %f, \n", i,i,v->log_in_a[i][i]); */ } #ifdef DEBUG int emission = ghmm_dpmodel_pair(ghmm_dpseq_get_char(X, mo->s[i].alphabet, u + start_x), ghmm_dpseq_get_char(Y, mo->s[i].alphabet, v), mo->size_of_alphabet[mo->s[i].alphabet], mo->s[i].offset_x, mo->s[i].offset_y); if (emission > ghmm_dpmodel_emission_table_size(mo, i)){ printf("State %i\n", i); ghmm_dpmodel_state_print(&(mo->s[i])); printf("charX: %i charY: %i alphabet size: %i emission table: %i emission index: %i\n", ghmm_dpseq_get_char(X, mo->s[i].alphabet, u), ghmm_dpseq_get_char(Y, mo->s[i].alphabet, v), mo->size_of_alphabet[mo->s[i].alphabet], ghmm_dpmodel_emission_table_size(mo, i), emission); } #endif log_b_i = log_b_prop(pv, i, ghmm_dpmodel_pair(ghmm_dpseq_get_char(X, mo->s[i].alphabet, u + start_x), ghmm_dpseq_get_char(Y, mo->s[i].alphabet, v), mo->size_of_alphabet[mo->s[i].alphabet], mo->s[i].offset_x, mo->s[i].offset_y)); /* this is the difference from the main loop: check whether this state could be an initial state and add the initial probability */ if (log_b_i == +1 ) { set_phi_prop(pv, u, v, i, +1); } else { if (max_value == -DBL_MAX) set_phi_prop(pv, u, v, i, +1); else set_phi_prop(pv, u, v, i, max_value); /* if (mo->s[i].pi != 0 && mo->s[i].offset_x - 1 == u && mo->s[i].offset_y - 1 + start_y == v) { */ if (mo->s[i].log_pi != 1 && mo->s[i].offset_x - 1 == u && mo->s[i].offset_y - 1 + start_y == v){ set_phi_prop(pv, u, v, i, mo->s[i].log_pi); #ifdef DEBUG printf("Initial log prob state %i at (%i, %i) = %f\n", i, start_x + u, v, get_phi_prop(pv, u, v, 0, 0, i)); printf("Characters emitted X: %i, Y: %i\n", ghmm_dpseq_get_char(X, mo->s[i].alphabet, u + start_x), ghmm_dpseq_get_char(Y, mo->s[i].alphabet, v)); #endif } if (get_phi_prop(pv, u, v, 0, 0, i) != 1) { set_phi_prop(pv, u, v, i, get_phi_prop(pv, u, v, 0, 0, i) + log_b_i); } } } } /* complete time step for emitting states */ /* last_osc = osc; */ /* save last transition class */ /*if (mo->model_type & kSilentStates) { p__viterbi_silent( mo, t, v ); }*/ /* complete time step for silent states */ /************** for (j = 0; j < mo->N; j++) { printf("\npsi[%d],in:%d, phi=%f\n", t, v->psi[t][j], v->phi[j]); } for (i = 0; i < mo->N; i++){ printf("%d\t", former_matchcount[i]); } for (i = 0; i < mo->N; i++){ printf("%d\t", recent_matchcount[i]); } ****************/ } /* End for v in Y */ /* Next character in X */ /* push back the old phi values */ push_back_phi_prop(pv, Y->length); #ifdef DEBUG if (start != NULL && mo->s[start->state].offset_y == 0) { max_value = -DBL_MAX; i = -1; y = -1; off_x = -1; int x; for (x = 0; x<=mo->max_offset_x; x++) for (v = - mo->max_offset_y; v<Y->length; v++) { for (j=0; j<mo->N; j++) { if (get_phi_prop(pv, x, v, x, 0, j) >= max_value && get_phi_prop(pv, x, v, x, 0, j) < 1 - PROP_EPS) { max_value = get_phi_prop(pv, x, v, x, 0, j); i = j; off_x = x; y = v; } } } printf("u = %i start_x = %i off_x = %i ", u, start_x, off_x); printf("max log prob state %i at (%i, %i) = %f after pushback\n", i, start_x + u - (off_x - 1), y, get_phi_prop(pv, u, y, off_x, 0, i)); } #endif } /* End for u in X */ #undef CUR_PROC }
/*============================================================================*/ cell * ghmm_dpmodel_copy_cell(cell * c) { if (c) return init_cell(c->x, c->y, c->state, c->previous_state, c->log_p, c->log_a); else return NULL; }
QStandardItem *FlagColumn::build_cell(Dwarf *d) { QStandardItem *item = init_cell(d); item->setData(CT_FLAGS, DwarfModel::DR_COL_TYPE); item->setData(0,DwarfModel::DR_STATE); //default QString info_msg = ""; QString info_col_name = ""; short rating = 0; if(d->get_flag_value(m_bit_pos)) rating = 1; //check to fix butchering pets. currently this will cause the butchered parts to still be recognized as a pet //and they'll put them into a burial recepticle, but won't use them as a food source ViewColumn::CELL_STATE state = STATE_TOGGLE; if(m_bit_pos == FLAG_BUTCHER){ if(d->is_pet()){ info_msg = tr("<b>Pets cannot be slaughtered!</b>"); state = STATE_DISABLED; }else if(!d->get_caste() || !d->get_caste()->flags().has_flag(BUTCHERABLE)){ info_msg = tr("<b>This caste cannot be slaughtered!</b>"); state = STATE_DISABLED; }else if(rating == 1){ info_msg = tr("<b>This creature has been marked for slaughter.</b>"); state = STATE_PENDING; }else if(d->trained_level() >= Dwarf::unknown_trained){ info_msg = tr("<b>Captured wild animals cannot be butchered!</b>"); state = STATE_DISABLED; }else{ state = STATE_TOGGLE; } }else if(m_bit_pos == FLAG_GELD){ if(d->get_gender() != Dwarf::SEX_M){ info_msg = tr("<b>Only males can be gelded!</b>"); state = STATE_DISABLED; }else if(d->has_health_issue(eHealth::HI_GELDED,0)){ info_msg = tr("<b>This creature has already been gelded!</b>"); state = STATE_ACTIVE; }else if(rating == 1){ info_msg = tr("<b>This creature has been marked for gelding.</b>"); state = STATE_PENDING; }else if(!d->get_caste()->is_geldable()){ //check last as it's the most expensive info_msg = tr("<b>This caste is not geldable!</b>"); state = STATE_DISABLED; }else{ state = STATE_TOGGLE; } } item->setData(state,DwarfModel::DR_STATE); info_col_name = get_state_color(state).name();//item->data(Qt::BackgroundColorRole).value<QColor>().name(); item->setData(rating, DwarfModel::DR_SORT_VALUE); item->setData(m_bit_pos, DwarfModel::DR_OTHER_ID); item->setData(m_set->name(), DwarfModel::DR_SET_NAME); QString tooltip = QString("<center><h3>%1</h3>%2</center>%3") .arg(m_title) .arg(QString("<font color=%1>%2</font>").arg(info_col_name).arg(info_msg)) .arg(tooltip_name_footer(d)); item->setToolTip(tooltip); return item; }
void test_player_move_to_cell(void) { printf("\ntest_player_move_to_cell\n"); s_cell c1, c2, c3; s_player p1, p2; short result; init_cell(&c1, 1, 3); init_cell(&c2, 2, 3); init_cell(&c3, 3, 3); init_player(&p1, 1, "p1", 1, STRATEGY_NONE, 10); init_player(&p2, 2, "p2", 1, STRATEGY_NONE, 10); cell_add_neighbour(&c1, &c2); cell_add_neighbour(&c2, &c3); cell_set_owner(&c1, &p1); cell_set_nb_pawns(&c1, 10); cell_set_owner(&c3, &p2); cell_set_nb_pawns(&c3, 10); // test move all pawns from src cell result = player_move_to_cell(&p1, 10, &c1, &c2); assert_int_equals(result, PLAYER_ERROR_MOVE_ALL_PAWNS); // test move too many pawns result = player_move_to_cell(&p1, 11, &c1, &c2); assert_int_equals(result, PLAYER_ERROR_MOVE_NOT_ENOUGH_PAWNS); // test move to a cell too far away result = player_move_to_cell(&p1, 1, &c1, &c3); assert_int_equals(result, PLAYER_ERROR_MOVE_CELLS_NOT_NEIGHBOURS); // move no fight assert_int_equals(p1.nb_cells, 1); result = player_move_to_cell(&p1, 5, &c1, &c2); assert_int_equals(result, NO_FIGHT); assert_int_equals(c1.nb_pawns, 5); assert_int_equals(c2.nb_pawns, 5); assert_int_equals(p1.nb_pawns, 10); assert_int_equals(p1.nb_cells, 2); assert_int_equals(c2.owner->id, p1.id); // move fight win result = player_move_to_cell(&p2, 6, &c3, &c2); assert_int_equals(result, FIGHT_WON); assert_int_equals(c3.nb_pawns, 4); assert_int_equals(c2.nb_pawns, 6); assert_int_equals(p2.nb_pawns, 10); assert_int_equals(p2.nb_cells, 2); assert_int_equals(p1.nb_pawns, 5); assert_int_equals(p1.nb_cells, 1); assert_int_equals(c2.owner->id, p2.id); // move fight lose result = player_move_to_cell(&p1, 4, &c1, &c2); assert_int_equals(result, FIGHT_LOST); assert_int_equals(c1.nb_pawns, 1); assert_int_equals(c2.nb_pawns, 6); assert_int_equals(p1.nb_pawns, 1); assert_int_equals(p1.nb_cells, 1); assert_int_equals(p2.nb_pawns, 10); assert_int_equals(p2.nb_cells, 2); assert_int_equals(c2.owner->id, p2.id); // move fight draw result = player_move_to_cell(&p2, 1, &c2, &c1); assert_int_equals(result, FIGHT_DRAW); assert_int_equals(c2.nb_pawns, 6); assert_int_equals(c1.nb_pawns, 1); assert_int_equals(p1.nb_pawns, 1); assert_int_equals(p1.nb_cells, 1); assert_int_equals(p2.nb_pawns, 10); assert_int_equals(p2.nb_cells, 2); assert_int_equals(c2.owner->id, p2.id); assert_int_equals(c1.owner->id, p1.id); free_cell(&c1); free_cell(&c2); free_cell(&c3); }
com() { int i, kuusho, hukasa; int x, y; char **a; char *bp; CELL *p; joseki(); if(te) return; kuusho = 0; a = aki; for (i = 0; i < 60; ) { bp = ban + yuusen[i++]; if(*bp == BLANK) { *(a++) = bp; kuusho++; } } *a = 0; sekisa = 0; for(y = 1; y < 9; y++) { for(x = 1; x < 9; x++) { switch(ban[y*9+x]) { case BLACK: sekisa++; break; case WHITE: sekisa--; } } } init_cell(); p = get_cell(); p->child = NULL; p->cdr = NULL; if(kuusho <= lvtbl[level-1].kanzen) { p->h = -64; mr2(p, kuusho, 64); } else if(kuusho <= lvtbl[level-1].hishou) { p->h = -1; mr2(p, kuusho, 1); } else { hukasa = lvtbl[level-1].hukasa; if(kuusho <= lvtbl[level-1].kyoka) hukasa += 2; p->h = -10000; mr1(p, hukasa, 10000); } te = p->t; }