Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TOTALGAMES 16
#define TOTALTEAMS 32
#define VECTORLENGTH 4
typedef struct
{
int week;
int hometeam;
int awayteam;
float homescore;
float awayscore;
} game_t;
game_t * init_games(game_t *gamePtr)
{
static game_t game[TOTALGAMES] = {
{1,15,11,17.0,24.0} ,
{1,29,12,30.0,10.0} ,
{1,28,30,13.0,34.0} ,
{1,18,22,27.0,23.0} ,
{1,25,24,32.0,40.0} ,
{1,5,13,16.0,17.0} ,
{1,9,14,24.0,40.0} ,
{1,17,3,48.0,28.0} ,
{1,31,16,26.0,23.0} ,
{1,7,26,20.0,16.0} ,
{1,6,20,16.0,10.0} ,
{1,19,0,22.0,30.0} ,
{1,4,27,31.0,19.0} ,
{1,23,2,44.0,13.0} ,
{1,21,8,14.0,22.0} ,
{1,1,10,41.0,21.0}
};
gamePtr = game;
return gamePtr;
}
float getAverageHome(game_t *gamePointer)
{
int i;
float hometotal = 0;
for (i = 0 ; i < TOTALGAMES ; i++)
{
hometotal += gamePointer[i].homescore;
}
float homeaverage = hometotal / (TOTALGAMES * 1.0);
//printf("%f",awayaverage);
return homeaverage;
}
float getAverageAway(game_t *gamePointer)
{
int i;
float awaytotal = 0;
for (i = 0 ; i < TOTALGAMES ; i++)
{
awaytotal += gamePointer[i].awayscore;
}
float awayaverage = awaytotal / (TOTALGAMES * 1.0);
//printf("%f",awayaverage);
return awayaverage;
}
float getAverage(game_t *gamePointer)
{
int i;
float total = 0;
int count=0;
for (i = 0 ; i < TOTALGAMES ; i++)
{
total += gamePointer[i].homescore;
total += gamePointer[i].awayscore;
count += 2;
}
float homeaverage = total / (count * 1.0);
//printf("%f",homeaverage);
return homeaverage;
}
void runVectors(game_t *gamePointer , float teamoffense[VECTORLENGTH][TOTALTEAMS],float teamdefense[VECTORLENGTH][TOTALTEAMS], float homeaverage , float awayaverage)
{
float initdelta = .1;
float delta = initdelta;
int i,j,k,loop;
float tohtxtdat,toatxtdht;
float epsilon = .000001;
for (j = 0 ; j < VECTORLENGTH ; j++)
{
// delta = initdelta / ( pow(10, (j)));
for (loop = 0 ; loop < 100000 ; loop++)
{
for (i = 0 ; i < TOTALGAMES ; i++)
{
tohtxtdat = 0;
toatxtdht = 0;
for (k = 0 ; k <= j ; k++) // FIND THE SUM OF OFFENSE VECTOR TIMES DEFENSE VECTOR
{
tohtxtdat += teamoffense[k][gamePointer[i].hometeam]*teamdefense[k][gamePointer[i].awayteam];
toatxtdht += teamoffense[k][gamePointer[i].awayteam]*teamdefense[k][gamePointer[i].hometeam];
}
// IF THE PREDICTED SCORE, BASED ON THE VECTORS IS HIGHER THAN THE ACTUAL SCORE, THEN DECREASE THE OFFENSE AND DEFENSE VECTORS
if ( ((tohtxtdat * homeaverage) > gamePointer[i].homescore) && (abs((tohtxtdat*homeaverage)-gamePointer[i].homescore) > epsilon) )
{
teamoffense[j][gamePointer[i].hometeam] -= delta;
teamdefense[j][gamePointer[i].awayteam] -= delta;
}
if ( ((tohtxtdat * homeaverage) < gamePointer[i].homescore) && (abs((tohtxtdat*homeaverage)-gamePointer[i].homescore)>epsilon) )
{
teamoffense[j][gamePointer[i].hometeam] += delta;
teamdefense[j][gamePointer[i].awayteam] += delta;
}
if ( ((toatxtdht * awayaverage) > gamePointer[i].awayscore) && (abs((toatxtdht*awayaverage)-gamePointer[i].awayscore)>epsilon) )
{
teamoffense[j][gamePointer[i].awayteam] -= delta;
teamdefense[j][gamePointer[i].hometeam] -= delta;
}
if ( ((toatxtdht * awayaverage) < gamePointer[i].awayscore) && (abs((toatxtdht*awayaverage)-gamePointer[i].awayscore)>epsilon) )
{
teamoffense[j][gamePointer[i].awayteam] += delta;
teamdefense[j][gamePointer[i].hometeam] += delta;
}
}
}
}
}
int main(void)
{
float teamoffense[VECTORLENGTH][TOTALTEAMS];
float teamdefense[VECTORLENGTH][TOTALTEAMS];
int i,j;
for (i = 0 ; i < VECTORLENGTH ; i++)
{
for (j = 0 ; j < TOTALTEAMS ; j++)
{
teamoffense[i][j] = 1.0;
teamdefense[i][j] = 1.0; // INITIALIZE VECTORES TO 1.0
}
}
printf("FOOTBALL: \n");
game_t * gamePointer = NULL;
gamePointer = init_games(gamePointer); //LOAD THE ACTUAL NFL WEEK 1 SCORES
//float homeaverage = getAverageHome(gamePointer);
//float awayaverage = getAverageAway(gamePointer);
float homeaverage = 1.0; // SET THIS TO 1.0 FOR TESTING
float awayaverage = 1.0;
runVectors(gamePointer , teamoffense ,teamdefense, homeaverage , awayaverage);
int home,away,v;
away = 28; // TITANS -- ACTUAL SCORE OF GAME: AWAY TITANS: 13 -- HOME PATRIOTS: 34
home = 30; // N.E. PATRIOTS
float homescore=0,awayscore=0;
for (v = 0 ; v < VECTORLENGTH ; v++)
{
homescore += (teamoffense[v][home]*teamdefense[v][away]);
awayscore += (teamoffense[v][away]*teamdefense[v][home]);
}
homescore = (homescore * homeaverage);
awayscore = (awayscore * awayaverage);
printf("------------\n");
printf("Away %i : %f \n",away,awayscore);
printf("Home %i : %f \n",home,homescore); // PREDICTION IS 13.97, TO 34.998
printf("------------ \n");
printf("%f\n",teamoffense[0][home]);
printf("%f\n",teamdefense[0][away]);
printf("-----\n");
printf("%f\n",teamoffense[1][home]);
printf("%f\n",teamdefense[1][away]);
printf("-----\n");
printf("%f\n",teamoffense[2][home]);
printf("%f\n",teamdefense[2][away]);
printf("-----\n");
printf("%f\n",teamoffense[3][home]);
printf("%f\n",teamdefense[3][away]);
printf("homeavg %f\n",homeaverage);
printf("awayavg2 %f\n",awayaverage);
return 0;
}