-
Notifications
You must be signed in to change notification settings - Fork 0
Ai #106
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
Open
ghost
wants to merge
17
commits into
master
Choose a base branch
from
ai
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ai #106
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
72f2937
adding skeleton for AI elements
kc-beard 150d542
Merge branch 'master' into ai
kc-beard 6f17892
first commit w/ ai components. jenky fixes to errors i was getting, s…
kc-beard b6bfd77
functioning AI
kc-beard c6a49ea
adding css back in
kc-beard 8ea9da5
commenting rather than deleting stylesheets requirement
kc-beard 22c9f25
removing enableAI flag
kc-beard 5089d8f
fixing css indent
kc-beard 95ac50e
refactoring, cr changes
kc-beard 4c5b903
improving ai, refactoring
kc-beard fc37ac5
basic ai tutorial
kc-beard 62b4fee
adding advanced section
kc-beard ce4d9a9
Merge branch 'master' into ai
kc-beard 959539a
child.subscribe still not working for me - adding error handling
kc-beard 27ee68c
bug fixes
kc-beard 0dbc656
cr changes
kc-beard 39e5fdb
Merge branch 'master' into ai
kc-beard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| var inherits = require('util').inherits; | ||
| var Player = require("./Player.js"); | ||
| var Gridboard = require("./grid_board.js"); | ||
| var c = require("./ttConstants"); | ||
|
|
||
| /** | ||
| * AI Player | ||
| * @constructor | ||
| * @extends {Player} | ||
| * @param {string} difficulty - difficulty of AI. Should be one of the values of TableTop.Constants.validAIDifficulties. | ||
| */ | ||
|
|
||
| function AIPlayer(name, color, id, difficulty) { | ||
| Player.call(this, name, color, id); | ||
|
|
||
| // safety check | ||
| if (c.validAIDifficulties.indexOf(difficulty) == -1) | ||
| difficulty = c.AIDifficultyEasy; | ||
|
|
||
| this.difficulty = difficulty; | ||
| } | ||
|
|
||
| inherits(AIPlayer, Player); | ||
|
|
||
|
|
||
| AIPlayer.prototype.isAI = function() { | ||
| return true; | ||
| }; | ||
|
|
||
|
|
||
| AIPlayer.prototype.generateMove = function(game) { | ||
|
|
||
| var moves = game.getValidMoves(); | ||
| var results = []; | ||
|
|
||
| moves.forEach(function(move) { | ||
|
|
||
| var gameCopy = game.copyGameStatus(game); | ||
| gameCopy.proposedMove = game.copyMoveForGame(move, gameCopy); | ||
| gameCopy.executeMove(); | ||
| results.push({ | ||
| move: move, | ||
| score: gameCopy.scoreBoard() | ||
| }); | ||
| }); | ||
|
|
||
| var result = this.pickMove(results); | ||
| return result.move; | ||
| }; | ||
|
|
||
| AIPlayer.prototype.pickMove = function(results) { | ||
|
|
||
| // sort descending based on score | ||
| var resultsSorted = results.sort(function(a, b) { | ||
| return b.score - a.score; | ||
| }); | ||
|
|
||
| var range; | ||
| if (this.difficulty == c.AIDifficultyHard) { | ||
| range = 1; | ||
| } else if (this.difficulty == c.AIDifficultyMedium) { | ||
| range = Math.min(results.length, 3); | ||
| } else if (this.difficulty == c.AIDifficultyEasy) { | ||
| range = Math.min(results.length, 5); | ||
| } | ||
|
|
||
| return resultsSorted[Math.floor(Math.random()*range)]; | ||
| }; | ||
|
|
||
| module.exports = AIPlayer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrewjmeier I still can't run webpack with this line not commented. I didn't want to uncomment and merge when i haven't tested it, so wasn't sure what to do with this line