我在学习javascript。作为这一努力的一部分,我写了一个基本的极小极大AI。我有以下几种方法:JavaScript方法不明确
Computer.prototype.expand = function(node) {
/* adds all state action pairs to the node.successors array */
};
Computer.prototype.getMove = function(boardAr) {
console.log("getMove");
var b2 = boardAr.slice();
var i;
var action;
this.root = new TNode(b2, this.mark);
this.root.AIPlayedLast = false;
this.expand(this.root);
this.root.successors.forEach(this.minVal);
action = maxNode(root.successors);
this.draw(action);
registerMove(action, this.mark);
};
Computer.prototype.minVal = function(node) {
if (node.isTerminal) {
return;
} else {
this.expand(node);
node.successors.forEach(maxVal);
node.utility = this.minNode(node.successors).utility;
}
};
当getMove
方法被调用的后续调用expand
去预期。但是,从minVal
方法调用expand
时,我得到:Uncaught TypeError: undefined is not a function
。我完全被这个困惑了。任何帮助/建议将不胜感激。
不知道,但据我所知,你应该以一个分号结束每一个功能,所以之后的每个}你应该增加; - 编辑:测试过,但不会有太大变化,只有几个语法错误会消失 – briosheje 2014-09-30 08:47:07
乍一看,这看起来很好(尽管如果你正在编写很多这种类型的代码,你可能想看看组合构造函数它提供了一个更加整洁的书写方式 - http://javascriptissexy.com/oop-in-javascript-what-you-need-to-know/),所以问题可能出现在代码被调用的方式中? – glenatron 2014-09-30 08:50:45
你可以请创建一个小提琴来重现这个问题吗? – thefourtheye 2014-09-30 08:51:45