Created
May 29, 2014 07:24
-
-
Save sharikovvladislav/50fcd3510192ca51b052 to your computer and use it in GitHub Desktop.
This file contains 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
function alphabeta(node, depth, alpha, beta, isMax, g) { | |
g.nodes[node.name].shape.items['0'].attr('fill', 'green'); | |
if((depth == 0) || (node.isTerminal == true)) { | |
return node.value; | |
} | |
if(isMax) { | |
console.log('maximizing'); | |
for (var i in node.children) { | |
var child = node.children[i]; | |
console.log(g.nodes[child.name]); | |
alpha = Math.max(alpha, alphabeta(child, depth-1, alpha, beta, false, g)); | |
if(beta <= alpha) { | |
console.log('beta '+beta+' alpha '+alpha); | |
break; | |
} | |
} | |
g.nodes[node.name].shape.items['1'].attr('text', alpha); | |
return alpha; | |
} else { | |
console.log('minimizing'); | |
for (var i in node.children) { | |
var child = node.children[i]; | |
console.log(g.nodes[child.name]); | |
beta = Math.min(beta, alphabeta(child, depth-1, alpha, beta, true, g)); | |
if (beta <= alpha) { | |
console.log('beta '+beta+' alpha '+alpha); | |
break; | |
} | |
} | |
g.nodes[node.name].shape.items['1'].attr('text', beta); | |
return beta; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment