Knight's tour: Difference between revisions

Content added Content deleted
Line 8,551: Line 8,551:


dnl Extract the nth position from the path.
dnl Extract the nth position from the path.
define(`path_nth',
define(`path_nth',`substr($1,eval(( $2 ) * 2),2)')
`ifelse($2,0,`path_car($1)',`path_nth(path_cdr($1),eval(( $2 ) - 1))')')


define(`random_position',`path_nth($1,randnum(path_length($1)))')
define(`random_move',`path_nth($1,randnum(path_length($1)))')


dnl Is the position $1 contained in the path $2?
dnl Is the position $1 contained in the path $2?
Line 8,612: Line 8,611:
`pushdef(`moves',next_moves($2))`'dnl
`pushdef(`moves',next_moves($2))`'dnl
ifelse(moves,`',`find_tour($1)',
ifelse(moves,`',`find_tour($1)',
`find_tour($1,$2`'random_position(next_moves($2)))')`'dnl
`find_tour($1,$2`'random_move(next_moves($2)))')`'dnl
popdef(`moves')')')
popdef(`moves')')')