home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 6
/
FreshFish_September1994.bin
/
new
/
dev
/
c
/
hce
/
examples
/
amiga
/
pools
/
pools.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-02
|
16KB
|
569 lines
/*
* EasyPools:
*
* Copyright (c) 1994. Author: Jason Petty.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to redistribute it freely, with the
* following restrictions:
* 1) No charge may be made other than reasonable charges for reproduction.
* 2) Modified versions must be clearly marked as such.
* 3) The authors are not responsible for any harmful consequences
* of using this software, even if they result from defects in it.
*
*
* USAGE:
*
* Gives simple pools results based on tables found in the
* 'P_TABLES' file.
* Can send the results to a printer.
*
*
* This first version of EasyPools is a some what rushed version,
* and does not do nearly enough calculations to get good pools results.
* It is here merely as an example of using HCE with more than one C
* source file. Feel free to improve EasyPools.
*
*/
#include <exec/types.h>
#include <exec/errors.h>
#include <exec/memory.h>
#include <clib/stdio.h>
#include <clib/string.h>
#include "pools.h"
/* For calculation functions. */
#define G_PLAYED 0
#define G_WON 1
#define G_DRAWN 2
#define G_LOST 3
#define SAME_PLAYED 0x00000001
#define NEAR_PLAYED 0x00000002
#define SAME_WON 0x00000004
#define NEAR_WON 0x00000008
#define SAME_DRAWN 0x00000010
#define NEAR_DRAWN 0x00000020
#define SAME_LOST 0x00000040
#define NEAR_LOST 0x00000080
extern P_TABLE *t_head; /* Head of table list read in by read.c */
int PRINT_ON=FALSE; /* flag. Send results to printer?. */
BYTE p_error; /* flag. General printer error. */
char PRT_B[5][100]; /* Printer Buffer. */
char TXT_B[100]; /* Window text buffer. */
char draw_msg[60]; /* Prediction message. */
int home_c=0; /* Vars - used to calculate chances of a Draw. */
int away_c=0;
int draw_c=0;
int league_c=0; /* Show/Print league number. */
int coupon_c=0; /* Show/Print coupon number. */
void main()
{
long league=0;
int i=0;
int quit=0;
if(!start()) /* Open screen/window/gad/printer set graphics etc. */
exit(10); /* EXIT_ERROR. This must succeed to continue!!. */
if(!readfile()) { /* Try read the pools tables from disk .*/
close_shop("ERROR: Could not read tables from disk!!");
}
PRINT_ON=FALSE; /* Keep false for now. */
Show_LEAGUE_N(); /* Show league names to choose from. */
while(!quit) /* MAIN LOOP */
{
league = Get_GMsgs2(); /* Get a valid league number. (gfx_win). */
if(league != -1)
{
league_c = league+1;
if(league == 1000)
quit++;
else
Do_LEAGUE(league);
Show_LEAGUE_N(); /* Reshow league names,( might have */
league = -1; /* been trashed). */
}
}
close_shop("OK!!"); /* Ok!!. */
}
void close_shop(msg) /* Close and free everything. */
char *msg;
{
/* printf("%s\n",msg); */
(void)finish(); /* Must call this!!. (frees all memory gads etc). */
exit(0); /* OK!. */
}
void Do_LEAGUE(id) /* Do Fixtures until IDCMP_CLOSEWINDOW. */
int id;
{
P_TABLE *pt;
int i,r,home,away,near;
WORD endall=0;
WORD limmit = 0;
int *h_team,*a_team;
int *tb[30];
WORD step;
char *t_names[30];
char *p,pb[2];
draw_msg[0] = '\0';
draw_msg[1] = '\0';
pt=t_head; /* Head of table list. */
for(i=0;i < id;i++) { /* Find correct table. */
if(pt->next != NULL)
pt = pt->next;
}
if(!(Open_GWind(pt->league))) /* Open wind with new heading. */
return;
limmit = pt->count;
Show_LEAGUE(pt); /* Show teams. */
for(i=0;i <= limmit;i++) /* Get pointers to team form numbers. */
tb[i] = pt->table[i];
for(i=0;i <= limmit;i++) /* Get pointers to team names. */
t_names[i] = pt->team[i];
Draw_RBOX(); /* Draw pools result box. */
g_BPEN(10); /* Grey. */
Refresh_GWind(); /* Refresh gadgets in g_window. */
while(!endall)
{
home_c=0;
away_c=0;
draw_c=0;
near=0;
step=0;
if(!(Get_Team(&home,limmit))) { /* Get valid home team. */
(void)Close_GWind();
return; /* User Quit? */
}
Clear_RBOX(); /* Clear printing area. */
g_FPEN(1); /* White. */
i = strlen(t_names[home])-1; /* Get home teams string length*/
pb[1] = '\0';
while(i >= 0) { /* Print home team in reverse, */
pb[0] = t_names[home][i]; /* keeps it even to away team. */
g_TXT(pb,(269-step), RS_Y); /* RS_Y: Result area Y start. */
step += 8;
i--;
}
g_TXT("- V`s -",293, RS_Y);
if(!(Get_Team(&away,limmit))) { /* Get valid away team. */
(void)Close_GWind();
return; /* User Quit? */
}
g_TXT(t_names[away],365, RS_Y); /* No need for reverse here. */
h_team = tb[home];
a_team = tb[away];
coupon_c++; /* Inc coupon number. */
/* DEBUG **************************************************************
printf("HOME TABLE: %d %d %d %d %d %d %d\n",
h_team[0],h_team[1],h_team[2],h_team[3],h_team[4],h_team[5],h_team[6]);
printf("AWAY TABLE: %d %d %d %d %d %d %d\n",
a_team[0],a_team[1],a_team[2],a_team[3],a_team[4],a_team[5],a_team[6]);
***********************************************************************/
/****************** CALCULATIONS *******************/
/* Calc home_c and away_c. */
near |= cr_GamesPlayed(h_team,a_team);
near |= cr_GamesWon(h_team,a_team);
near |= cr_GamesDrawn(h_team,a_team);
near |= cr_GamesLost(h_team,a_team);
/****** These are not really required! *****
cr_GamesFor();
cr_GamesAgainst();
cr_TeamPoints();
**********************************/
/* Work out chances of a draw. */
if(home_c > away_c) {
draw_c = 100 - (home_c - away_c);
}
if(home_c < away_c) {
draw_c = 100 - (away_c - home_c);
}
if(home_c == away_c) {
draw_c = 100;
}
if(draw_c < 0)
draw_c = 0;
/* Work out comment to go with results */
Do_Comment();
strcat(draw_msg,"-(");
if(near & SAME_PLAYED) /* HOME & AWAY - PLAYED SAME. */
strcat(draw_msg,"P");
if(near & NEAR_PLAYED) /* HOME or AWAY - PLAYED, 1 MORE. */
strcat(draw_msg,"p");
if(near & SAME_WON) /* HOME & AWAY - WON SAME. */
strcat(draw_msg,"W");
if(near & NEAR_WON) /* HOME or AWAY - WON, 1 MORE. */
strcat(draw_msg,"w");
if(near & SAME_DRAWN) /* HOME & AWAY - DRAWN SAME. */
strcat(draw_msg,"D");
if(near & NEAR_DRAWN) /* HOME or AWAY - DRAWN, 1 MORE. */
strcat(draw_msg,"d");
if(near & SAME_LOST) /* HOME & AWAY - LOST SAME. */
strcat(draw_msg,"L");
if(near & NEAR_LOST) /* HOME or AWAY - LOST, 1 MORE. */
strcat(draw_msg,"l");
strcat(draw_msg,")");
/*************** END OF CALCULATIONS *******************/
/* Print results in g_window. */
g_FPEN(5); /* Blue. */
g_TXT("COUPON-NO LEAGUE HOME AWAY DRAW ?",156,RS_Y+20);
g_FPEN(1); /* White. */
sprintf(TXT_B,"%d",coupon_c); /* Coupon No. */
g_TXT(TXT_B,156,RS_Y+30);
sprintf(TXT_B,"%d",league_c); /* League. */
g_TXT(TXT_B,156+88,RS_Y+30);
sprintf(TXT_B,"%d%%",home_c); /* Print Home. */
g_TXT(TXT_B,156+152,RS_Y+30);
sprintf(TXT_B,"%d%%",away_c); /* Print Away. */
g_TXT(TXT_B,156+200,RS_Y+30);
sprintf(TXT_B,"%d%%",draw_c); /* Print Draw. */
g_TXT(TXT_B,156+248,RS_Y+30);
g_FPEN(2); /* Yellow. */
g_TXT(draw_ms