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. Well… have a nice weekend! J.R. > Greetz > Fernand >> >> I am writing a quite big macro thing, it's actually a simple game in >> Calc, called ”Maxi-Yatzy” in Swedish, somewhat known as a Swedish >> extended variant of Yahtzee, with 6 dice, 20 categories and you can >> save two of your three rolls for later. >> >> I ran into something that made me vary confused for quite some time. >> >> I have a couple of dialogs, one of them is the game itself. Another >> one is for selecting names from drop down boxes and things like that. >> I did all this in Calc, so I can easily save all results ever played >> in detail with date and time and everything, so the high scores list >> will be huge eventually, which is one of the points with the whole >> thing. >> >> Anyway, in the games dialog, I have a check box called ”sort”. If the >> player checked this box, the dice will be rolled as usual (I use some >> UTF-8 characters, U+2680-U+2685 - ”⚀⚁⚂⚃⚄⚅” to display the results of >> each roll), beu when the roll stops, a pause of one second will follow >> and then all dice will be sorted. I figured that maybe not everyone >> want their dice sorted, that's why I added that check box. >> >> The strange thing was that if I selected ”Sort” then rolled the dice, >> the dice showed up as sorted. If I then unchecked it again, they still >> showed up as sorted, however wothout the one second pause… >> >> So why was that? >> >> I use two different arrays for the dice: >> Dim Dice(1 To 6) As Integer ' All the six dice >> Dim SDice(1 To 6) As Integer ' All the six dice sorted >> >> So, if the checkbox is checked, the macro copies the sorted data to >> the unsorted array, like this: >> Dice()=SDice() >> >> Very elegant, right? >> Yes, I wish… >> This very line was actually the reason for those strange things going on! >> >> It seems like ”Dice()=SDice()” actually means that ”from now on Dice() >> is just another name for SDice()”. It seems to work like pointers in >> C/C++: Dice() points at SDice(). >> >> So what I did to correct this was to use a loop to copy all the values >> one by one: >> For i=1 To 6 >> Dice(i)=SDice(i) >> Next i >> >> Well, going back to the macro now. I still have quite a lot problems to >> solve… >> >> J.R. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
