Commit ecd7382d authored by Antoine Cellerier's avatar Antoine Cellerier

Really prevent illegal puzzles and prevent some illegal moves.

parent cf3059ba
......@@ -120,14 +120,23 @@ static vlc_bool_t finished( vout_sys_t *p_sys )
}
static vlc_bool_t is_valid( vout_sys_t *p_sys )
{
int i, s=0;
int i, j, d=0;
if( p_sys->b_blackslot == VLC_FALSE ) return VLC_TRUE;
for( i = 0; i < p_sys->i_cols * p_sys->i_rows; i++ )
{
if( (p_sys->i_cols*p_sys->i_rows+i-p_sys->pi_order[i])%2 ) s++;
else s--;
if( p_sys->pi_order[i] == p_sys->i_cols * p_sys->i_rows - 1 )
{
d += i / p_sys->i_cols + 1;
continue;
}
for( j = i+1; j < p_sys->i_cols * p_sys->i_rows; j++ )
{
if( p_sys->pi_order[j] == p_sys->i_cols * p_sys->i_rows - 1 )
continue;
if( p_sys->pi_order[i] > p_sys->pi_order[j] ) d++;
}
}
if( s!=0 ) return VLC_FALSE;
if( d%2!=0 ) return VLC_FALSE;
else return VLC_TRUE;
}
static void shuffle( vout_sys_t *p_sys )
......@@ -153,14 +162,14 @@ static void shuffle( vout_sys_t *p_sys )
}
p_sys->b_finished = finished( p_sys );
} while( p_sys->b_finished == VLC_TRUE
&& is_valid( p_sys ) == VLC_FALSE );
|| is_valid( p_sys ) == VLC_FALSE );
if( p_sys->b_blackslot == VLC_TRUE )
{
for( i = 0; i < p_sys->i_cols * p_sys->i_rows; i++ )
{
if( p_sys->pi_order[i] ==
( p_sys->i_cols - 1 ) * p_sys->i_rows )
p_sys->i_cols * p_sys->i_rows - 1 )
{
p_sys->i_selected = i;
break;
......@@ -171,7 +180,6 @@ static void shuffle( vout_sys_t *p_sys )
{
p_sys->i_selected = -1;
}
printf( "selected: %d\n", p_sys->i_selected );
}
/*****************************************************************************
......@@ -463,8 +471,10 @@ static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
{
p_vout->p_sys->i_selected = -1;
}
else if( p_vout->p_sys->i_selected == i_pos + 1
|| p_vout->p_sys->i_selected == i_pos - 1
else if( ( p_vout->p_sys->i_selected == i_pos + 1
&& p_vout->p_sys->i_selected%p_vout->p_sys->i_cols != 0 )
|| ( p_vout->p_sys->i_selected == i_pos - 1
&& i_pos % p_vout->p_sys->i_cols != 0 )
|| p_vout->p_sys->i_selected == i_pos + p_vout->p_sys->i_cols
|| p_vout->p_sys->i_selected == i_pos - p_vout->p_sys->i_cols )
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment