Esempio n. 1
0
/*	function :	rollBack ()
		UNDO all actions that occured after the last leap of faith.
		in other words : rollback until you reach a leap of faith action.
		if this action reaches a (BOARD_INITIALIZED) action before reaching
		a (LEAP_OF_FAITH) action, it considers that the initial  state of
		the board is an invalid state and impossible to solve.
		in the later case, this function sets the state flag (_BAD_INITIALIZATION).
		return type :
			-	if rolled back successfully	: true.
			-	otherwise					: false.
*/
bool actionCourse::rollBack()
{

	do
	{
		if( lastAction() . act == actionRecord::BOARD_INITIALIZED)
		{
			// if reached the BOARD_INITIALIZED action ...
			// set the state flag _BAD_INITIALIZATION
			dynamic_cast<sudokuBoard*>(this)->state |= sudokuState::_BAD_INITIALIZATION;
			return false;
		}
		else
			Undo();
	}
	// keep rolling back until you reach a LEAP_OF_FAITH action.
	while( Tracker.top() != actionRecord::LEAP_OF_FAITH );

	// signal the current value as faulty and shouldn't be used for future leaps.
		Tracker.top().faultyValues.push_back(*(lastAction().subject));

		if( Tracker.top().faultyValues.size() < (unsigned)Tracker.top().subject->countPossibilities() )
		//correct the value taken by the leap
			return Correct_LeapOfFaith();

		else if(Tracker.top().subject->countPossibilities() == Tracker.top().faultyValues.size() )
			return rollBack();	//if all the possibilities are tried, then a previuos leap is the mistake, roll back another time.

		else
			return false;	// report failure.
}
void testlastAction()	{

    GameProperties newGame = getGame(NULL);
    delayGame(ACTIONCOOLDOWN);
    sput_fail_unless(lastAction(newGame) == 1,"Checking delay more than Cooldown returns true");
    delayGame(ACTIONCOOLDOWN-1);
    sput_fail_unless(lastAction(newGame) == 0,"Checking delay less than Cooldown returns false");

}
Esempio n. 3
0
void testlastAction()	{

	GameProperties newGame = createGame();
	delayGame(ACTIONCOOLDOWN);
	sput_fail_unless(lastAction(newGame) == 1,"Checking delay more than Cooldown returns true");
	delayGame(ACTIONCOOLDOWN-1);
	sput_fail_unless(lastAction(newGame) == 0,"Checking delay less than Cooldown returns false");
	free(newGame->clock);
	free(newGame);

}
Esempio n. 4
0
void QompQtMultimediaPlayer::tuneUrlReady(const QUrl &url)
{
#ifdef DEBUG_OUTPUT
	qDebug() << "QompQtMultimediaPlayer::tuneUrlReady()  " << lastAction() << url;
#endif

	player_->setMedia(QMediaContent(url));

	switch (lastAction()) {
	case Qomp::StatePlaying: player_->play();
		break;
	case Qomp::StatePaused: player_->pause();
		break;
	default: player_->stop();
		break;
	}	
}
Esempio n. 5
0
/*	function : Correct_LeapOfFaith ()
		pre-condition	: the top of the action tracker is a wrong leap of faith action.
		this function corrects the error made at the last leap of faith, by choosing
		a value that is valid and not specified in the faultyValues vector.
		if this function fails, it sets the error stat _BAD_OPERATION and registers
		a BAD_OPERATION actionRecord on top of the action course.
		
		return value :
			-	if succeeded and changed the value	.	.	.	.	: true
			-	if the value wasn't changed due to any circumstance	: false
*/
bool		sudokuBoard::Correct_LeapOfFaith()
{
	actionRecord last = lastAction();
	// check for a faulty LEAP_OF_FAITH action
	if( last != actionRecord::LEAP_OF_FAITH )
	{
		pushAction( actionRecord ( actionRecord::BAD_OPERATION , Cell() , false) );
		return false;
	}
	// check if the current leap is actually faulty,
	// by checking if it has any faulty values.
	if( last.faultyValues.size() == 0 )
	{
		pushAction( actionRecord ( actionRecord::BAD_OPERATION , Cell() , false) );
		return false;
	}


	// cycle through the possibilities
	for( Index i = 0 ; i<10 ; i++ )
	{
		// if the number contained in (i) is a valid in the subject cell:
		if( last.subject->possible[i] )
		{
			// validate the cell to avoid any possible errors in expectations :
			expectFor( *last.subject );

			// check if that number exists in the faulty values:
			bool IsFaulty = false;
			for( Index j = 0 ; j < last.faultyValues.size() ; j++)
			{
				if( i == static_cast<int>(last.faultyValues[j]) )
				{
					IsFaulty = true;
					break;
				}
			}

			// if the value is a faulty one, then look for another :
			if (IsFaulty)
				continue;
			
			// else, make this value the new choice of this leap :
			else
			{
				// set the new value :
				last.subject->v = i;

				// re-validate the cell :
				expectFor( *last.subject );

				// report success :
				return true;
			}
		}
	}

	// if execution reaches this point, then a value hasn't been changed.
	// report failure.
	return false;
}