Knight's tour: Difference between revisions
Content added Content deleted
Line 8,335:
n_tour := 0
if n_tour < max_tours then
every tour_board := tours.generate(i, j, closed_only) do
{
n_tour +:= 1
write("Tour number ", n_tour)
Line 8,529 ⟶ 8,530:
local moves, mv
if n_squares - n_position = 1 then
{
# Is the last move possible? If so, make it and output the
# board. (Only zero or one of the moves can be non-null.)
Line 8,535 ⟶ 8,537:
every try_last_move(consumer, moves[1 to 8],
closed_only, i_start, j_start)
}
else
{
moves := next_moves(i, j, n_position)
every mv := !moves do
Line 8,585 ⟶ 8,589:
w := 0
if \move then
{
board.try(move.i, move.j, n_position + 1)
following_moves := possible_moves(move.i, move.j)
Line 8,647 ⟶ 8,652:
(i_diff = 1 & j_diff = 2)) & &yes) | fail
end</lang>
{{out}}
$ ./knights_tour c5 2 closed
|