Jump to content

Hockey Season problem


pugg09

Recommended Posts

Newbie Alert!!!

 

Sorry, but I'm really struggling with this project of mine.  I'm not have any problem storing the arrays, but what problem I'm having is that I always come up with the same order of games.  For example, from Game 1 to Game 10 all the teams play the same teams.  Can anyone help me?

 

 

 



	$theTeams = Array(13,12,8,7,4,2);

	$theTeamPointer = 2;
	$homeAway = "";

	$numGames = 10;

	$SEASON = Array();

	for($game = 0; $game<$numGames ; $game++){//game loop, create 12 home and away games for each team

	echo "<hr>Setting up Game #".$game;

			for($team = 0; $team < count($theTeams); $team++){//setting up each team's home and away game



				//SET UP THE HOME GAME FIRST----------------------------------------------------------------
				$homeAway = "home";
				echo "<BR><B>Setting up ".$homeAway." game ".$game." for Team #".$theTeams[$team]."</B>";
				//check to see if home game is set already
				if(is_int($SEASON[$game][$team][$homeAway]))
				{ echo "<BR>->Game #".$game." for team ".$theTeams[$team]." is set against team #".$SEASON[$game][$team][$homeAway]; }
				else
				{ echo "<BR>->Game #".$game." for team ".$theTeams[$team]." is empty."; 
				  //it's not set up yet, so find the first available team.
				  //make sure that the teamPointer is not pointing to the team we're setting a game up with
				  if($theTeams[$team] == $theTeams[$theTeamPointer]){
					echo "<BR>->Oops, ".$theTeams[$team]." is the same as ".$theTeams[$theTeamPointer].". Better increment.";
					//make sure that the team pointer isn't already at the end of the Team list, if it is, don't increment, set it back to 0
					if($theTeamPointer == count($theTeams)-1){
						//it's a the end reset it
						echo "<BR>-->Oops again, ".$theTeams[$theTeamPointer]." is at the end of my array, setting the index back to 0";
						$theTeamPointer = 0;
						}
					else {
						echo "<BR>-->Incrementing the pointer now from ".$theTeamPointer;
						$theTeamPointer++;
						echo " to ".$theTeamPointer;
						}
					}//end if($theTeams[$team] == $theTeams[$theTeamPointer])

				 //take this team and assign it as the Away team for this Home game
				 echo "<BR>Team #".$theTeams[$team]." will play against Team #".$theTeams[$theTeamPointer];


				 //SET THE GAME for the HOME team
				$SEASON[$game][$team][$homeAway] = $theTeams[$theTeamPointer];
				echo "<BR>Game #".$game." for Team #".$theTeams[$team]."has a ".$homeAway." game against Team #".$theTeams[$theTeamPointer];
				echo "<BR>This is the value of HOME the SEASON array: ".$game."-".$team."-".$homeAway."=".$SEASON[$game][$team][$homeAway];


				//SET THE GAME for the AWAY team

				//make sure that the away team doesn't already have a game set for that game#
				if(is_int($SEASON[$game][$theTeamPointer]["away"])){
					//a game for that game is set 
					echo "<BR>Game #".$game." is already taken for team ".$theTeams[$theTeamPointer];

					//loop to the end of the season, and find the next available game
					for($nextGame = ($game+1); $nextGame < $numGames; $nextGame++){
						echo "<BR>Checking to see if Game #".$nextGame." is available.";
						if(is_int($SEASON[$nextGame][$theTeamPointer]["away"])){
							echo "<BR>Game #".$nextGame." is full.";
							}
						else {
							echo "<BR>Game #".$nextGame." is available.";
							echo "<BR>Setting game....";
							echo "<BR>This is the value of AWAY the SEASON array:".$nextGame."-".$theTeamPointer."-"."away"." = ".$theTeams[$team];
							$SEASON[$nextGame][$theTeamPointer]["away"] = $theTeams[$team];

							if($theTeamPointer == count($theTeams)-1){ $theTeamPointer = 0; } else { $theTeamPointer++; }
							echo "<BR>Moving the team pointer to the next team in the array, which should be Team #";
				 			echo $theTeams[$theTeamPointer];
							$nextGame = $numGames;
							}
						}
					//$SEASON[$game][$theTeamPointer]["away"] = $theTeams[$team];
				}
				else
				{
					echo "<BR>This is the value of AWAY the SEASON array:".$game."-".$theTeamPointer."-"."away"." = ".$theTeams[$team];
					$SEASON[$game][$theTeamPointer]["away"] = $theTeams[$team];
				 	//this Away team has now been used, so move to the next team.
				 	if($theTeamPointer == count($theTeams)-1){ $theTeamPointer = 0; } else { $theTeamPointer++; }
				 	echo "<BR>Moving the team pointer to the next team in the array, which should be Team #";
				 	echo $theTeams[$theTeamPointer];
				 }
				}
				//--------------------------------------




				//SET UP THE AWAY GAME NEXT----------------------------------------------------------------
				$homeAway = "away";
				echo "<BR><B>Setting up ".$homeAway." game ".$game." for Team #".$theTeams[$team]."</B>";
				//check to see if home game is set already
				if(is_int($SEASON[$game][$team][$homeAway]))
				{ echo "<BR>->Game #".$game." for team ".$theTeams[$team]." is set against team #".$SEASON[$game][$team][$homeAway]; }
				else
				{ echo "<BR>->Game #".$game." for team ".$theTeams[$team]." is empty."; 
				  //it's not set up yet, so find the first available team.
				  //make sure that the teamPointer is not pointing to the team we're setting a game up with
				  if($theTeams[$team] == $theTeams[$theTeamPointer]){
					echo "<BR>->Oops, ".$theTeams[$team]." is the same as ".$theTeams[$theTeamPointer].". Better increment.";
					//make sure that the team pointer isn't already at the end of the Team list, if it is, don't increment, set it back to 0
					if($theTeamPointer == count($theTeams)-1){
						//it's a the end reset it
						echo "<BR>-->Oops again, ".$theTeams[$theTeamPointer]." is at the end of my array, setting the index back to 0";
						$theTeamPointer = 0;
						}
					else {
						echo "<BR>-->Incrementing the pointer now from ".$theTeamPointer;
						$theTeamPointer++;
						echo " to ".$theTeamPointer;
						}
					}//end if($theTeams[$team] == $theTeams[$theTeamPointer])

				 //take this team and assign it as the Away team for this Home game
				 echo "<BR>Team #".$theTeams[$team]." will play against Team #".$theTeams[$theTeamPointer];


				 //SET THE GAME for the AWAY team
				$SEASON[$game][$team][$homeAway] = $theTeams[$theTeamPointer];
				echo "<BR>Game #".$game." for Team #".$theTeams[$team]."has a ".$homeAway." game against Team #".$theTeams[$theTeamPointer];
				echo "<BR>This is the value of AWAY the SEASON array: ".$game."-".$team."-".$homeAway."=".$SEASON[$game][$team][$homeAway];


				//SET THE GAME for the HOME team

				//make sure that the away team doesn't already have a game set for that game#
				if(is_int($SEASON[$game][$theTeamPointer]["home"])){
					//a game for that game is set 
					echo "<BR>Game #".$game." is already taken for team ".$theTeams[$theTeamPointer];

					//loop to the end of the season, and find the next available game
					for($nextGame = ($game+1); $nextGame < $numGames; $nextGame++){
						echo "<BR>Checking to see if Game #".$nextGame." is available.";
						if(is_int($SEASON[$nextGame][$theTeamPointer]["home"])){
							echo "<BR>Game #".$nextGame." is full.";
							}
						else {
							echo "<BR>Game #".$nextGame." is available.";
							echo "<BR>Setting game....";
							echo "<BR>This is the value of HOME the SEASON array:".$nextGame."-".$theTeamPointer."-"."home"." = ".$theTeams[$team];
							$SEASON[$nextGame][$theTeamPointer]["home"] = $theTeams[$team];

							if($theTeamPointer == count($theTeams)-1){ $theTeamPointer = 0; } else { $theTeamPointer++; }
							echo "<BR>Moving the team pointer to the next team in the array, which should be Team #";
				 			echo $theTeams[$theTeamPointer];
							$nextGame = $numGames;
							}
						}
					//$SEASON[$game][$theTeamPointer]["away"] = $theTeams[$team];
				}
				else
				{
					echo "<BR>This is the value of HOME the SEASON array:".$game."-".$theTeamPointer."-"."home"." = ".$theTeams[$team];
					$SEASON[$game][$theTeamPointer]["home"] = $theTeams[$team];
				 	//this Away team has now been used, so move to the next team.
				 	if($theTeamPointer == count($theTeams)-1){ $theTeamPointer = 0; } else { $theTeamPointer++; }
				 	echo "<BR>Moving the team pointer to the next team in the array, which should be Team #";
				 	echo $theTeams[$theTeamPointer];
				 }
				}
				//--------------------------------------


			}//end for($j = 0; $j < count($theTeams); $j++)


		}//end for($i = 0; $i<11 ; $i++){



Link to comment
https://forums.phpfreaks.com/topic/120300-hockey-season-problem/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.