当前位置: 首页>>代码示例>>C++>>正文


C++ Square::HasSolutionRebus方法代码示例

本文整理汇总了C++中Square::HasSolutionRebus方法的典型用法代码示例。如果您正苦于以下问题:C++ Square::HasSolutionRebus方法的具体用法?C++ Square::HasSolutionRebus怎么用?C++ Square::HasSolutionRebus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Square的用法示例。


在下文中一共展示了Square::HasSolutionRebus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: assert

bool
Scrambler::ScrambleSolution(unsigned short key_int)
{
    bool ok = m_grid.GetWidth() > 0 && m_grid.GetHeight() > 0;
    ok = ok && (m_grid.m_flag & FLAG_NO_SOLUTION) == 0;

    assert(m_grid.First() != NULL);

    if (! ok)
        return false;

    if (key_int == 0)
        key_int = MakeKey();

    assert(1000 <= key_int && key_int <= 9999);

    // Read the key into an array of single digits
    unsigned char key[4];
    key[0] = int(key_int / 1000) % 10;
    key[1] = int(key_int / 100)  % 10;
    key[2] = int(key_int / 10)   % 10;
    key[3] = int(key_int / 1)    % 10;

    std::string solution = GetSolutionDown();

    unsigned short cksum = Checksummer::cksum_region(solution, 0);
    if (cksum == 0)
        return false;

    size_t length = solution.length();

    // Don't scramble really small puzzles
    if(length < 12)
        return 0;

    // Do the scrambling
    for (int i = 0; i < 4; ++i)
    {
        std::string scramble_part;
        for (size_t j = 0; j < length; ++j)
        {
            char letter = solution[j] + key[j % 4];

            // Make sure the letter is capital
            if (letter > 90)
                letter -= 26;

            // Range for capital letters
            assert(isupper(letter));

            scramble_part.push_back(letter);
        }
        assert(scramble_part.length() == length);

        scramble_part = ShiftString(scramble_part, key[i]);
        assert(scramble_part.length() == length);

        scramble_part = ScrambleString(scramble_part);
        assert(scramble_part.length() == length);

        solution = scramble_part;
    }


    // Save the scrambled solution to the puzzle file
    std::string::iterator it = solution.begin();
    for (Square * square = m_grid.First();
         square != NULL;
         square = square->Next(DOWN))
    {
        if (square->IsBlack())
            continue;

        // Make sure we preserve any rebus in the solution
        if (! square->HasSolutionRebus())
            square->SetSolution(decode_puz(std::string(1, *it)));
        else
            square->SetPlainSolution(*it);
        ++it;
    }
    assert(it == solution.end());

    m_grid.m_flag |= FLAG_SCRAMBLED;
    m_grid.m_cksum = cksum;
    m_grid.m_key = key_int;

    return true;
}
开发者ID:mattprintz,项目名称:wx-xword,代码行数:88,代码来源:Scrambler.cpp


注:本文中的Square::HasSolutionRebus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。