2009/10/2 Johnny Rosenberg <[email protected]>:
> 2009/10/2 Fernand Vanrie <[email protected]>:
>> Johnny ,
>>
>> I had also some strange experiences with sorted arrays using the
>> "Bubblesortlist" function, but thats not the reason for this reply. Why
>> using Calc en not a Base document for hosting your dialogs and storing the
>> results ?
>
> 1. Historical reasons. Originally I started to use a spreadsheet as a
> protocol only. When we play, I just filled in the results for each
> roll and sums and bonus were calculated automatically. The cells are
> also formatted conditionally, so if I enter a value that is not valid,
> like 23 on sixes, the background colour of that cell turns red. If I
> score 0 points somewhere, the background turns kind of yellow, when a
> valid value it turns green and when nothing is entered it stays white.
>
> After each game I manually moved the whole protocol to another sheet,
> transforming it and a third sheet calculates what's needed to be
> calculated for a high score list (at the moment more than 900 rows…).
> A fourth sheet displays some average values for each name, like how
> many games they played, average upper sum, average lower sum, average
> bonus nd even average values of every one of the 20 categories etc…
>
> Anyway, then I just felt like making the physical dice unnecessary, by
> simulating them also and… well, the point is that I started it rather
> simple and it kept growing, kind of…
>
> 2. I want to make it happen, and I know Calc best…
>
> Actually i started to write the whole game in C in the late 1980's,
> and I actually reused some of that code in the macros. Well, I
> translated them to BASIC, of course, but some of the algorithms are
> the same. However the dice sorting algorithm is ”new” and very fast
> and very simple… (but it's very optimised for use with dice and things
> like that).
>
> Since I don't have anything better to do right now, I want to tell you
> about the sort algorithm:
> It's a kind of pigeonhole sort.
>
> I have three arrays (I actually only need two of them, but in this
> application I use three for some reasons, which I however won't
> mention here, unless someone asks…):
> Dim Dice(1 To 6) As Integer, SDice(1 To 6) As Integer, Count(1 To 6) As 
> Integer
>
> Dice is, of course, the unsorted array, ”S” in ”SDice” stands for
> Sorted and Count is an array that contains information about how many
> there are of every value of the dice…
>
> So first I use a simple For loop to count dice values, for example if
> Dice = array(3,5,3,4,6,3), then Count will contain array(0,0,3,1,1,1)
> after the loop, telling us that there a no ones, no twos, three
> threes, one four, one five and one six.
>
> Now it's extremely easy to fill the SDice array. Just use the Count
> array and fill SDice with as many of every kind as there is supposed
> to be…
>
> So all I need is two For loops from 1 to 6, kind of.

Forgot to mention that this method of course is more or less
impossible to use for sorting strings and floating point values, but I
guess that's obvious… But it's great for sorting dice, as you can see.

>
> Well… have a nice weekend!
>
> J.R.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to