Re: Coding gnome-sudoku





2016-07-29 16:42 GMT+02:00 Michael Catanzaro <mcatanzaro gnome org>:
I would recommend against making different types of clicks perform
different actions on the button. That will be really confusing to
users.
HeHe, since I am the user I will not get confused but I actually disagree
as long it is documented (for example: a tooltip when pressing the button)
A "long click" should at least be a second.

> 1)  The board generation is run by a Worker which eventually ends up
> at:
>           puzzle = QQwing.generate_puzzle ((int) category);   // in
> sudoku-generator.vala
>      So when the first run is performed for a number of boards how do
> I get
> new boards when
>      I need to fill up the list?

Currently there's no saved state, we just generate a bunch of boards,
add them to a list, and return them.
That is exactly my point, e.g it is in the start_game_cb function I will have to
make modification to where the board sent to the start_game(<selected board>)
is done.
With my spec, the <selected board> is for normal click:
   next unsolved board from the affected saved list.
and for a "long click":
   the selected board from the affected saved list
 
You probably don't want to modify
the SudokuGenerator as the code there is tricky. The public interface
is pretty easy to use, though, so I would use that to get new boards
when you want them:

SudokuGenerator.generate_boards_async.begin (num_boards, difficulty, (obj, res) => {
        try {
            var boards = SudokuGenerator.generate_boards_async.end (res);
            // Do something with your boards
        } catch (Error e) {
            // ThreadError or IOError, unlikely
        }
    });

Then store the boards you get from that in some other list somewhere
and call it again whenever you want to get some new boards to add to
your list.
Yes and that is my question, 
  How do I ensure that I will not get the same boards generated?
When I examine the qqwing_generate_puzzle function I can't see
it not producing same board again but for some reason are the 
generated boards currently put in the  gen_boards list different
but will be identical when I start the application again, e.g gen_boards[0]
is always the same board.


If you haven't worked with async functions before: the implementation
is a bit tricky but they're easy to use. The begin function returns
immediately, you pass to it a GAsyncReadyCallback that will be executed
sometime in the future when it completes. Usually easiest to use a
lambda for this, if the implementation is small. Inside that callback,
you pass the GAsyncResult res to the end function, and out pops your
result. If the async function throws an exception (generate_boards can
throw two types of exceptions), it will be thrown from the end
function.

Michael
I am totally new to the GTK world of widgets/events/signals./... and have never
worked with vala but looking at the code is not very difficult, just a new way
of writing.
This is mostly a learning experience and as bonus I will get my sudoku game
working as I want it.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]