예제 #1
0
bool simulated_move(int side, const map_location& from, const map_location& to, int steps, map_location& unit_location)
{
	LOG_AI_SIM_ACTIONS << "Simulated move" << std::endl;

	unit_map::unit_iterator move_unit;
	bool success = false;

	// In simulation, AI should not know if there is a enemy's ambusher.
	std::tie(move_unit, success) = resources::gameboard->units().move(from, to);

	if(!success) {
		// This happened because in some CAs like get_village_phase and move_leader_to_keep phase,
		// if the destination is already occupied will not be checked before execute. Just silent
		// errors in ai/actions and tell rca the game state isn't changed.
		unit_location = to;
		return false;
	}

	move_unit->set_movement(move_unit->movement_left()-steps);	// Following original logic, remove_movement_ will be considered outside.

	unit_location = move_unit->get_location();	// For check_after.

	LOG_AI_SIM_ACTIONS << move_unit->type_name() << " move from " << from << " to " << to << std::endl;

	if(resources::gameboard->map().is_village(to)){
		helper_check_village(to, side);
	}

	return true;
}
예제 #2
0
void helper_place_unit(const unit& u, const map_location& loc){
	unit new_unit = u;
	new_unit.set_movement(0, true);
	new_unit.set_attacks(0);
	new_unit.heal_all();

	std::pair<unit_map::iterator, bool> add_result = resources::units->add(loc, new_unit);
	assert(add_result.second);
	unit_map::iterator& new_unit_itor = add_result.first;

	if(resources::gameboard->map().is_village(loc)){
		helper_check_village(loc, new_unit_itor->side());
	}
}
예제 #3
0
void helper_place_unit(const unit& u, const map_location& loc){
	unit_ptr new_unit = u.clone();
	new_unit->set_movement(0, true);
	new_unit->set_attacks(0);
	new_unit->heal_fully();
	new_unit->set_location(loc);

	unit_map::unit_iterator new_unit_itor;
	bool success = false;

	std::tie(new_unit_itor, success) = resources::gameboard->units().insert(new_unit);
	assert(success);

	if(resources::gameboard->map().is_village(loc)){
		helper_check_village(loc, new_unit_itor->side());
	}
}