This is what our subgroup came up with for scoring. The array “temp” is useful for properly scoring “rows”. It could be a little more clean in the columns, but identifying singletons isn’t too easy.
vb code tag to display your code with the proper formatting.
It looks like the score function assumes that the global field array will be populated, and to calculate each teams score, you call it twice. The rack array can use any two characters that you want and the character to count are passed to the score function.
Is that correct?
Sounds good. The <cout> for debugging has been removed. Those singletons were troublesom for us, probably not too uncommon an issue for anyone messing with this.
I wish things were a bit more elegant for the columns, but when it’s only 3 high, what are you going to do…
I just have a quick question about this code. Was it intentional to define the rack array as being 9x4? In the game, the rack is 8x3. If I followed the code correctly, it appears that none of the extra spots are used, meaning that there are 12 useless cells in the array.
Otherwise, this looks good. I’m trying to get my own scoring algorithm done and also having a hard time with the singletons.
From what I recall, the 9x4 array was a holdover (no longer used) from a draft where we thought it may be useful to know the sum of pieces active in each row and column, kind of like this image:
(x’s)
xoxxoxxo5
xoooooox2
oxxxxoxx6
21221122
Not that mixing ints and chars is good practice, but it was just a draft that grew.
As far as execution speed, I’m not sure that this would make much of a difference, but would it be equivalent to replace lines 16 through 22 with:
while(c<8 && rack[c]**==piece) c++;
Also, how fast is the pow function compared to say, an array that you make that just contains the correct number of points for a given length? This would also allow you not to use math.h.
Add:
int run_points[9]={0,0,4,8,16,32,64,128,256};
and then replace:
pow(2,counter);
with
run_points[counter];
Edit:
-Corrected a couple of brackets.
-I’ve also written my own version of a score keeping program, though I’m sure it runs many times slower than yours because it does fun things like passing lots of structures by value. Depending on what your using it for though, performance might not really be an issue and you might want to take a look. See: http://www.chiefdelphi.com/forums/showthread.php?t=51408**