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

Feature(HERO) Add randomly selected standard AI to bots #26

Merged
merged 3 commits into from Oct 13, 2014
Merged

Feature(HERO) Add randomly selected standard AI to bots #26

merged 3 commits into from Oct 13, 2014

Conversation

ConstableBrew
Copy link
Contributor

Testing against real competition is much more useful than just all Blind Men. This branch adds Hero.prototype.move() and 'Hero.brains' to public/game_classes/Hero.js'. Whenmoveis called it randomly selects from the availableHero.brains` and uses that brain for all decisions for the duration of the current game.

@ConstableBrew
Copy link
Contributor Author

Note: I have been unable to configure my pc to run javascript-battle-testing-website in any form. I've done my best to validate my code, but I still haven't been able to actually run it.

@forrestbthomas
Copy link
Contributor

Thanks so much for the contribution! Looking through the code, everything looks good, but I think that public/js/game/Game.js still needs to be changed to make this all come together. So, if you can make some changes there incorporating what you have already done, we can take a look then and see if it works.
As far as the site not running, that's interesting. A couple thoughts:
Did you install all of the dependencies?
Did you run node server.js to start up the server that serves the static files?

@ConstableBrew
Copy link
Contributor Author

I'm a bit confused about what you are asking to have changed.

public/game_classes/Hero.js

119    Hero.prototype.move = function(gameData, helpers) {
120        // Select a random brain for this hero
121        var brains = Object.keys(Hero.brains);
122        this.move = Hero.brains[brains[ brains.length * Math.random() << 0 ]];
123        return this.move(gameData, helpers);
124    };

This is the move function. It is a lazy loader that will choose a random brain the first time it is called and then replace this.move with the selected brain. Then all future calls for that bot's move will simply grab the brain function directly.

public/js/game/Game.js

79          var botsFunction = gameData.activeHero.move;
80          var botsMove = botsFunction(gameData, helpers);
81          handleHeroTurn.call(gameData, botsMove);
82          this.clientSideGame[turnKeeper] = JSON.parse(JSON.stringify(gameData));

This is the modified bit in Game.js. Here the bot's move function is being passed gameData and helpers and gets back the direction to move.

I haven't been able to get bower to install and npm install gives me a bunch of errors that my google-foo hasn't been able to resolve just yet. Here is what npm install gives:

C:\github\javascript-battle-testing-website [feat/GiveBrainsToMooks]> npm install
npm http GET https://registry.npmjs.org/body-parser
npm http GET https://registry.npmjs.org/browserify
npm http GET https://registry.npmjs.org/mongoose
npm http GET https://registry.npmjs.org/express-session
npm http GET https://registry.npmjs.org/grunt-blanket/0.0.8
npm http GET https://registry.npmjs.org/chai
npm http GET https://registry.npmjs.org/grunt-contrib-cssmin
npm http GET https://registry.npmjs.org/grunt-nodemon
npm http GET https://registry.npmjs.org/grunt-contrib-concat
npm http GET https://registry.npmjs.org/q
npm http GET https://registry.npmjs.org/grunt-contrib-clean
npm http GET https://registry.npmjs.org/grunt-mocha-test
npm http GET https://registry.npmjs.org/supertest
npm http GET https://registry.npmjs.org/grunt
npm http GET https://registry.npmjs.org/passport
npm http GET https://registry.npmjs.org/grunt-contrib-watch
npm http GET https://registry.npmjs.org/grunt-contrib-uglify
npm http GET https://registry.npmjs.org/grunt-contrib-sass
npm http GET https://registry.npmjs.org/mocha
npm http GET https://registry.npmjs.org/passport-github
npm http GET https://registry.npmjs.org/grunt-contrib-jshint
npm http GET https://registry.npmjs.org/blanket
npm http GET https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/mongodb
npm http GET https://registry.npmjs.org/grunt-browserify
npm http 304 https://registry.npmjs.org/mongoose
npm http 304 https://registry.npmjs.org/body-parser
npm http 304 https://registry.npmjs.org/chai
npm http 304 https://registry.npmjs.org/express-session
npm ERR! Error: No compatible version found: body-parser@'^1.6.2'
npm ERR! Valid install targets:
npm ERR! ["1.0.0","1.0.1","1.0.2","1.1.0","1.1.1","1.1.2","1.2.0","1.2.1","1.2.2","1.3.0","1.3.1","1.4.0","1.4.1","1.4.2
","1.4.3","1.5.0","1.5.1","1.5.2","1.6.0","1.6.1","1.6.2","1.6.3","1.6.4","1.6.5","1.6.6","1.6.7","1.7.0","1.8.0","1.8.1
","1.8.2","1.8.3","1.8.4","1.9.0"]
npm ERR!     at installTargetsError (C:\Program Files\nodejs\node_modules\npm\lib\cache.js:685:10)
npm ERR!     at C:\Program Files\nodejs\node_modules\npm\lib\cache.js:607:10
npm ERR!     at saved (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-registry-client\lib\get.js:138:7)
npm ERR!     at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"
 "install"
npm ERR! cwd C:\github\javascript-battle-testing-website
npm ERR! node -v v0.10.4
npm ERR! npm -v 1.2.18
npm http 304 https://registry.npmjs.org/grunt-contrib-concat
npm http 304 https://registry.npmjs.org/grunt-nodemon
npm http 304 https://registry.npmjs.org/q
npm http 304 https://registry.npmjs.org/grunt-contrib-clean
npm http 304 https://registry.npmjs.org/browserify
npm http 200 https://registry.npmjs.org/grunt
npm http 304 https://registry.npmjs.org/grunt-mocha-test
npm http 304 https://registry.npmjs.org/grunt-contrib-watch
npm http 304 https://registry.npmjs.org/grunt-contrib-uglify
npm http 304 https://registry.npmjs.org/supertest
npm http 304 https://registry.npmjs.org/grunt-contrib-cssmin
npm http 304 https://registry.npmjs.org/passport
npm http 304 https://registry.npmjs.org/grunt-blanket/0.0.8
npm http 200 https://registry.npmjs.org/grunt-contrib-jshint
npm http 304 https://registry.npmjs.org/grunt-contrib-sass
npm http 304 https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/mongodb
npm http 200 https://registry.npmjs.org/mocha
npm http 304 https://registry.npmjs.org/grunt-browserify
npm http 304 https://registry.npmjs.org/passport-github
npm http 304 https://registry.npmjs.org/blanket
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     C:\github\javascript-battle-testing-website\npm-debug.log
npm ERR! not ok code 0
C:\github\javascript-battle-testing-website [feat/GiveBrainsToMooks]>

Installing bower gives many pages worth of similar errors. I am on Win 8.1. If you have any ideas on how to resolve this, please let me know!

@Yahkob
Copy link
Contributor

Yahkob commented Oct 13, 2014

There seems to be some helpful solutions here, npm/npm#3664

@ConstableBrew
Copy link
Contributor Author

🤦 My version of NPM was pretty old. I updated it and life is better.

@ConstableBrew
Copy link
Contributor Author

Everything checks out. I might suggest a future enhancement of changing the bot names from "Random" to the selected brain.

@forrestbthomas
Copy link
Contributor

DOH!
Ok, so my turn for a facepalm. I was viewing the whole Hero.js file and didn't check the Game.js file. Everything does look good, and I noticed too that I need to remove two hero types from the Hero.js file: Health Nut and Aggressor - they were replaced by the Coward and the Assassins.
Would you like to remove those types and we can include those changes in this merge? If not, I can just merge this and make the change after.

@ConstableBrew
Copy link
Contributor Author

They are removed now.

@forrestbthomas
Copy link
Contributor

Awesome. Thank you!

forrestbthomas added a commit that referenced this pull request Oct 13, 2014
Feature(HERO) Add randomly selected standard AI to bots
@forrestbthomas forrestbthomas merged commit dce3b7b into JavascriptBattle:master Oct 13, 2014
@ConstableBrew ConstableBrew deleted the feat/GiveBrainsToMooks branch October 13, 2014 22:11
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

Successfully merging this pull request may close these issues.

None yet

3 participants