/**
  * Simulates the specified match by the number of specified minutes.
  * 
  * @param SimulationMatch $match match to simulate.
  * @param int $minutes number of minutes to simuate.
  */
 public function simulateMatch(SimulationMatch $match, $minutes)
 {
     if ($match->minute == null) {
         $match->minute = 0;
     }
     // start the match
     if ($match->minute == 0) {
         foreach ($this->_observers as $observer) {
             $observer->onBeforeMatchStarts($match);
         }
     }
     // match might be completed already before simulation, e.g. when there is no formation provided
     if ($match->isCompleted) {
         $this->completeMatch($match);
         return;
     }
     // complete match if team has no players
     if (!$this->_hasPlayers($match->homeTeam) || !$this->_hasPlayers($match->guestTeam)) {
         $this->completeMatch($match);
         return;
     }
     for ($simMinute = 1; $simMinute <= $minutes; $simMinute++) {
         $match->minute = $match->minute + 1;
         if ($match->minute == 1) {
             $this->_simStrategy->kickoff($match);
         } else {
             SimulationHelper::checkAndExecuteSubstitutions($match, $match->homeTeam, $this->_observers);
             SimulationHelper::checkAndExecuteSubstitutions($match, $match->guestTeam, $this->_observers);
         }
         // execute next action
         $actionName = $this->_simStrategy->nextAction($match);
         $this->_simStrategy->{$actionName}($match);
         // increase minutes played
         $this->_increaseMinutesPlayed($match->homeTeam);
         $this->_increaseMinutesPlayed($match->guestTeam);
         // match ended?
         // two possibilities:
         // a. Normal matches end after regular time
         // b. if penalty shooting is enabled, play extension if there is no result after 90 minutes
         $lastMinute = 90 + SimulationHelper::getMagicNumber(1, 5);
         if ($match->penaltyShootingEnabled || $match->type == 'Pokalspiel') {
             // match ended after regular or extension time with a winner
             if (($match->minute == 91 || $match->minute == 121) && ($match->type != 'Pokalspiel' && $match->homeTeam->getGoals() != $match->guestTeam->getGoals() || $match->type == 'Pokalspiel' && !SimulationCupMatchHelper::checkIfExtensionIsRequired($this->_websoccer, $this->_db, $match))) {
                 $this->completeMatch($match);
                 break;
                 // no winner after extension time -> penalty shooting
             } elseif ($match->minute == 121 && ($match->type != 'Pokalspiel' && $match->homeTeam->getGoals() == $match->guestTeam->getGoals() || $match->type == 'Pokalspiel' && SimulationCupMatchHelper::checkIfExtensionIsRequired($this->_websoccer, $this->_db, $match))) {
                 $this->_simStrategy->penaltyShooting($match);
                 // we have a winner now
                 if ($match->type == 'Pokalspiel') {
                     // home team won
                     if ($match->homeTeam->getGoals() > $match->guestTeam->getGoals()) {
                         SimulationCupMatchHelper::createNextRoundMatchAndPayAwards($this->_websoccer, $this->_db, $match->homeTeam->id, $match->guestTeam->id, $match->cupName, $match->cupRoundName);
                         // guest team won
                     } else {
                         SimulationCupMatchHelper::createNextRoundMatchAndPayAwards($this->_websoccer, $this->_db, $match->guestTeam->id, $match->homeTeam->id, $match->cupName, $match->cupRoundName);
                     }
                 }
                 $this->completeMatch($match);
                 break;
             }
             // regular match
         } elseif ($match->minute >= $lastMinute) {
             $this->completeMatch($match);
             break;
         }
     }
 }