Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Scoring function in C (http://www.chiefdelphi.com/forums/showthread.php?t=51480)

mgreene 10-01-2007 15:31

Scoring function in C
 
1 Attachment(s)
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.

Any ideas for something a little more efficient?

Joe Ross 10-01-2007 15:54

Re: Scoring function in C
 
You can use the [code] 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?

mgreene 10-01-2007 16:37

Re: Scoring function in C
 
Sounds about right, and perhaps the commenting leaves something to be desired.

int score(char piece)
returns the (integer) score of a particular team(passed as a char, "piece").

char rack[][] contains character "pieces" (X's and O's, if you like)

MG

(spoilers actually score correctly, but only because their char (piece) would be different from that passed to the function on the call)

Joe Ross 10-01-2007 17:48

Re: Scoring function in C
 
Your algorithm gives the same results as mine (and I think yours is faster, although I haven't really tested it).

The single cout seems to be unnecessary, and removing it saves someone from having to include iostream (if they aren't already using it).

Also, declaring your variables inside the for construct is only legal in c++ not c.

mgreene 10-01-2007 21:00

Re: Scoring function in C
 
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...

MattD 11-01-2007 07:34

Re: Scoring function in C
 
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.

mgreene 11-01-2007 13:02

Re: Scoring function in C
 
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.

MG

SoftwareBug2.0 12-01-2007 02:36

Re: Scoring function in C
 
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:
Code:

while(c<8 && rack[c][b]==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:
Code:

int run_points[9]={0,0,4,8,16,32,64,128,256};
and then replace:
Code:

pow(2,counter);
with
Code:

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/sh...ad.php?t=51408


All times are GMT -5. The time now is 17:31.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi