Пример #1
0
void* fastRealloc(void* p, size_t n)
{
    Q_ASSERT(!isForbidden());

    void* result = realloc(p, n);
    if (!result)
        CRASH();
    return result;
}
Пример #2
0
void* fastMalloc(size_t n)
{
    Q_ASSERT(!isForbidden());

    void* result = malloc(n);
    if (!result)
        CRASH();
    return result;
}
Пример #3
0
void* fastCalloc(size_t n_elements, size_t element_size)
{
    Q_ASSERT(!isForbidden());

    void* result = calloc(n_elements, element_size);
    if (!result)
        CRASH();
    return result;
}
Пример #4
0
bool State::set(const std::shared_ptr<Piece>& p)
{
    bool success = false;
    if (!isForbidden(p->getPosition(), p->isBlack() ? BLACK : WHITE)) {
        noTestSet(p);
        success = true;
    }
    return success;
}
Пример #5
0
std::shared_ptr<State::Attackable> State::check3(const Test &test, std::size_t start) const
{
    assert(test->line.size() == test->position.size());
    assert(start < test->line.size());
    Block b = test->line[start];
    assert(b == WHITE || b == BLACK);

    std::shared_ptr<State::Attackable> attackable = std::make_shared<Attackable>();
    Rank rank = NONE;
    auto testFunc = [&](size_t space, size_t start) {
        if (!isForbidden(test->position[space], b, test)) {
            Test t = std::make_shared<Tst>();
            t->line = test->line;
            t->position = test->position;
            t->line[space] = b;
            auto result = check4(t, start);
            if (result->rank == S_FOUR || result->rank == FOUR) {
                rank = result->rank == S_FOUR ? S_THREE : THREE;
                attackable->chances.push_back(test->position[space]);
            }
        }
    };

    
    if (start + 2 < test->line.size() &&test->line[start + 1] == b && test->line[start + 2] == b) {
        if (start > 0 && test->line[start - 1] == SPACE) {
            testFunc(start - 1, start - 1);
        }

        if (start+3 < test->line.size() && test->line[start + 3] == SPACE) {
            testFunc(start + 3, start);
        }

    }

    if (start + 3 < test->line.size() && test->line[start + 1] == SPACE && test->line[start + 2] == b && test->line[start + 3] == b) {
        testFunc(start + 1, start);
    }
    if (start + 3 < test->line.size() && test->line[start + 1] == b && test->line[start + 2] == SPACE && test->line[start + 3] == b) {
        testFunc(start + 2, start);
    }
    

    attackable->player = b;
    attackable->rank = rank;

    return attackable;
}
bool
noVehicles(SVCPermissions permissions) {
    return isForbidden(permissions) || isSidewalk(permissions);
}
Пример #7
0
void* tryFastRealloc(void* p, size_t n)
{
    Q_ASSERT(!isForbidden());

    return realloc(p, n);
}
Пример #8
0
void fastFree(void* p)
{
    Q_ASSERT(!isForbidden());

    free(p);
}
Пример #9
0
void* tryFastCalloc(size_t n_elements, size_t element_size)
{
    Q_ASSERT(!isForbidden());

    return calloc(n_elements, element_size);
}
Пример #10
0
void* tryFastMalloc(size_t n)
{
    Q_ASSERT(!isForbidden());

    return malloc(n);
}
Пример #11
0
std::shared_ptr<State::Attackable> State::check4(const Test &test, std::size_t start) const
{
    assert(test->line.size() == test->position.size());
    assert(start < test->line.size());
    Block b = test->line[start];
    assert(b == WHITE || b == BLACK);

    std::shared_ptr<State::Attackable> attackable = std::make_shared<Attackable>();
    auto testFunc = [&](size_t space, size_t start) {
        Test t = std::make_shared<Tst>();
        t->line = test->line;
        t->position = test->position;
        t->line[space] = b;
        if (check5(t, start) && !isForbidden(test->position[space], b, t)) {
            attackable->chances.push_back(test->position[space]);
        }
    };

    if (start + 4 < test->line.size() && test->line[start + 4] == b) {
        size_t count = 0;
        std::vector<size_t> blank;
        for (size_t i = start + 1; i < start + 4; ++i) {
            Block t = test->line[i];
            if (t == b) {
                ++count;
            } else if (t == SPACE) {
                blank.push_back(i);
            } else {
                break;
            }
        }
        if (blank.size() == 1 && count == 2) {
            testFunc(blank[0], start);
        }
    } else {
        size_t count = 0;
        for (size_t i = start; i < start + 4; ++i) {
            if (test->line[i] == b) {
                ++count;
            }
            else {
                break;
            }
        }
        if (count == 4) {
            if (start > 0 && test->line[start - 1] == SPACE) {
                testFunc(start - 1, start - 1);
            }
            if (start + 4 < test->line.size() && test->line[start + 4] == SPACE) {
                testFunc(start + 4, start);
            }
        }
    }
    

    attackable->player = b;
    switch (attackable->chances.size()) {
    case 0:
        attackable->rank = NONE;
        break;
    case 1:
        attackable->rank = FOUR;
        break;
    case 2:
        attackable->rank = S_FOUR;
        break;
    default:
        assert(false);
    }


    return attackable;
}