Example #1
0
int main(int argc, char* argv[]) {
  if(argc != 2) {
    std::cout << "Usage : " << argv[0] << " <movie | pic>" << std::endl;
    return 0;
  }

  bool movie = std::string(argv[1])=="movie";

  // random seed initialization
  std::srand(std::time(0));

  // Let us create a dictionary...
  auto dict = gaml::span::dictionary<Point>(NU,gaussian_kernel);

  // ... and adjust it so that it spans the distribution.
  for(unsigned int nb = 0; nb < NB_SAMPLES; ++nb) dict.submit(get_sample());
  std::cout << dict.container().size() << " samples added."<< std::endl;

  Graph          som;
  Similarity     distance;
  UnitSimilarity unit_distance(distance);
  Learn          learning_rule;
  UnitLearn      unit_learning_rule(learning_rule);
  WinnerTakeMost competition;
  
  std::cout << "Processing SOM..." << std::endl;

  auto line = vq2::algo::make::line(som,K,
				    [&dict](unsigned int w) -> Feature {return dict(Point(0,0));},
				    [](unsigned int w, unsigned int ww) -> char {return ' ';});
  unsigned int k = 0;
  for(auto& ref_vertex : line) (*ref_vertex).stuff.label = k++;
  
  competition.coef = WIDE_COEF;
  for(unsigned int nb = 0; nb < NB_EPOCHS; ++nb) {
    if(nb == START_NARROW_EPOCH) competition.coef = NARROW_COEF;
    for(unsigned int e = 0; e < EPOCH_SIZE; ++e) 
      vq2::algo::som::step(som,unit_distance,competition,
			   unit_learning_rule,
			   LEARNING_RATE,
			   dict(get_sample()));
    if(movie) {
      std::ostringstream filename;
      filename << "som-" << std::setw(6) << std::setfill('0') << nb << ".ppm";
      plot(som,unit_distance,dict,filename.str());
    }
  }
   
  if(!movie)
    plot(som,unit_distance,dict,"som.ppm");
  
  return 0;
}
Example #2
0
/*==========================================
 * 取引要請を相手に送る
 *------------------------------------------
 */
void trade_traderequest(struct map_session_data *sd,int target_id)
{
	// clif_tradestart flag: 0: You are too far away from the person to trade., 1: This Character is not currently online or does not exist, 2: The person is in another trade., 3: (trade ok->open the trade window)., 4: The deal has been rejected.
	struct map_session_data *target_sd;

	nullpo_retv(sd);

	if(sd->npc_id)
		npc_event_dequeue(sd);

	target_sd = map_id2sd(target_id);
	if(target_sd && target_sd->bl.prev && sd != target_sd) { // check same player to avoid hack
		if(target_sd->state.storage_flag) {
			clif_tradestart(sd, 5);
			return;
		}
		if(target_sd->state.store || target_sd->state.mail_appending) {
			clif_tradestart(sd, 4);
			return;
		}
		if(!battle_config.invite_request_check) {
			if(target_sd->guild_invite > 0 || target_sd->party_invite > 0 || target_sd->adopt_invite) {
				clif_tradestart(sd,2);	// 相手はPT要請中かGuild要請中か養子要請中
				return;
			}
		}
		if(target_sd->trade.partner != 0) {
			clif_tradestart(sd, 2);
		} else if(sd->bl.m != target_sd->bl.m || unit_distance(&sd->bl, &target_sd->bl) > 2) {
			clif_tradestart(sd, 0);
		} else if(battle_config.gvg_trade_request_refused && map[sd->bl.m].flag.gvg &&
		          target_sd->status.guild_id > 0 && sd->status.guild_id != target_sd->status.guild_id) {
				// if on a gvg map and not in same guild (that can block other player when WoE)
				clif_tradestart(sd, 4);
		} else if(battle_config.pvp_trade_request_refused && map[sd->bl.m].flag.pvp) {
			// Same on PVP map
			clif_tradestart(sd, 4);
		} else {
			target_sd->trade.partner = sd->status.account_id;
			sd->trade.partner = target_sd->status.account_id;
			clif_traderequest(target_sd,sd->status.name);
		}
	} else {
		clif_tradestart(sd, 1);
	}

	return;
}
Example #3
0
/*==========================================
 * 取引要請
 *------------------------------------------
 */
void trade_tradeack(struct map_session_data *sd, unsigned char type)
{
	struct map_session_data *target_sd;

	nullpo_retv(sd);

	// possible types: 3: trade ok., 4: trade canceled.
	if (type != 3 && type != 4)
		return;

	if(sd->npc_id != 0)
		npc_event_dequeue(sd);

	target_sd = map_id2sd(sd->trade.partner);
	if(target_sd && target_sd->bl.prev) {
		if(sd->bl.m != target_sd->bl.m || unit_distance(&sd->bl, &target_sd->bl) > 2) {
			trade_tradecancel(sd);
			return;
		}
		if(sd->state.storage_flag || target_sd->state.storage_flag) {
			trade_tradecancel(target_sd);
			trade_tradecancel(sd);
			return;
		}
		clif_tradestart(target_sd,type);
		clif_tradestart(sd,type);
		if(type == 4) {	// Cancel
			sd->state.deal_locked = 0;
			sd->state.deal_mode   = 0;
			sd->trade.partner     = 0;
			target_sd->state.deal_locked = 0;
			target_sd->state.deal_mode   = 0;
			target_sd->trade.partner     = 0;
		} else {
			sd->state.deal_mode        = 1;
			target_sd->state.deal_mode = 1;
		}
	}

	return;
}
Example #4
0
/*==========================================
 * アイテム追加完了(ok押し)
 *------------------------------------------
 */
void trade_tradeok(struct map_session_data *sd)
{
	struct map_session_data *target_sd;

	nullpo_retv(sd);

	target_sd = map_id2sd(sd->trade.partner);
	if(target_sd && target_sd->bl.prev) {
		if (sd->bl.m != target_sd->bl.m || unit_distance(&sd->bl, &target_sd->bl) > 2) {
			trade_tradecancel(sd);
			return;
		}
		sd->state.deal_locked = 1;
		clif_tradeitemok(sd,0,0);
		clif_tradedeal_lock(sd,0);
		clif_tradedeal_lock(target_sd,1);
	} else {
		trade_tradecancel(sd);
	}

	return;
}