|
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 s
Length: 2198 (0x896) Types: TextFile Names: »strength.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/X/Xgo/strength.c«
/* * $Header: strength.c,v 1.3 88/02/19 13:49:15 hale Exp $ */ #include "go.h" #include <pwd.h> FILE *strfile; char filename[500]; extern int strength,opponstr; extern float wins; GetStr() { int id; struct passwd *pw; char *dir; id=geteuid(); pw=getpwuid(id); dir = pw->pw_dir; strcpy(filename,dir); strcat(filename,GOFILE); /* fprintf(stderr,"FILENAME:%s\n",filename); */ if ((strfile = fopen(filename, "r")) != NULL) { fscanf(strfile,"%d",&strength); fscanf(strfile,"%f",&wins); fclose(strfile); } else { strength = 0; wins = 0.0; } } savestr() { float getdelta(), newwins; newwins = getdelta(); if (newwins * wins < 0.0) wins = newwins; else wins += newwins; savestr0(); } savestr0() { if ((strfile=fopen(filename, "w")) != NULL) { if ((wins >= WINSUP && strength < MAXSTR)) { fprintf(strfile,"%d 0.0\n", strength+1); } else if ((wins <= -WINSUP && strength > 1)) { fprintf(strfile,"%d 0.0\n", strength-1); } else { fprintf(strfile,"%d %f\n", strength,wins); } fclose(strfile); } } float getdelta() { if (iwon) { /* i won */ if (strength < opponstr) /* i'm weaker */ return ( (opponstr - strength)/10.0 +1.0); else return ( ((strength - opponstr) > 20) ? 2.0 : 1.0); } else { if (strength < opponstr) return (-1.0); else return ( -((strength - opponstr)/20.0+1.0) ); } } showstr() { GetStr(); if (strength < 31) { printf("Your strength is about: %d kyu.\n", 31-strength); } else if (strength < 40) { printf("Your strength is about: %d dan.\n", strength-30); } else if (strength < MAXSTR+1) { printf("Your strength is about: %d professional dan.\n", strength-39); } else { printf("Your are at maximum strength.\n"); } if (wins>=0) printf("You have also won %d games in a row.\n",(int)(wins/2.0)); else printf("You have also lost %d games in a row.\n",-(int)(wins)); } /* * $Log: strength.c,v $ * Revision 1.3 88/02/19 13:49:15 hale * Added io changes for loading games. * Load game is cleaned up. Variable board * sizes and formats available in save game * as well as printed comments. * * Revision 1.2 88/02/13 12:52:11 hale * modified strength function. * */