示例#1
0
bool RuleBase::can_reverse_direction(	const Object::Enemy& self,
										int friends_size,
										const Object::Enemy* friends,
										int self_index) const
{
	for (int i = 0; i < friends_size; ++i)
	{
		if (i == self_index)
		{
			continue;
		}

		if (friends[i].point() == self.point())
		{
			return false;
		}
	}

	GameLib::Framework f = GameLib::Framework::instance();

	return f.getRandom(MaxRate) < reverse_rate_at_moving_;
}
示例#2
0
Point RuleBase::select_direction(	const Object::Enemy& self,
									const Map& map,
									int friends_size,
									const Object::Enemy* friends,
									int self_index)
{
	int rates[4];
	Point next_candidates[4];

	// do not change the original
	for (int i = 0; i < 4; ++i)
	{
		rates[i] = direction_rates_[i];
	}

	for (int i = 0; i < 4; ++i)
	{
		next_candidates[i] = self.point() + Directions[i];

		if (map.can_not_invade(next_candidates[i]))
		{
			rates[i] = 0;
		}
	}

	for (int i = 0; i < friends_size; ++i)
	{
		if (i == self_index)
		{
			continue;
		}

		if (friends[i].point() == next_candidates[i])
		{
			rates[i] = 0;
		}
		else if (friends[i].current_point() == next_candidates[i])
		{
			rates[i] = 0;
		}
	}
	
	normalize_rate(rates);

	if ((rates[0] + rates[1] + rates[2] + rates[3]) == 0)
	{
		return Point(0, 0);
	}

	GameLib::Framework f = GameLib::Framework::instance();

	int rate = f.getRandom(MaxRate);
	int index = 0;
	int sum = 0;

	for (int i = 0; i < 4; ++i)
	{
		sum = sum + rates[i];

		if (sum > rate)
		{
			index = i;
			break;
		}
	}

	return Directions[index];
}
示例#3
0
AppStatus::ITEM AppStatus::randomItem(){
	GameLib::Framework f = GameLib::Framework::instance();
	return static_cast<ITEM>(f.getRandom(4));
}