Beispiel #1
0
 mapped_type& operator[](const key_type& key) {
     TMapIterator iter = m_Map.lower_bound(SNode(key));
     if ( iter == m_Map.end() || m_Map.key_comp()(key, iter->first) ) {
         // insert
         iter = m_Map.insert(iter, SNode(key, mapped_type()));
         x_MarkAdded(iter);
     }
     else {
         x_MarkUsed(iter);
     }
     // the underlying type is set<> so the value_type is unnecessary const
     return x_GetNode(iter).second;
 }
SNode AStarStrategyOnYAGSBPL::searchPath(SNode& start, SNode& finish) {
    GenericSearchGraphDescriptor<SNode, double> graph;

    graph.getHashBin_fp = &getHashBin;
    //graph.getHeuristics_fp = &getHeuristics;
    graph.getSuccessors_fp = &getSuccessors;
    graph.isAccessible_fp = &isAccessible;

    graph.hashTableSize = (int)std::max(aStarStaticMap->sizeOnXaxis(), aStarStaticMap->sizeOnYaxis()) + 1;

    graph.SeedNode = start;
    graph.TargetNode = finish;

    A_star_planner<SNode, double> planner;
    planner.init(graph);
    planner.plan();

    std::vector< std::vector< SNode > > paths = planner.getPlannedPaths();
    /*
    printf("Number of paths: %lu\nPath coordinates: \n[ ", paths.size());
    if (paths.size() > 0) {
        for (int a=0; a<paths[0].size(); a++) {
            printf("[%d, %d]{%d}; ", paths[0][a].position.first+1, paths[0][a].position.second+1, paths[0][a].direction);
        }
        printf(" ]\n\n");
    }
    */
    if (paths.size() > 0) {
        int pathSize = (int)paths[0].size();
        return paths[0][pathSize-2];
    } else {
        std::cout << "!!!NO PATH FOUND!!!" << std::endl;
        return SNode(-1,-1,0,0);
    }
}
void VSearcher::Set( unicode_t* uStr, bool sens, charset_struct* charset ) //throw
{
	sBigList.clear();
	sList.clear();
	bytes.clear();
	_cs = charset;
	mode = 0;

	int maxSymLen = 0;
	bool one = true;
	int i;

	for ( ; *uStr; uStr++ )
	{
		SBigNode node;

		if ( !node.Set( *uStr, sens, charset ) )
		{
			unicode_t x[2] = { *uStr, 0};
			throw_msg( "symbol '%s' not exist in charset '%s'", unicode_to_utf8( x ).data(), charset->name );
		}

		int n = node.MaxLen();

		if ( maxSymLen < n ) { maxSymLen = n; }

		if ( node.b[0] ) { one = false; }

		sBigList.append( node );
	}

	sBigList.append( SBigNode() );

	mode = 1;

	if ( one )
	{
		for ( i = 0; i < sBigList.count(); i++ )
		{
			for ( char* s = sBigList[i].a; *s; s++ )
			{
				bytes.append( *s );
			}
		}

		mode = 3;
	}
	else if ( maxSymLen == 1 )
	{
		for ( i = 0; i < sBigList.count(); i++ )
		{
			sList.append( SNode( sBigList[i].a[0], sBigList[i].b[0] ) );
		}

		mode = 2;
	}
}
Beispiel #4
0
 pair<iterator, bool> insert(const value_type& value) {
     pair<TMapIterator, bool> ins = m_Map.insert(SNode(value));
     if ( ins.second ) {
         x_MarkAdded(ins.first);
     }
     else {
         x_MarkUsed(ins.first);
     }
     return pair<iterator, bool>(iterator(ins.first), ins.second);
 }
Beispiel #5
0
/*
 @brief 通过当前棋局中已有的模式计算得分。模式为一个无符号整数,其中只有六个位有效,
        最高位代表死(1)活(0)。为1则代表有棋子,0则为无棋子。
        评分规则如下(镜像同样):
            0 11111(31)       => 100    成5
            1 11111(63)       => 100    成5
            0 11110(30)       => 90     活4
            1 11110(62) *2    => 90     双死4
            1 11110 0 11100   => 90     死4活3
            0 11100(28) *2    => 80     双活3
            1 11100 0 11100   => 70     死3活3
            1 11110(62)       => 60     死4
            0 11100(28)       => 50     活3
            0 11000(24) *2    => 40     双活2
            1 11100(60)       => 30     死3
            0 11000(24)       => 20     活2
            1 11000(56)       => 10     死2
 
 @param pat 当前棋局中已有的模式,下标为模式编号,值为此编号的模式的数量
 @return 总得分,无匹配得分模式返回0分
*/
int CalScore(PatType pat[])
{
    struct SNode {
        int score;
        int req[2][2];
        SNode():score(0){req[0][0]=req[1][0]=-1;}
        SNode(int sc, int pat1, int cnt1, int pat2=-1, int cnt2=-1){
            score = sc;
            req[0][0] = pat1;
            req[0][1] = cnt1;
            req[1][0] = pat2;
            req[1][1] = cnt2;
        }
    };
    
    SNode scale[] = {   // 分值表
        SNode(INFINIT, 63, 1),
        SNode(INFINIT, 31, 1),
        SNode(90, 30, 1),
        SNode(90, 62, 2),
        SNode(90, 62, 1, 28, 1),
        SNode(80, 28, 2),
        SNode(70, 60, 1, 28, 1),
        SNode(60, 62, 1),
        SNode(50, 28, 1),
        SNode(40, 24, 2),
        SNode(30, 60, 1),
        SNode(20, 24, 1),
        SNode(10, 56, 1)
    };
    
    bool flag = true;
    for (int i=0; i<(sizeof(scale)/sizeof(scale[0])); ++i) {
        // 从分值最高的模式开始检测 一旦满足直接返回最高分
        SNode cur = scale[i];
        
        flag = true;
        for (int j=0; j<2; ++j) {
            if (cur.req[j][0] == -1)
                continue;
            
            if (pat[cur.req[j][0]]+pat[ReversePattern(cur.req[j][0])] < cur.req[j][1])
                flag = false;
        }
        if (flag)
            return cur.score;
    }
    
    return 0;
}