//===============================================
//   Filename:  teamClass.cpp
//   By:        Roger Z. Rios Mercado
//   Date:      SP/94
//===============================================

#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#include "teamClass.hpp"


////////////////////////////////////////
//     Class team: constructor
////////////////////////////////////////  
team::team(char* s, int gr, int g2, int f2, int a2, int pts2,
           int g1, int f1, int a1, int pts1,
           int h_w, int h_d, int h_l, int h_f, int h_a,
	   int a_w, int a_d, int a_l, int a_f, int a_a) {
     
     //
     //  Create team name.
     //
     name = new char [strlen(s) + 1];
     assert(name);
     strcpy(name, s);

     group = gr;
     g_2 = g2;  f_2 = f2;  a_2 = a2;  pts_2 = pts2;
     g_1 = g1;  f_1 = f1;  a_1 = a1;  pts_1 = pts1;
     hw = h_w;  hd = h_d;  hl = h_l;  hf = h_f;  ha = h_a;
     aw = a_w;  ad = a_d;  al = a_l;  af = a_f;  aa = a_a;

     //
     //  Compute home fields.
     //
     hg = hw + hd + hl;
     hdif = hf - ha;
     hpts = PTS_PER_WIN * hw + hd;

     //
     //   Compute away fields.
     //
     ag = aw + ad + al;
     adif = af - aa;
     apts = PTS_PER_WIN * aw + ad;

     //
     //   Update current statistics.
     //
     g = hg + ag;
     w = hw + aw;
     d = hd + ad;
     l = hl + al;
     f = hf + af;
     a = ha + aa;
     dif = f - a;
     pts = hpts + apts;

     //
     //   Compute relegation fields.
     //   (2 pts per victory)
     g_t = g_2 + g_1 + g;
     //pts_t = pts_2 + pts_1 + pts;
     pts_t = (pts_2 + pts_1) + PTS_PER_WIN_HELL * w + d;

     if (g_t != 0) {
	  ptge = (double) pts_t / (double) g_t;
	  f_avg = (double) (f_2 + f_1 + f) / (double) g_t;
	  dif_avg = (double) (f_2 + f_1 - a_2 - a_1 + dif) / (double) g_t;
     } else {
	  ptge = 0.0;
	  f_avg = 0.0;
	  dif_avg = 0.0;
     }

     //
     //  Parameters not computed.
     //
     mn = 0;
     best_ptge = 0.0;

}     // End of constructor.

////////////////////////////////////////////////
//   Destructor.
////////////////////////////////////////////////
team::~team() {

     //delete [] name; use in UNX
     delete name;
     name = NULL;
}


