Guest User

Untitled

a guest
Oct 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. class GameSimulatorHelper extends Model
  2. {
  3. public function run()
  4. {
  5. // Get all the games from the database.
  6. $games = Game::all();
  7.  
  8. // Simulate each game.
  9. foreach ($games as $g) {
  10. $sim = new GameSimulator();
  11. $sim->run($g);
  12. unset($sim);
  13. }
  14. }
  15. }
  16.  
  17. class GameSimulator extends Model
  18. {
  19. public $homeGoals = 0;
  20. public $awayGoals = 0;
  21. // A bunch of other class variables here.
  22.  
  23. public function run($game)
  24. {
  25. $this->simulate($game);
  26. // This function just resets all the class variables for the next game to be simulated.
  27. $this->resetSimulator();
  28. echo 'MEMORY USAGE: '.memory_get_usage(true) . "n";
  29. }
  30.  
  31. public function simulate()
  32. {
  33. $maxPeriods = 3;
  34. for ($p=1; $p <= $maxPeriods; $p++) {
  35. for ($i=1; $i <= 1200; $i++) {
  36. // Do many things here like get and set data in database.
  37. }
  38. }
  39. }
  40. // Many other functions below.
  41. }
Add Comment
Please, Sign In to add comment