-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgmplot.c
157 lines (123 loc) · 4.3 KB
/
rgmplot.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* rgmplot.c: Rog-O-Matic XIV (CMU) Thu Jan 31 20:04:11 1985 - mlm
* Copyright (C) 1985 by A. Appel, G. Jacobson, L. Hamey, and M. Mauldin
*
* This program takes a Rog-O-Matic score file sorted by date and score,
* and produces a scatter plot of the scores.
*/
# include <stdio.h>
# define WIDTH 50
# define AVLEN 7
# define SCALE(n) (((n)+100)/200)
# define isdigit(c) ((c) >= '0' && (c) <= '9')
char *month[] =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
int doavg = 0, cheat = 0, min = -1;
main (argc, argv)
int argc;
char *argv[];
{ int mm, dd, yy, score = 0, lastday = -1, lastmon = -1, h;
int sumscores = 0, numscores = 0, i;
int sum[AVLEN], num[AVLEN], rsum, rnum, davg, ravg;
char player[100], plot[128], cheated;
/* Clear out the rolling average statistics */
for (i = 0; i < AVLEN; i++)
sum[i] = num[i] = 0;
/* Get the options */
while (--argc > 0 && (*++argv)[0] == '-')
while (*++(*argv))
{ switch (**argv)
{ case 'c': cheat++; break; /* List cheat games */
case 'a': doavg++; break; /* Print average */
default: printf ("Usage: rgmplot [-ac] [mininum]\n");
exit (1);
}
}
if (argc > 0) min = atoi (argv[0]);
/* Print out the header */
printf (" Scatter Plot of Rog-O-Matic Scores versus time\n\n");
if (min > 0)
printf (" Scores greater than %d\n\n", min);
printf (" 0 2000 4000 6000 8000 10000\n");
printf (" |----+----|----+----|----+----|----+----|----+----|\n");
/* Build an empty plot line */
strcpy (plot, "| |");
/* While more scores do action for each score */
while (getscore (&mm, &dd, &yy, player, &score, &cheated) != EOF)
{
/* Change days, overprint the average for day, rolling avg */
if ((dd != lastday || mm != lastmon) && lastday > 0)
{ if (doavg)
{ rsum = *sum; rnum = *num;
for (i = 1; i < AVLEN; i++)
{ rsum += sum[i]; rnum += num[i]; }
davg = SCALE ((*num > 0) ? (*sum / *num) : 0);
ravg = SCALE ((rnum > 0) ? (rsum / rnum) : 0);
/* Roll the daily average statistics */
for (i = AVLEN-1; i > 0; i--)
{ sum[i] = sum[i-1]; num[i] = num[i-1]; }
*sum = *num = 0;
/* Print a '*' for the daily average */
if (davg > 0 && davg < WIDTH)
plot[davg] = '*';
/* Print a '###' for the rolling average */
if (ravg > 0 && ravg < WIDTH-1)
plot[ravg-1] = plot[ravg] = plot[ravg+1] = '#';
}
printf ("%3s %2d %s\n", month[lastmon-1], lastday, plot);
strcpy (plot, "| |");
}
if (score > EOF)
{ if ((h = SCALE(score)) >= WIDTH) sprintf (plot, "%s %d", plot, score);
else if (plot[h] == '9') ;
else if (isdigit(plot[h])) plot[h]++;
else plot[h] = '1';
*sum += score;
++*num;
sumscores += score;
++numscores;
lastday = dd; lastmon = mm;
}
}
printf (" |----+----|----+----|----+----|----+----|----+----|\n");
printf (" 0 2000 4000 6000 8000 10000\n");
if (numscores > 0)
printf ("\nAverage score %d, total games %d.\n\n",
sumscores/numscores, numscores);
printf ("1-9 Number of games in range.\n");
if (doavg)
{ printf (" * Average of day's scores.\n");
printf ("### Rolling %d day average.\n", AVLEN);
}
}
getlin (s)
char *s;
{ int ch, i;
static int endfile = 0;
if (endfile) return (EOF);
for (i=0; (ch = getchar()) != EOF && ch != '\n'; i++)
s[i] = ch;
s[i] = '\0';
if (ch == EOF)
{ endfile = 1;
strcpy (s, "-1 -1, -1 string -1 ");
return (20);
}
return (i);
}
getscore (mm, dd, yy, player, score, cheated)
int *mm, *dd, *yy, *score;
char *player, *cheated;
{ char line[128], reason[32];
while (getlin (line) != EOF)
{ sscanf (line, "%d %d, %d %10s%d%c%17s",
mm, dd, yy, player, score, cheated, reason);
if ((*score >= min || *score < 0) &&
(*cheated != '*' || cheat) &&
!stlmatch (reason, "saved") &&
(*score > 2000 || !stlmatch (reason, "user")))
return (1);
}
return (EOF);
}