hi davebollinger
there are a few subscriptions on the web dealing with lua randomizer and his “mysteria”. I tried the samples all without success.
my lua code works without error. it only provides strange results.
to your remark: “same code runs in other languages” - which can not be true.
I can post the RING code here. However, I doubt it will help. you did not even test the lua code yourself. why then this polemic?
the index minValue “10” is intentionally not “8” so that you can not assign it incorrectly (it can also have the value 7 or even 6).
and to german comments: these are my notes … thoughts. I forgot to delete it. apologize.
besides that, German is not my mother tongue. I’ve had to learn a few languages in my (long) life. Now it is German (to be precise - Swiss German).
I agree with you that the discourse here actually develops in a wrong, (polemical) direction (you can already see it not only in these lines). Things are being criticized that have nothing to do with the actual (LUA) problem. even the “indentation” has already been mentioned … or namingstyle of the variables. the effect, even without your accusation (I’m a liar), really disappointing.
I apologize for taking your time. and please also excuse my google english - english is not my “native”.
and here … a little present for you (soon is christmas):
(look at it, it works perfectly. you will find (perhaps) that the program acts more inteligent than any writers here.)
I hope to have all my notes or comments either translated or deleted and: minValue “10” is now 8! (for you)
ok… have nice weekend.
[lua]
// kt-02-3.ring warnsdorff extended (for control of the lua version)
// http://ring-lang.net
// possible moves
pm = [[-2,1],[-1,2],[1,2],[2,1],[-2,-1],[-1,-2],[1,-2],[2,-1]]
n = 8 //number rows/collons
cbx = n // rows
cby = n // colls
// startfeld ( 2/2 = critical!)
kx = 2 // works fine now
ky = 2 // works fine now
// make chessboard n*n
cb = list(cby) for x in cb x = list(cbx) next
k = 0 // jmps-counter
while k <= cbx * cby
cb[ky][kx] = k+1
pq = [] // priority Queu (reset)
for i = 1 to n // row
nx = kx + pm[i][1]; ny = ky + pm[i][2]
if between(nx, 1, cbx) and between(ny, 1, cby)
if cb[ny][nx] = 0 ctr = 0 // without impact whether 0 oder 1
for j = 1 to n // col
ex = nx + pm[j][1] ; ey = ny + pm[j][2]
if between(ex, 1, cbx) and between(ey, 1, cby)
if cb[ey][ex] = 0 ctr++ ok
ok
next
add(pq,(ctr*100)+i) // format: 302
ok // if cb[ny][nx]
ok // if between(nx, 1, cbx) and
next // for i
# – Warnsdorff’s algorithmus; extended
if len(pq) > 0
pq = sort(pq) // min-wert at begin
minVal = 8 // max loop no
minD = 0 // min value (not necessary here)
for dd = 1 to len(pq)
x= pq[1] // min-value
p = floor(x/100) // ctr - counter
m = x % 10 // i - row (loop-no)
if p = minVal and random(10) <5 // take it… or not.
minVal = p; minD = m
end
if p < minVal
minVal = p; minD = m
end
Del(pq,1) // delete item number
end //dd
m = minD
kx = kx + pm[m][1]
ky = ky + pm[m][2]
else
if k < 63
see "Error in the field no.: "+k+nl
exit
else
see “Success.” +nl
exit
ok
ok
k++
end // while// end pgm **************************************
// kontroll-ausgabe:
for r = 1 to N // row
for c = 1 to N // col
see “|” //
if cb[c][r] <= (n+1)
see “_”
//see " " // alt 255 (nok)
see cb[c][r]
else
see cb[c][r] // jump-no. from cb
ok
next //for
see “|”
see nl
next //for
func between x, mi, mx // min & max keywords
between = (x >= mi) AND (x <= mx)
return between
[/lua]