|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T r
Length: 3541 (0xdd5)
Types: TextFile
Names: »remark.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/Sun/Othello/remark.c«
/* remark.c
*
* Remark making code.
*
* Copyright: Chris Miller, 1979, 1981, 1984
*
* Included with this othello game by
* Rich Burridge, Sun Microsystems, Australia - December 1986.
*/
#include "othello.h"
char rem_file[] = LIBPATH(LIB,othello.remarks) ;
extern int aspire ;
extern int cretin_flag ;
extern int last_remark ;
extern Panel_item remark_mes ;
FILE *rem_fp ;
long good_remarks[MAX_REMARKS],bad_remarks[MAX_REMARKS] ;
int max_good = 0 ;
int max_bad = 0 ;
make_remark(machine_piece,value)
int machine_piece,value ;
{
char message[100] ;
value *= machine_piece ;
if (value < -INFINITY+64)
{
last_remark = FIRST_REMARK ; /* Always remark next time */
if (aspire == MAXASPIRE)
(void) sprintf(message,"You should win (by at most %d)",-value-INFINITY+64) ;
else (void) strcpy(message,"You should win.") ;
}
else if (value < -1000)
{
if (last_remark != -INFINITY)
{
cretin_flag = TRUE ;
last_remark = -INFINITY ;
(void) strcpy(message,"Only a cretin could lose now.") ;
}
}
else if (value <= 1000) printr(value,message) ;
else if (value < INFINITY-63)
{
if (last_remark!=INFINITY)
{
(void) strcpy(message,"Resign, you dolt! Resistance is futile.") ;
last_remark = INFINITY ;
}
}
else
{
last_remark = FIRST_REMARK ;
if (aspire == MAXASPIRE)
(void) sprintf(message,"I shall win (by at least %d).", value-INFINITY+64) ;
else (void) strcpy(message,"I shall win") ;
}
remark_msg(message) ;
}
get_remarks ()
/* Set up file pointers to remarks; the format of the remarks file is:
*
* Remarks to the effect that machine is winning, in increasing order of
* strength, one per line.
*
* A line beginning with the character "@".
*
* Remarks to the effect that human is winning, in increasing order of
* strength, one per line.
*/
{
long fp = 0l ;
int ch ;
rem_fp = fopen(rem_file,"r") ;
if (rem_fp == NULL)
{
remark_msg("Remarks not available") ;
return ;
}
while ((ch = getc(rem_fp)) != EOF)
{
if (ch == '@') break ;
good_remarks[max_good++] = fp++ ;
if (max_good == MAX_REMARKS)
{
remark_msg("Too many remarks") ;
return ;
}
while (ch != '\n')
{
ch = getc(rem_fp) ;
fp++ ;
}
}
max_good-- ;
fp++ ;
while (ch != '\n')
{
ch = getc(rem_fp) ;
fp++ ;
}
while ((ch = getc(rem_fp)) != EOF)
{
bad_remarks[max_bad++] = fp++ ;
if (max_bad == MAX_REMARKS)
{
remark_msg("Too many remarks") ;
return ;
}
while (ch != '\n')
{
ch = fgetc(rem_fp) ;
fp++ ;
}
}
max_bad-- ;
}
printr(n,string)
int n ;
char string[100] ;
/* Locate file-pointer and print appropriate line. The strange
* computation is to cluster remarks towards low evaluations,
* since the evaluation function changes more rapidly with small
* changes in position as the evaluation gets larger
*/
{
int ch ;
int index ;
float findex ;
int sign_n = (n < 0 ? -1 : 1) ;
char *stringp = string ;
if (rem_fp == NULL) return ;
findex = (float) abs(n) / 1000.0 ;
index = findex * (2-findex) * (n < 0 ? max_bad : max_good) + 0.5 ;
/* Don't make the same remark twice in a row */
if (index * sign_n == last_remark) return ;
last_remark = index * sign_n ;
fseek(rem_fp,n < 0 ? bad_remarks[index] : good_remarks[index],0) ;
while ((ch = getc(rem_fp)) != EOF)
{
if (ch == '\n') break ;
*stringp++ = ch ;
}
*stringp = '\0' ;
}