/* Utils.c: Diverse small utility funcitons that shouldn't lie all over */ #include #include "defs.h" #include "structs.h" #include "vars.h" #include "protos.h" double fmin(double a, double b) { return(a 0) printf("\33[%dC", cols); else if (cols < 0) printf("\33[%dD", cols); } } /* Random integer in [1..i] */ int rnd(int i) { return(rand()%i+1); } int round(float x) { return(x<0.0?(int)(x-0.5):(int)(x+.5)); } int min(int x1, int x2) { return(x1>x2?x2:x1); } int max(int x1, int x2) { return(x10) { for (tf_number = 1;(!any) && (tf_number <= MAX_FLEETS); tf_number++) { any = ((tf[team][tf_number].dest==starnum) && (tf[team][tf_number].eta==0) && ((tf[team][tf_number].c>0) || (tf[team][tf_number].b>0))); } } return (any); } double fact(int k) { int res; for (res = 1; k > 1; res *= k, k--); return(res); } void swap(int *a, int *b) { int t; t = *a; *a = *b; *b = t; } int conv_bcd(int nibble, char byte) { if (nibble == 1) return (byte & 0x0f); return((byte >> 4) & 0x0f); }