knights-tour

Implementing warndorffs rule for the first 32 moves of my knights tour, then using a stack and brute force backtracking

倾然丶 夕夏残阳落幕 提交于 2020-03-24 09:42:06
问题 Ive changed the code, and even got a knights tour to work at starting at 0,0, but ever since the first time I've complied I havent gotten it to work, and im a little confused on how it possibly worked correctly the first time. sample output: 0 61 14 23 50 27 12 25 15 22 63 60 13 24 51 28 62 1 58 49 52 55 26 11 21 16 37 56 59 48 29 54 2 57 20 45 36 53 10 47 17 44 35 38 41 46 7 30 34 3 42 19 32 5 40 9 43 18 33 4 39 8 31 6 import java.util.Stack; import java.util.concurrent.ThreadLocalRandom;

Translating a tabled predicate from b-prolog to gprolog

≯℡__Kan透↙ 提交于 2020-01-05 04:06:33
问题 For fun I've been attempting to write a Knight's Tour (https://en.wikipedia.org/wiki/Knight%27s_tour) solver in gprolog using Warnsdorf's rule. I found another SO post asking about efficiency that provided a solution in B-prolog: knight's tour efficient solution. My problem arises with the following section: :- table warnsdorff(+,+,+,+,+,-,-,min). warnsdorff(R, C, X, Y, Visits, NewX, NewY, Score) :- possible_knight_moves(R, C, X, Y, Visits, NewX, NewY), possible_moves_count(R, C, NewX, NewY,

Keeping track of the path, Knights travel

我的未来我决定 提交于 2019-12-11 14:15:04
问题 So far my shortest path method will stop when it reaches the goal position, printing out everything it did along the way. I would like to know how I could go about implementing parent positions so I can print the path along with the goal. This is an assignment. class Knight attr_accessor :x, :y, :prev_position, :moves def initialize(position) @x = position[0] @y = position[1] @prev_position = nil @moves = [ [-1,-2], [-2,-1], [-2,+1], [-1,+2], [+1,-2], [+2,-1], [+2,+1], [+1,+2]] end def