Skip to content

Commit

Permalink
fix a score bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl Yogi authored and Karl Yogi committed Aug 11, 2016
1 parent 2d09028 commit 7885c7e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
function yourAI() {
//***** start your AI code inside ******//
console.log(board.getStatus());
// Demo right now
// Random Demo
while(board.currPlayer == board.selectedPlayer)
{
var index = Math.floor(Math.random()*9)+1;
Expand Down
39 changes: 39 additions & 0 deletions ml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

var ml = {
"updateConstant": 0.4,
"hypothesis": [0.5,0.5,0.5,0.5,0.5,0.5],
chooseMove: function() {

},
getTrainingExamples: function(history){

},
getHistory: function() {

},
getRows: function(board) {

},
getColumns: function(board) {

},
getDiagonals: function(board) {

},
getPossibilities: function(board) {
var possibilities = [];

},
getFeatures: function( board) {

},
evaluateBoard: function(board) {
x1,x2,x3,x4,x5,x6 = ml.getFeatures(board);
w0,w1,w2,w3,w4,w5,w6 = ml.hypothesis;
return w0 + w1*x1 + w2*x2 + w3*x3 + w4*x4 + w5*x5 + w6*x6
},
updateWeights: function(history, trainingExamples) {

}

}
8 changes: 7 additions & 1 deletion ttt.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@
},
};

// opposite player
function notPlayer(player) {
return player !== 'x' ? 'o' : 'x';
return player !== 'o' ? 'o' : 'x';
}

function handlePress(id, event) {
Expand Down Expand Up @@ -178,12 +179,17 @@ function score(play, player) {
count(play.b, counts);
count(play.c, counts);

// this winning case not gonna work
if(counts.total === 3) {
return -1;
}

// stop the opposite from winning
if(counts[notPlayer(player)] == 2) {
return 7;
}

// winning position
if(counts[player] == 2) {
return 6;
}
Expand Down

0 comments on commit 7885c7e

Please sign in to comment.