Jump to content

Balanced Schedule Request.


pgd44

Recommended Posts

I don't know if I should do this (or if anybody cares), but I'm almost done with the coding...but when I change

while(randomMonth == 200 || randomDay == 200 ||


teamOpponents[a][randomMonth][randomDay] != 100 ||


teamOpponents[b][randomMonth][randomDay] != 100)
to
while(randomMonth == 200 || randomDay == 200 ||


teamOpponents[a][randomMonth][randomDay] != 100 ||


teamOpponents[b][randomMonth][randomDay] != 100 ||


(randomMonth == 3 && randomMonth == 9))
, the program halts... By the way, I know that I am horrible at coding, but could someone tell me if there's like an infinite loop going on, or anything? My entire code:
#include <iostream>


#include <fstream>


#include <stdlib.h>


#include <time.h>


#include <string>




using namespace std;


using std::string;




/* This int-array keeps a running 30-team schedule of what teams one team will play on Month-Days(4-1, or 9-30] */


int teamOpponents[30][6][31];


int amountofGames[30][30];




int order[] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6}; // 12 5's, 17 6's


			// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8




int home[30][6][31];




// There are months 4 - 9 --- That gives total of 6 months


// ex. April 5 - teamOpponents[x][0][5]




// List of teams, organized into AL, NL, and divisions


string ALeast[] = {"Bal", "Bos", "NYY", "TB", "Tor"}; // 1, 2, 3, 4, 5


	// ALeast[0]="Bal"; // Baltimore Orioles


	// ALeast[1]="Bos"; // Boston Red Sox


	// ALeast[2]="NYY"; // New York Yankees


	// ALeast[3]="TB"; // Tampa Bay Devil Rays


	// ALeast[4]="Tor"; // Toronto Blue Jays




// 2 home + 2 away against each NL team (64)


// 3 home + 3 away vs. each AL East and AL West team (54)


// 2 AL central teams: 5 home, 6 away (22)


// 2 AL central teams: 6 home, 5 away (22)


string ALcentral[] = {"CWS", "Cle", "Det", "KC", "Min"}; // 6, 7, 8, 9, 10


	// ALcentral[0]="CWS"; // Chicago White Sox


	// ALcentral[1]="Cle"; // Cleveland Indians


	// ALcentral[2]="Det"; // Detroit Tigers


	// ALcentral[3]="KC"; // Kansas City Royals


	// ALcentral[4]="Min"; // Minnesota Twins


string ALwest[] = {"Ana", "Oak", "Sea", "Tex"}; // 11, 12, 13, 14


	// ALwest[0]="Ana"; // Los Angeles Angels of Anaheim


	// ALwest[1]="Oak"; // Oakland Athletics


	// ALwest[2]="Sea"; // Seattle Mariners


	// ALwest[3]="Tex"; // Texas Rangers




string NLeast[] = {"Atl", "Fla", "NYM", "Phi", "Was"}; // 15, 16, 17, 18, 19


	// NLeast[0]="Atl"; // Atlanta Braves


	// NLeast[1]="Fla"; // Florida Marlins


	// NLeast[2]="NYM"; // New York Mets


	// NLeast[3]="Phi"; // Philadelphia Phillies


	// NLeast[4]="Was"; // Washington Nationals


string NLcentral[] = {"ChC", "Cin", "Hou", "Mil", "Pit", "StL"}; // 20, 21, 22, 23, 24, 25


	// NLcentral[0]="ChC"; // Chicago Cubs


	// NLcentral[1]="Cin"; // Cincinnati Reds


	// NLcentral[2]="Hou"; // Houston Astros


	// NLcentral[3]="Mil"; // Milwaukee Brewers


	// NLcentral[4]="Pit"; // Pittsburgh Pirates


	// NLcentral[5]="StL"; // St. Louis Cardinals


string NLwest[] = {"Ari", "Col", "LA", "SD", "SF"}; // 26, 27, 28, 29, 30


	// NLwest[0]="Ari"; // Arizona Diamondbacks


	// NLwest[1]="Col"; // Colorado Rockies


	// NLwest[2]="LA"; // Los Angeles Dodgers


	// NLwest[3]="SD"; // San Diego Padres


	// NLwest[4]="SF"; // San Francisco Giants




string teams[] = {"Bal", "Bos", "NYY", "TB", "Tor", "CWS", "Cle", "Det", "KC", "Min", "Ana", "Oak", "Sea",


 "Tex", "Atl", "Fla", "NYM", "Phi", "Was", "ChC", "Cin", "Hou", "Mil", "Pit", "StL", "Ari", "Col", "LA", "SD", "SF"};




int daysInMonth(int month, int year)


{


	int m[] = {31,28,31,30,31,30,31,31,30,31,30,31};




	if (month != 2) return m[month - 1];


	if (year%4 != 0) return m[1];


	if (year%100 == 0 && year%400 != 0) return m[1] + 1;


}




int daysInYear(int year)


{


	int days = 0;	




	for(int i = 1; i <= 12; i++)


	{


		days += daysInMonth(i,year);


	}


	return days;


}




int daysBetweenDatesInclusive(int year1, int mon1, int day1, int year2, int mon2, int day2)


{


	int months = (mon2 - mon1) + ((year2 - year1) * 12);


	int year = year1;


	int month = mon1;


	int days = day2 - day1;




	for(int i = 0; i < months; i++)


	{


		days += daysInMonth(month, year);


		month++;




		if( month > 12 )


		{


			month = 1;


			year++;


		}


	}




	days++;




	return days;


}




//**************************************


//	 


// Name: Number of days between dates - 


//	 CORRECTLY!


// Description:There have been tons of d


//	 ate calculation functions that i've trie


//	 d and used, but they are never 100%. Mos


//	 t of them use the getTime() function whi


//	 ch can throw it off by a day. Here is a 


//	 100% accurate function.


// By: D Davis


//


//This code is copyrighted and has// limited warranties.Please see http://


//	 www.Planet-Source-Code.com/vb/scripts/Sh


//	 owCode.asp?txtCodeId=5517&lngWId=2//for details.//


//	 **************************************	 






void fillSchedule()


{


	/* This is made so that later, you can check if array number is null or not */




	int testing = 0;




	int countsix[30], leastsixcolumn[30];




	for(int a = 0; a < 30; a++)


	{


		countsix[a] = 0;


		for(int b = 0; b < 6; b++)


		{			


			for(int c = 0; c < 31; c++)


			{


				teamOpponents[a][b][c] = 100;


			}


		}


		for(int d = 0; d < 30; d++)


		{


			amountofGames[a][d] = 0;		


		}


	}








	int randomMonth, randomDay, random;


	int six, lowest;




	for(int a = 0; a < 30; a++)


	{				


		for(int m = 0; m < 30; m++)


		{


			countsix[m] = 0;


		}




		six = 17;


		lowest = 100;




		for(int b = (a+1); b < 30; b++)


		{


			if(a == 0)


			{


				amountofGames[a][b] = order[b-1];


				amountofGames[b][a] = order[b-1];


			}


		}




		// cout << "Six: ";




		if(a != 0)


		{


			for(int c = 0; c < 30; c++)


			{				


				if(amountofGames[a][c] == 6)


				{


					six--;


					// cout << six << "  ";


				}


			}




			for(int d = (a+1); d < 30; d++)


			{


				for(int e = 0; e < (a+1); e++)


				{


					if(amountofGames[e][d] == 6) countsix[d]++;


				}


				if(countsix[d] <= lowest)


				{


					lowest = countsix[d];


				}


			}




			for(int f = (a+1); f < 30; f++)


			{


				if(countsix[f] == lowest && six > 0)


				{


					amountofGames[a][f] = 6;


					amountofGames[f][a] = 6;




					six--;


				}else


				{


					amountofGames[a][f] = 5;


					amountofGames[f][a] = 5;	 


				}


			}			


		}




		for(int e = 0; e < 30; e++)


		{


			if(amountofGames[a][e] == 6) testing++;


		}




		if(testing != 17)


		{


			for(int fix = 0; fix < (17-testing); fix++)


			{


				tryagain:


				random = rand()%30;


				if(amountofGames[a][random] == 5)


				{


					amountofGames[a][random] = 6;


				}else goto tryagain;


			}		   


		}


		testing = 0;


		for(int e = 0; e < 30; e++)


		{


			cout << amountofGames[a][e] << " ";


			if(amountofGames[a][e] == 6) testing++;


		}




		cout << " --- " << testing << endl;


		testing = 0;


	}






	system("pause");




	// Testing




	for(int a = 0; a < 30; a++)


	{			   


		cout << "Team: " << teams[a] << endl;


		for(int b = 0; b < 30; b++)


		{


			if(a != b)


			{


				cout << teams[b] << " " << amountofGames[a][b] << ", ";


			}


		}


		cout << endl << endl;	


	}




	system("pause");




	// End Testing	




	for(int a = 0; a < 30; a++)


	{


		for(int b = (a+1); b < 30; b++)


		{


			for(int c = 0; c < amountofGames[a][b]; c++)


			{				


				do


				{


					randomMonth = rand()%6;


					randomDay = rand()%31;


				}


				while(teamOpponents[a][randomMonth][randomDay] != 100 || teamOpponents[b][randomMonth][randomDay] != 100 || (randomMonth == 3 && randomDay == 9));




				// Store Dates in Array			




				teamOpponents[a][randomMonth][randomDay] = b;


				teamOpponents[b][randomMonth][randomDay] = a;




				random = rand()%2;




				if (random == 0)


				{


					home[a][randomMonth][randomDay] = 1;


					home[b][randomMonth][randomDay] = 0;


				}else


				{


					home[a][randomMonth][randomDay] = 0;


					home[b][randomMonth][randomDay] = 1; 


				}


				// End Store Dates in Array


			}


		}


	}// End Scheduling


	system("pause");


}




void writetofile()


{


	// Test ----




	int testing = 0;




	for(int a = 0; a < 30; a++)


	{


		testing = 0;


		cout << teams[a] << ":n";


		for(int b = 0; b < 6; b++)


		{


			cout << "Month: " << (b+4) << endl;


			for(int c = 0; c < 31; c++)


			{


				if(teamOpponents[a][b][c] != 100){ cout << "Day " << c << ": " << teams[teamOpponents[a][b][c]] << endl; testing++; }


				else { cout << "Day " << (c+1) << ": !NO GAME!" << endl; }


			}


		}	


		cout << testing << "YAY!";	


	}




	system("pause");




	// End Test




	// Write to File


	/* ofstream myfile ("schedule.html");


	if (myfile.is_open())


	{


		myfile << "<table border="1">";


		myfile << "<tr>";


		myfile << "<td><p><strong>Date:</strong></p></td>";


		for(int a = 0; a < 7; a++)


		{


			for(int b = 0; b < 31; b++)


			{


				myfile << "<td><p><strong>" << (a+4) << "-" << (b+1) << "</strong></p></td>";


			}


		}


		myfile << "</tr>";




		int temp = 0;




		for(int a = 0; a < 30; a++)


		{


			temp = 0;


			myfile << "<tr>";


			myfile << "<td width="200"><p><strong>Team: " << teams[a] << "</strong></p></td>";


			for(int b = 0; b < 7; b++)


			{


				for(int c = 0; c < 31; c++)


				{	 


					if(teamOpponents[a][b][c] != 100)


					{


						myfile << "<td><p>" << teams[teamOpponents[a][b][c]] << " " << ++temp << "</p></td>";


					}else


					{


						myfile << "<td><p><strong>NA</strong></p></td>";


					}


				}


			}


			myfile << "</tr>";


		}




		myfile << "</table>";


		myfile.close();


	}


	else cout << "Unable to open file";


	*/


	// End Write to File




	int temp = 0;


	int randomnumber;




	ofstream myfile ("mlb162_1.dat");


	if (myfile.is_open())


	{


		myfile << "DATE,Time,Home,Road,Halfn";


		myfile << ",,,,n";


		for (int a = 0; a < 6; a++)


		{


			for(int b = 0; b < 31; b++)


			{


				for(int c = 0; c < 30; c++)


				{


					if(a == 3 && b == 9 && temp == 0)


					{


						myfile << "07/10/2007,20:05,NL,AL,-n";


						temp++;


					}


					if(teamOpponents[c][a][b] != 100)


					{


						if(a < 6) myfile << "0";




						myfile << (a+4) << "/";




						if(b < 9) myfile << "0";




						myfile << (b+1) << "/" << 2007 << ",";




						randomnumber = rand()%2;


						if(randomnumber == 0) myfile << "13:05";


						else myfile << "19:05";




						if(home[c][a][b] == 0) myfile << "," << teams[c] << "," << teams[teamOpponents[c][a][b]] << ",";


						if(home[c][a][b] == 1) myfile << "," << teams[teamOpponents[c][a][b]] << "," << teams[c] << ",";




						if(a == 0 || a == 1 || a == 2 || (a == 3 && b < 9)) myfile << "0";


						else if(a == 3 && b == 9) myfile << "-";


						else myfile << "1"; 




						myfile << "n";




						teamOpponents[teamOpponents[c][a][b]][a][b] = 100;


					}


				}


			}


		}




		myfile.close();


	}


	else cout << "Unable to open file";


}




int main()


{	


	fillSchedule();




	writetofile();




	return 0;   


}

Link to comment
Share on other sites

  • Replies 111
  • Created
  • Last Reply

I've gotta tell you dude. I know you used a D/L'd function here or there... but you've truly done a LOT of work and made a TON of progress. You learned a LOT in a very compressed time frame.

I am very impressed with what you've been able to do, starting from scratch.

I know people tell you that you ask a lot of questions - but you clearly use the answers you get to the very best of your ability.

Link to comment
Share on other sites

I've gotta tell you dude. I know you used a D/L'd function here or there... but you've truly done a LOT of work and made a TON of progress. You learned a LOT in a very compressed time frame.

I am very impressed with what you've been able to do, starting from scratch.

I know people tell you that you ask a lot of questions - but you clearly use the answers you get to the very best of your ability.

Thanks, and...

Well, the three functions that I downloaded in there --- I don't even use them...I just keep them in there just in case...

...so I basically wrote all of it from scratch.

But that one little bug is killing me!!!!! I can't stand the fact that I wasted so much time on this, and then it fails on one little thing...I'm still waiting for help from other C++ boards.

Link to comment
Share on other sites

I'll finish up my generator, and if I have some time, I'll work on possibly converting that schedule...

And anyway, how did you make the balanced schedule? Doesn't it take forever?

And by the way, your schedule has 189 days...

...Aren't there only 183 days between April 1 and September 30?

Correct me if I'm wrong.

Link to comment
Share on other sites

I'll finish up my generator, and if I have some time, I'll work on possibly converting that schedule...

And anyway, how did you make the balanced schedule? Doesn't it take forever?

And by the way, your schedule has 189 days...

...Aren't there only 183 days between April 1 and September 30?

Correct me if I'm wrong.

I actually set up a league in HH2003 where all teams played each other, saved it, exported the schedule with HHedit 2003, then I imported the schedule into HH2004 with the HHedit 2004. There is no need to convert the schedule I made for HH2004, I just thought that maybe it could help you in some way.

Thanks for all your efforts in trying to make a balanced schedule.

PGD44

Link to comment
Share on other sites

I actually set up a league in HH2003 where all teams played each other, saved it, exported the schedule with HHedit 2003, then I imported the schedule into HH2004 with the HHedit 2004. There is no need to convert the schedule I made for HH2004, I just thought that maybe it could help you in some way.

Thanks for all your efforts in trying to make a balanced schedule.

PGD44

no problem, I'll keep working on it when I get home. When I actually get something decent together, I'll release the generator...but it'll be in beta stages, and every few days I'll fix something.

Link to comment
Share on other sites

Yes! I'm done! (But there are some shortcomings...just as you play against each of the 29 teams 5/6 games in a row...)

Please post your suggestions on this thread, and I'll try to accommodate them...

My download's pending now...

Link to comment
Share on other sites

  • 4 weeks later...

K here is the deal!

I love this mod, i always wish i could play every team!

However, this mod only works in MVP 07 under certain conditions.

If you intsall MVP 07, when you start a dynasty, by default the dynasty will start in 2005!

I tested the mod, and the schedule generator works fine under default settings (i.e. dynasty that starts in 2005)

However, because i wanted my stats to work with MVPsavreader, i ran the 07 maker tool, which basically makes it so your dynasty starts in 2007.

Basically the problem is that when you run the "07 maker tool", and make it so that your dynasty starts in 2007, the schedule generator does not work.

So is there a way that you can make the schedule maker work with MVP 2007 after the "07 maker tool" has been ran!

Any help would be much appreciated!

thank!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...