Exemplo n.º 1
0
/* Clear moves, leaving fixed squares
 */
static
void
clear_moves( void )
{
    for( idx_history = 0 ; history[ idx_history ] & FIXED ; ++idx_history )
        ;
    reapply( );
}
Exemplo n.º 2
0
void VersionFinal::reload(const bool onlyVanilla, const QStringList &external)
{
	//FIXME: source of epic failure.
	beginResetModel();
	OneSixVersionBuilder::build(this, m_instance, onlyVanilla, external);
	reapply(true);
	endResetModel();
}
Exemplo n.º 3
0
bool VersionFinal::remove(const int index)
{
	if (canRemove(index) && QFile::remove(versionFiles.at(index)->filename))
	{
		beginResetModel();
		versionFiles.removeAt(index);
		reapply(true);
		endResetModel();
		return true;
	}
	return false;
}
Exemplo n.º 4
0
void VersionFinal::move(const int index, const MoveDirection direction)
{
	int theirIndex;
	if (direction == MoveUp)
	{
		theirIndex = index - 1;
	}
	else
	{
		theirIndex = index + 1;
	}
	if (theirIndex < 0 || theirIndex >= versionFiles.size())
	{
		return;
	}
	const QString ourId = versionFileId(index);
	const QString theirId = versionFileId(theirIndex);
	if (ourId.isNull() || ourId.startsWith("org.multimc.") ||
			theirId.isNull() || theirId.startsWith("org.multimc."))
	{
		return;
	}

	VersionFilePtr we = versionFiles[index];
	VersionFilePtr them = versionFiles[theirIndex];
	if (!we || !them)
	{
		return;
	}
	beginMoveRows(QModelIndex(), index, index, QModelIndex(), theirIndex);
	versionFiles.replace(theirIndex, we);
	versionFiles.replace(index, them);
	endMoveRows();

	auto order = getExistingOrder();
	order[ourId] = theirIndex;
	order[theirId] = index;

	if (!OneSixVersionBuilder::writeOverrideOrders(order, m_instance))
	{
		throw MMCError(tr("Couldn't save the new order"));
	}
	else
	{
		reapply();
	}
}
Exemplo n.º 5
0
/* Backtrack to a previous choice point, and attempt to reseed
 * the search. Return -1 if no further choice possible, or
 * the index of the changed square.
 *
 * Assumes that the move history and board are valid.
 */
static
int
backtrack( void )
{
    int digit, idx;

    rb->yield();

    for( ; 0 <= --idx_history ; )
        if( history[ idx_history ] & CHOICE )
        {
            /* Remember the last choice, and advance */
            idx = GET_INDEX( history[ idx_history ] );
            digit = GET_DIGIT( history[ idx_history ] ) + 1;
            reapply( );
            if( -1 != choose( idx, digit ) )
                return idx;
        }

    return -1;
}
Exemplo n.º 6
0
/* Return number of hints. The hints mechanism should attempt to find
 * 'easy' moves first, and if none are possible, then try for more
 * cryptic moves.
 */
int
findhints( void )
{
    int i, n, mutated = 0;

    rb->yield();

    n = findmoves( );
    if( n < 2 )
    {
        /* Each call to pairs() can mutate the board state, making the
         * hints very, very cryptic... so later undo the mutations.
         */
        for( i = 0 ; i < 9 ; ++i )
        {
            count_set_digits( i, idx_row );
            pairs( i, idx_row );

            count_set_digits( i, idx_column );
            pairs( i, idx_column );

            count_set_digits( i, idx_block );
            pairs( i, idx_block );
        }
        mutated = 1;
        n = findmoves( );
    }
    if( n < 2 )
    {
        for( i = 0 ; i < 9 ; ++i )
        {
            block( i );
            common( i );
        }
        mutated = 1;
        n = findmoves( );
    }

    /* Sort the possible moves, and allow just one hint per square */
    if( 0 < n )
    {
        int i, j;

        rb->qsort( possible, n, sizeof( int ), cmpindex );
        for( i = 0, j = 1 ; j < n ; ++j )
        {
            if( GET_INDEX( possible[ i ] ) == GET_INDEX( possible[ j ] ) )
            {
                /* Let the user make mistakes - do not assume the
                 * board is in a consistent state.
                 */
                if( GET_DIGIT( possible[i] ) == GET_DIGIT( possible[j] ) )
                    possible[ i ] |= possible[ j ];
            }
            else
                i = j;
        }
        n = i + 1;
    }

    /* Undo any mutations of the board state */
    if( mutated )
        reapply( );

    return n;
}
Exemplo n.º 7
0
void VersionFinal::resetOrder()
{
	QDir(m_instance->instanceRoot()).remove("order.json");
	reapply();
}