Example #1
0
bool GameFieldExpression::Move(int color, int row, int col)
{
    using namespace std;

    if (matrix(row, col) != CHIP_NONE)
        return false;

    int chipsFlipped = 0;

    for (int dir = 0; dir < directions; ++dir) {
        int i = row, j = col;
        SReference toFlip = *PTheEmptyList;

        while (true) {
            i += shift[dir][0];
            j += shift[dir][1];

            if (matrix.CheckBounds(i,j) && matrix(i,j) == OpponentColor(color))
                toFlip = Point(i,j) ^ toFlip;
            else
                break;
        }

        if (matrix.CheckBounds(i,j) && matrix(i,j) == color) {
            for (SReference p = toFlip; !p.IsEmptyList(); p = p.Cdr()) {
                Point point = p.Car();
                matrix(point->Row(), point->Col()) = color;
                ++chipsFlipped;
            }
        }
    }

    if (chipsFlipped > 0) {
        matrix(row, col) = color;
        return true;
    } else {
        return false;
    }
}
Example #2
0
// point_col(+Point,-Col)
static bool predicatePointCol(const PlgAtom &functor, const SReference &args, PlgExpressionContinuation &cont)
{
    Point point = args.Car();
    PlgReference result = args.Cdr().Car();
    return result.Unify(SReference(point->Col()), cont.Context());
}