back step function for st8ts player

Str8ts discussion with Jeff Widderich and Andrew Stuart.
Stellen Sie hier Fragen an Str8ts-Erfinder Jeff Widderich und Andrew Stuart.

Moderatoren: Syndicate, Andrew

back step function for st8ts player

Beitragvon Str8tsFan » Montag 7. Juni 2010, 20:59

Hi,

I think we should do the tech talk about the back step function here. ;)

Jeff Widderich hat geschrieben:Insider information
Ein rueckwaerts Funktion ist sehr viel arbeit .


Sorry, I don't get it where the 'much work' of a back step function should be. As far as I can see, it takes 5 steps to introduce this functionality:

  1. The button itself calling the function back_step(). No big deal, only HTML.
  2. The function back_step() This is quite easy: get the necessary information out of *somewhere*, change the array at one cell and repaint this cell if needed. I assume, the repainting could do the function set_square() which is allready in place.
  3. Some hook at the onchange event of every Cell. It's allready there: function Sudoku1(). So all you need to do is to store the current value of the changed cell *somewhere*. This should be one or two additional lines of code at function Sudoku1().
  4. We need some sort of init step for *somewhere*, as the hook stores the current value of each cell and not the old value. Unfortunately the task of 'loading a board' was mixed up with the task of 'deciding which board to load'. Threrefore you have two setup functions load_board() and load_easy() where the init step must be implemented. This might be the right time to do a little cleanup:
    • rewrite load_board(initString) to load only the board itself
    • create a load_current(print_version) to get the *.asp file and call the new function load_board(mySudoku)
    • and rewrite the load_easy(print_version) also to get only the *.asp file and call the new function load_board(mySudoku)
    Anyway, the init step of our *somewhere* is only some lines of code inside the double loop of j an i where you init all the other arrays also.
  5. Last but not least, the famous *somewhere* must be defined. As allways, the more time you spend in design of your data, the easier it will be to handle it. After some minutes to think about the problem, I would sugest the following solution:
    • One list (which is a stack, lifo-principle) storing all the cell names which are changed. Lets call it cellStack.
    • Second, a hash (associative list) with keys representing the cell name (e.g. 28) and the value being a list (again implemented as a stack) of values. Lets call it cell_valueStack to remember that we refer to it via the cell names and we will get a value which is itself a list of values. So you end up with 81 lists (one for each cell) of old values bundled together to one hash.
    Of course, there are a lot of possible solutions how to build up the data, use whatever you want.
Following my proposal, I will give some examples here:

Init step inside load_board(), load_easy()
Code: Alles auswählen
var cellStack=new Array();
var cell_valueStack=new Object();
// inside the double loop 
    var cellName=''+j+i;
    var cell_valueStack[cellName]=new Array(); 
    cell_valueStack
[cellName].push(g[j][i]);  

Store current value inside Sudoku1()
Code: Alles auswählen
// assuming that you have the variables x and  y and afield.value
var cellName=''+y+x;
cellStack.push(cellName);
// note that we store the current value (after user has changed it), not the old one!
cell_valueStack[cellName].push(afield.value); // or use mask[y][x] if you prefer       

go one step back
Code: Alles auswählen
// check if there are any steps to go back
if(cellStack.length==0){
    alert('Es gibt keine Änderungen zum zurücknehmen.');
    return;
}
// get the last cell which was changed and remove it from stack
var cellToChange=cellStack.pop();
//As we have stored allwasy the current value,
//we now remove the last value of the stack
cell_valueStack[cellToChange].pop();
//now get the value we want to restore
var last=cell_valueStack[cellToChange].length-1;
var valueToRestore=cell_valueStack[cellToChange][last];
// now you have all you need, and you can do the fancy convert_* things to set 
// mask[y][x] and g[y][x] and finally call set_square()
 


Just my 2 cts, maybe I missed some blocking points, this is just a proposal from scratch as I didn't test it.
Cheers,
Str8tFan
Str8tsFan
 
Beiträge: 4
Registriert: Samstag 29. Mai 2010, 12:04

Re: back step function for st8ts player

Beitragvon Andrew » Montag 14. Juni 2010, 11:44

Hi, thanks for the ideas on this. I has been in my job queue for a while now, and today I have added a Back button. It has a memory of 50 steps. A step is any change on the board including the adding or deleting of 'notes'. Do let me know if there are any bugs, I have tested it in many ways. I'm sure I'm going to be asked for a 'forward' button now :)

Appreciate the great feedback so far, and I'm going to be more active in this forum now.

Andrew Stuart
Andrew
 
Beiträge: 4
Registriert: Dienstag 25. Mai 2010, 12:17

Re: back step function for st8ts player

Beitragvon Str8tsFan » Dienstag 15. Juni 2010, 14:08

Welcome Andrew!

Thanks for realizing this function.

Can you give me some hint - why did you limit the stack to 50 steps? Are there any limits within other browsers than firefox?

Andrew hat geschrieben:and I'm going to be more active in this forum now.
Which is very much appreciated!

Andrew hat geschrieben:Do let me know if there are any bugs
Yes, there are. ;)
I try to give my best to debug them, or at least to give a reproduceable testcase. I will give detailed feedback as soon as I know more.

Cheers,
Str8tsFan
Str8tsFan
 
Beiträge: 4
Registriert: Samstag 29. Mai 2010, 12:04

Re: back step function for st8ts player

Beitragvon Andrew » Mittwoch 16. Juni 2010, 02:42

50 steps is arbitrary, but if you need that many steps back you are completely lost and might as well hit 're-start'

I do appreciate bug reports - best to email me directlt at andrew@scanraid.com, my main email address

Many thanks

Andrew
Andrew
 
Beiträge: 4
Registriert: Dienstag 25. Mai 2010, 12:17


Zurück zu English Str8ts forum

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast

cron