(SOLVED) Random Fixture (Loop problem) HELP!!!

Started by alexhans, Thu 26/04/2007 17:30:26

Previous topic - Next topic

alexhans

   Well I tried to make Random Fixture with 20 teams like any common league... There should be 10 matches per Week and 19 total weeks because every team plays only once with each team (I dont care about being local, yet).  I made this script and I have problems with the 15001 loop error.  Its not a matter of noloopcheck, there is a problem with logic.
  If I put less teams, say 4 teams, 2 matches per week, 3 weeks.  There is no problem, but if I increase the number of teams (6,8,10,12, etc) maybe they hang up with the loop problem.  That makes me think there is a problem with the random or with the way I wrote it. 
  Right now I just cant figure it out, Id appreciate any help.

Code: ags

// Script header for module 'soc'
int g, a, b;
String sg;
int aeamnumber = 5;                       // this would be the number of teams in this case 6  
int aatches = 2;                               // Number of matches played per week in this case 3
struct eams {
  String Name;
	int EconSitu;
	int played[20];
  int MediaAttack;
	int MediaDefensa;
	String Manager;
	int FechaMatch;
	String Stadium;
};
	
eams team[20];

int FechaLeague;

struct eague {
  String Match[10];
  int match[10];
  };
  
eague league[20];

function nineteenrandom () {		// I dont use it, but i could and it would be the same

  int f;
  if (f > 19) { 
  f = 0;
	}
f++;
}

function whilee (int teamnumber, int matches) {									// this is where the problems start, in this while that I transformed into an independent function trying to solve them but the problems remain.  THIS IS THE LINE WHERE THE LOOP CROSSES THE 15001.

			while((team[a].played[b] > 0) || (team[b].FechaMatch > FechaLeague) || (a == b)) {							// did they play against each other?,  Has "b" Played this week?, and if "a" equals "b"

				g++;
			//	if(g > 100) { Display("%d", g); }
				b++;
				if (b > teamnumber) { 
				b = 0;
			//	Display("did they play against each other?: %d match %d Week %d", team[b].played[a], team[b].FechaMatch, FechaLeague);
				}
			}
  }

function /*noloopcheck*/ dostuff (int teamnumber, int matches) { // teamnumber 19, matches 9

  a = Random(teamnumber);
  b = Random(teamnumber);
  int c, d = 0;
  int f;
File *output = File.Open("stats.txt", eFileWrite);
  while(FechaLeague < teamnumber) {										// If all matches are played

		while(c <= matches) {															// if last match of the week is played
			while(team[a].FechaMatch > FechaLeague) {	// if "a" played this week
				a = Random(teamnumber);
				}
			}
	whilee (teamnumber, matches);
/*			while((team[a].played[b] > 0) || (team[b].FechaMatch > FechaLeague) || (a == b)) {							// if they played against each other,  if "b" played this week, and if "a" equals "b"
				g++;
			//	if(g > 100) { Display("%d", g); }
				b++;
				if (b > teamnumber) { 
				b = 0;
			//	Display("did they play against each other: %d Fechamatch(match) %d FechaLeague(week) %d", team[b].played[a], team[b].FechaMatch, FechaLeague);
				}
			}*/
			team[a].played[b]++;											// writes that they play against each other
			team[b].played[a]++;											// ditto									
			team[a].FechaMatch++;											// writes that it played this week 
			team[b].FechaMatch++;											// ditto
		//	Display("Fecha(week) %d Partido(match) %d %s Vs %s", d, c, team[a].Name, team[b].Name);
			

//output.WriteInt(a);
//output.WriteInt(b);
output.WriteString(team[a].Name);
output.WriteString(" Vs ");
output.WriteRawLine(team[b].Name);


		
			league[d].match[c] = 1;
			//league[d].Match[c] = "a Vs b";			
			c++;
		}
		output.WriteRawLine("Fecha");
		d++;																			// new week
		FechaLeague = d;													// ditto
		c = 0;																		// Match 0
	}
output.Close();
}      
		
		
	
      

// Script header for module 'list'
/*struct eams {
  String Name;
	int EconSitu;
	int played[19];
  int MediaAttack;
	int MediaDefensa;
	String Manager;
	int FechaMatch;
	String Stadium;
};*/

function maketeams () {				// In case you wonder this are Argentinian games (Best League of the world!!) ;)				
team[0].Name = "Argentinos";
team[1].Name = "Arsenal";
team[2].Name = "Banfield";
team[3].Name = "Belgrano";
team[4].Name = "Boca";
team[5].Name = "Colon";
team[6].Name = "Estudiantes";
team[7].Name = "Gimnasia de Jujuy";
team[8].Name = "Gimnasia de la Plata";
team[9].Name = "Godoy Cruz";
team[10].Name = "Independiente";
team[11].Name = "Lanus";
team[12].Name = "Newells";
team[13].Name = "Nueva Chicago";
team[14].Name = "Quilmes";
team[15].Name = "Racing";
team[16].Name = "River";
team[17].Name = "Rosario Central";
team[18].Name = "San Lorenzo";
team[19].Name = "Velez";

}


$$$!$$$ MS 1 -320440618
// Main script for module 'list'


  


  I hope its not to hard to understand, I believe the problem relays in some logic error in the while I Extruded as an independent function.
             
                                   
                                                 Alexhans

mmmmm... is someone there?... hellooo...
Never let your sense of morals prevent you from doing what is right.

Pumaman

It's a lot of code to look through, and there are various ways it could get stuck ... sorry, I don't have the time to debug it right now.

alexhans

Hi... Im not sure that anybody has read this topic or the code but just to clear things out if someone has looked at it.
            I want to tell you that I found that the problem was that the way it was being created, it went through loops imposing conditions that sometimes could not be fullfilled and it crashed because not all the combinations that were randomly created where possible.
            After investigating what mathematical models were used in real fixtures (like NBA, NFL, Argentine and Chilean Football, that have a lot more restrictions than mine)  I decided to use a simple Model and swap positions at random so that althoug slots are the same the fixture is practically random.

              A    B            then         A   C              and so on
              C    D                            E   B
              E    F                             F   D

Then... All thats left is to randomly choose a slot for each team and you can even swap the fixture of each week so as to make it even more random.

Ive coded a kind of Argentine league in wich the teams play matches taking into consderation two variables and there's a Table with points and Average that makes out wich team is relegated each season.  Its pretty fussy because I made it just for fun and testing and maybe to stick in some game in the future.

  If anyone is interested in the code just ask...


                                                          Alexhans
                                           


           
Never let your sense of morals prevent you from doing what is right.

Pumaman


SMF spam blocked by CleanTalk