Repository navigation
Expand file tree
/
Copy pathgene.c
More file actions
95 lines (84 loc) · 2.49 KB
/
Copy pathgene.c
File metadata and controls
95 lines (84 loc) · 2.49 KB
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
/*
* gene.c: Rog-O-Matic XIV (CMU) Sat Jul 5 23:47:33 1986 - mlm
* Copyright (C) 1985 by A. Appel, G. Jacobson, L. Hamey, and M. Mauldin
*
* Initialize and summarize the gene pool
*
* EDITLOG
* LastEditDate = Sat Jul 5 23:47:33 1986 - Michael Mauldin
* LastFileName = /usre3/mlm/src/rog/ver14/gene.c
*
* HISTORY
* 5-Jul-86 Michael Mauldin (mlm) at Carnegie-Mellon University
* Created.
*/
# include <stdio.h>
# include <stdlib.h>
# include "types.h"
# include "globals.h"
# include "install.h"
int knob[MAXKNOB];
char *knob_name[MAXKNOB] = {
"trap searching: ",
"door searching: ",
"resting: ",
"using arrows: ",
"experimenting: ",
"retreating: ",
"waking monsters: ",
"hoarding food: "
};
char genelock[100];
char genelog[100];
char genepool[100];
int main (argc, argv)
int argc;
char *argv[];
{ int m=10, init=0, seed=0, version=DEFRV, full=0;
/* Get the options */
while (--argc > 0 && (*++argv)[0] == '-')
{ while (*++(*argv))
{ switch (**argv)
{ when 'a': full=2;
when 'i': init++;
when 'f': full=1;
when 'm': m = atoi(*argv+1); SKIPARG;
printf ("Gene pool size %d.\n", m);
when 's': seed = atoi(*argv+1); SKIPARG;
printf ("Random seed %d.\n", m);
when 'v': version = atoi(*argv+1); SKIPARG;
printf ("Rogue version %d.\n", version);
otherwise: quit (1,
"Usage: gene [-if] [-msv<value>] [genepool]\n");
}
}
}
if (argc > 0)
{ if (readgenes (argv[0])) /* Read the gene pool */
analyzepool (full); /* Print a summary */
else
fprintf (stderr, "Cannot read file '%s'\n", argv[0]);
exit (0);
}
/* No file argument, assign the gene log and pool file names */
sprintf (genelock, "%s/GeneLock%d", RGMDIR, version);
sprintf (genelog, "%s/GeneLog%d", RGMDIR, version);
sprintf (genepool, "%s/GenePool%d", RGMDIR, version);
critical (); /* Disable interrupts */
if (lock_file (genelock, MAXLOCK))
{ if (init)
{ srand (seed); /* Set the random number generator */
openlog (genelog); /* Open the gene log file */
initpool (MAXKNOB, m); /* Random starting point */
writegenes (genepool); /* Write out the gene pool */
closelog (); /* Close the log file */
}
else if (! readgenes (genepool)) /* Read the gene pool */
quit (1, "Cannot read file '%s'\n", genepool);
unlock_file (genelock);
}
else
quit (1, "Cannot access file '%s'\n", genepool);
uncritical (); /* Re-enable interrupts */
analyzepool (full); /* Print a summary */
}