Knight's tour: Difference between revisions

Content added Content deleted
Line 8,335: Line 8,335:
n_tour := 0
n_tour := 0
if n_tour < max_tours then
if n_tour < max_tours then
every tour_board := tours.generate(i, j, closed_only) do {
every tour_board := tours.generate(i, j, closed_only) do
{
n_tour +:= 1
n_tour +:= 1
write("Tour number ", n_tour)
write("Tour number ", n_tour)
Line 8,529: Line 8,530:
local moves, mv
local moves, mv


if n_squares - n_position = 1 then {
if n_squares - n_position = 1 then
{
# Is the last move possible? If so, make it and output the
# Is the last move possible? If so, make it and output the
# board. (Only zero or one of the moves can be non-null.)
# board. (Only zero or one of the moves can be non-null.)
Line 8,535: Line 8,537:
every try_last_move(consumer, moves[1 to 8],
every try_last_move(consumer, moves[1 to 8],
closed_only, i_start, j_start)
closed_only, i_start, j_start)
} else {
}
else
{
moves := next_moves(i, j, n_position)
moves := next_moves(i, j, n_position)
every mv := !moves do
every mv := !moves do
Line 8,585: Line 8,589:


w := 0
w := 0
if \move then {
if \move then
{
board.try(move.i, move.j, n_position + 1)
board.try(move.i, move.j, n_position + 1)
following_moves := possible_moves(move.i, move.j)
following_moves := possible_moves(move.i, move.j)
Line 8,647: Line 8,652:
(i_diff = 1 & j_diff = 2)) & &yes) | fail
(i_diff = 1 & j_diff = 2)) & &yes) | fail
end</lang>
end</lang>

{{out}}
{{out}}
$ ./knights_tour c5 2 closed
$ ./knights_tour c5 2 closed