static
bool setTriggerLiterals(RoleInfo<role_id> &roleInfo,
        const map<u32, vector<vector<CharReach>>> &triggers) {
    u32 minLiteralLen = ~0U;
    for (const auto &tr : triggers) {
        for (const auto &lit : tr.second) {
            if (lit.empty()) {
                return false;
            }
            minLiteralLen = min(minLiteralLen, (u32)lit.size());
            roleInfo.last_cr |= lit.back();
            for (const auto &c : lit) {
                roleInfo.prefix_cr |= c;
            }
            roleInfo.literals.push_back(lit);
        }
    }

    if (roleInfo.role.graph()) {
        const NGHolder &g = *roleInfo.role.graph();
        roleInfo.cr = getReachability(g);
    } else if (roleInfo.role.castle()) {
        roleInfo.cr = roleInfo.role.castle()->reach();
    }

    // test the score of this engine
    roleInfo.score = 256 - roleInfo.cr.count() + minLiteralLen;
    if (roleInfo.score < 20) {
        return false;
    }

    return true;
}
Esempio n. 2
0
std::pair< std::vector<BattleHex>, int > BattleInfo::getPath(BattleHex start, BattleHex dest, const CStack *stack)
{
	auto reachability = getReachability(stack);

	if(reachability.predecessors[dest] == -1) //cannot reach destination
	{
		return std::make_pair(std::vector<BattleHex>(), 0);
	}

	//making the Path
	std::vector<BattleHex> path;
	BattleHex curElem = dest;
	while(curElem != start)
	{
		path.push_back(curElem);
		curElem = reachability.predecessors[curElem];
	}

	return std::make_pair(path, reachability.distances[dest]);
}