Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The first game is ignored! #55

Open
himahuja opened this issue Jul 9, 2017 · 2 comments
Open

The first game is ignored! #55

himahuja opened this issue Jul 9, 2017 · 2 comments

Comments

@himahuja
Copy link

himahuja commented Jul 9, 2017

The first game of the first generation is ignored. From the second game the program starts evaluating the fitness of the genomes. Also, from the second game, the dinosaur can't keep 'DOWN' when the down is kept pressed, i.e. the input taken becomes slow. Any leads on where could possible changes be made on the code?

@himahuja
Copy link
Author

himahuja commented Jul 9, 2017

I think I know the reason why.


var _startKeyInterval; //will automatically init to zero
GameManipulator.startNewGame = function (next) {

  // Refresh state
  GameManipulator.readGameState();

  // If game is already over, press space
  if (GameManipulator.gamestate == 'OVER') {
    clearInterval(_startKeyInterval);

    // Set start callback
    GameManipulator.onGameStart = function (argument) {
      clearInterval(_startKeyInterval);
      next && next();
    };

    // Press space to begin game (repetidelly)
    _startKeyInterval = setInterval(function (){
      // Due to dino slowly gliding over the screen after multiple restarts, 
      //its better to just reload the page
      GameManipulator.reloadPage();
      setTimeout(function() {
        // Once reloaded we wait 0.5sec for it to let us start the game with a space.
          robot.keyTap(' ');
      }, 500);
    }, 300);

    // Refresh state
    GameManipulator.readGameState();

  } else {
    // Wait die, and call recursive action
    GameManipulator.onGameEnd = function () {
      GameManipulator.startNewGame(next);
    }
  }
}

Before the first game, the gameState = 'PLAYING', hence the if selection flow is skipped, the GamemManipulator then waits to start the next game, from whereon the if will always read true per game and the next() callback will be initiated.

@himahuja
Copy link
Author

himahuja commented Jul 9, 2017

I still am trying to find why the dinosaur can't keep down. (from the second game onwards)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant