Go to Post It's a process of elimination led by inspiration. - JaneYoung [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 10-01-2007, 15:31
mgreene mgreene is offline
Registered User
AKA: Mike Greene
FRC #1351 (TKO)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: San Jose, CA
Posts: 12
mgreene is on a distinguished road
Scoring function in C

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?
Attached Files
File Type: doc score.doc (22.0 KB, 86 views)

Last edited by mgreene : 10-01-2007 at 20:58. Reason: (edited to remove debugging statements)
  #2   Spotlight this post!  
Unread 10-01-2007, 15:54
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,576
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
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?

Last edited by Joe Ross : 10-01-2007 at 15:59.
  #3   Spotlight this post!  
Unread 10-01-2007, 16:37
mgreene mgreene is offline
Registered User
AKA: Mike Greene
FRC #1351 (TKO)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: San Jose, CA
Posts: 12
mgreene is on a distinguished road
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)

Last edited by mgreene : 10-01-2007 at 16:50.
  #4   Spotlight this post!  
Unread 10-01-2007, 17:48
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,576
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
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.
  #5   Spotlight this post!  
Unread 10-01-2007, 21:00
mgreene mgreene is offline
Registered User
AKA: Mike Greene
FRC #1351 (TKO)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: San Jose, CA
Posts: 12
mgreene is on a distinguished road
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...
  #6   Spotlight this post!  
Unread 11-01-2007, 07:34
MattD's Avatar
MattD MattD is offline
Registered User
AKA: Matthew Douglas
FRC #0228 (GUS Robotics)
Team Role: Alumni
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Indianapolis, IN
Posts: 185
MattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to behold
Send a message via AIM to MattD
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.
__________________
GUS Robotics Team 228

2010 WPI Engineering Inspiration Award
2010 WPI Regional Champions (Thanks 230 & 20!)
2010 CT VEX Champions
2010 CT VEX Innovate Award
2009 QCC VEX Champions
2009 CT Motorola Quality Award
2007 CT J&J Sportsmanship Award
2006 CT Best Website Award
  #7   Spotlight this post!  
Unread 11-01-2007, 13:02
mgreene mgreene is offline
Registered User
AKA: Mike Greene
FRC #1351 (TKO)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: San Jose, CA
Posts: 12
mgreene is on a distinguished road
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
  #8   Spotlight this post!  
Unread 12-01-2007, 02:36
SoftwareBug2.0's Avatar
SoftwareBug2.0 SoftwareBug2.0 is offline
Registered User
AKA: Eric
FRC #1425 (Error Code Xero)
Team Role: Mentor
 
Join Date: Aug 2004
Rookie Year: 2004
Location: Tigard, Oregon
Posts: 486
SoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant futureSoftwareBug2.0 has a brilliant future
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

Last edited by SoftwareBug2.0 : 12-01-2007 at 02:50.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
To function properly? Pirate_Nelly354 Chit-Chat 22 18-08-2006 21:33
Arcade Function gabrielse Programming 1 08-02-2006 00:49
Limit_Mix() Function EricWilliams Programming 2 27-07-2005 23:19
Autocalibrate function Validius Programming 2 29-03-2005 21:59
FreeLibrary() Function Raven_Writer Programming 0 09-08-2003 15:39


All times are GMT -5. The time now is 02:58.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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