need help in lua

hi roaminggamer

yes, I write at the beginning of the discussion: the code runs without error. only the results are totally unexpected in comparison with python, basic … or ring. 

So the question remains unexplained: why does not it run properly in lua? (probably randomizer?)

I agree with you - it is not corona problem.

many thanks for cleaned code. I want to study it… and forgive me the indentation mistake. it was (evidently) created by copy & past (I overlooked it).

thanks for the time given.

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.) :wink:

I hope to have all my notes or comments either translated or deleted and: minValue “10” is now 8! (for you) :wink:

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]

the provided ring code will not run as is:

Line 49 Error (R34) : Variable is required for the assignment operation in file kt.ring&nbsp;

and i’m not about to first debug your ring code just so that i can then debug your lua code derived from it!

>> my lua code works without error. it only provides strange results.

twenty posts later and you STILL haven’t defined what the actual problem is - merely saying “strange results” doesn’t suffice, you have to “help us help you” or why should we even bother?  you get what you pay for with free help.

and who’s the polemical one?  you’ve managed to alienate someone willing to assist, and someone who has actually written a functional knight’s tour in lua.  so i’m done looking at yours, good luck, perhaps others can still help.

  1. you’re right. have the wrong delimiter “;” used.
  2. if p = minVal and random(10) <5 // take it… or not.
  3. minVal = p “;” minD   = m
  4. end
  5. if p < minVal 
  6. minVal = p “;” minD   = m
  7. end  

the correction is here:

minVal = p

minD = m

end

if p < minVal

minVal = p

minD = m

I do not want to get involved with polemik this time.

It only costs time for you and me too.

thank you for looking ring.

it works realy perfect.

I agree with Dave here.  You came in with a question not related to game development in any way.  This would normally be an instant, “Can’t help!”   This isn’t a general help forums.  It is for game developers working with Corona.

However, I’m a sucker for question involving algorithms so I gave it a look.  That said, I hate it when people ask questions and post code that is impossible to read.  I always suggest, ‘provide a full project I can download and run’.  I also ask that the OP provide clear and legible code.  It irks me to have to put in more time examining the code that the OP did asking the question.

Again, Dave is right.  Help us to help you and you’ll be much better off.  I’m waiting to see a copy of this code in the language you programming language copied it from.  That way we can compare the ‘original’ to the ‘converted Lua’ version.

I’d also love to know what ‘does not run properly’ means.

hello roaminggamer

Agreed. I wonder how I was going to react in such situarion in her place. I want to say thank you very much for being patient with me.

I am glad that you are interested in my solution. the algorithm is relatively short (compared to others), clearly understandable and functions really well. we can say perfect because, as we both know, the warnsdorff’s rule is not always successful. It often happens that the choice of the best suitable field leads to the dead end.

the part with the random choice distinguishes the solution. we do not always take the first optimal field (in case of equality) but throw a “coin”. this makes the knight’s path more flexible.

Since I’m still looking for the solution, I need several versions side by side. this is not good with corona (or I do not know how). in the zb-editor I can compare that better. there it does not need the “main” part. therefore no project.

I posted the ring code. for the negligence with the delimiter I’m sorry. 

The phrase “not working properly” should mean better: does not deliver the expected results.

Please do not forget that I have to adapt every sentence I write in English more often in the translator. Sometimes things are different than expected. 

have nice weekend.

hi aficionados

I can not believe it yet … but: IT’S ON !

am still testing and clean up.

but it does and it does as good as the RING.

perfect.   

have nice weekend.