我想创建一个网络应用程序,在那里你可以玩一个UCI-切斯引擎。我找到了https://github.com/imor/uci,它在命令行上运行得很好。因此,我“只”需要一个websocket来评估移动。
但我无法让它运转..。我尝试过(基于uci-示例):
io.sockets.on('connection',function(socket){
socket.on('start', function(data) {
var uci = new UCI();
var game = new Chess();
uci.on('ready', function () {
//Start a new 10 minute game with engine as black, use the first found
//engine and the first found polyglot book
uci.startNewGame(uci.getAvailableEngines()[0], 'black', 10,
uci.getAvailableBooks()[0]);
}).on('newgame', function () {
console.log("A new 10 minute game has started.");
console.log("Enter your moves in algebraic notation. E.g. e2e4<Enter>");
console.log(game.ascii());
}).on('moved', function (move) {
game.move(move);
console.log(move.from + move.to + (move.promotion ? move.promotion : ''));
console.log(game.ascii());
}).on('error', function (message) {
console.log('Error:' + message);
}).on('exit', function (message) {
console.log('Exiting:' + message);
}).on('gameends', function (result, reason) {
console.log('Game ends with result ' + result + ' because ' + reason);
uci.shutdown();
process.exit();
});
})
socket.on('m',function(data){
uci.move(data.move);
});
});开始游戏是有效的:socket.emit(‘开始’,{‘bar’:‘foo’}),但是当我尝试使用socket.emit(‘m’:‘e2e4’)时,它不知道uci.move
没关系,因为它是在socket.on(“开始”)中定义的.所以他不知道,但我不能让它运行。我尝试过一些愚蠢的想法,比如把socket.on('m')放入socket.on(‘start’).
有人能帮我吗?如何将移动发送到创建的uci-连接?或者这是不可能的?
非常感谢。
发布于 2013-12-23 12:17:48
尝试在范围层次结构中向上移动var uci。
io.sockets.on('connection',function(socket){
var uci;
socket.on('start', function(data) {
uci = new UCI();
var game = new Chess();
...
})
socket.on('m',function(data){
uci.move(data.move);
});
});https://stackoverflow.com/questions/20743116
复制相似问题