使用镶边立方体浏览器
Using the chrome cube explorer
我正在寻找一些使用过Chrome的Cube Explorer http://iamthecu.be/的人。 在Rubik官方网站上找到的基本源代码 https://rubiks.com/chrome-cube-lab。 我想为这个平台编写一个自动求解器,但我不确定如何运行我编写的代码。
这是我在修改任何内容之前放置代码的文件。 重点在于块注释和ERNO.Solver = function() {...
部分:
/*
SOLVERS
Our Cube has its own animation loop conveniently called Cube.loop().
If Cube.isSolving === true then within that loop Cube will call
window.solver.consider( cube ). This means when you create your own
Solver instance you have to set window.solver equal to your instance.
Solver.consider() will do some very basic checking and if all's well
will pass the Cube instance to Solver.logic() which is the function that
you need to write yourself.
Your logic() should return false is the cube is solved or if something's
gone horribly wrong. This will set Cube.isSolving = false and stop the
solver from being called within the Cube's animation loop.
Your logic() should return true if an incremental improvement has been
made and the logic() should be run again in the next loop; For example,
run again after a twist queue completes.
--
@author Mark Lundin - http://www.mark-lundin.com
@author Stewart Smith
*/
ERNO.Solver = function(){
// When you create your own Solver this is the only function you need to build yourself.
// Having said that, it will probably be the most intense function like ... ever!
// Check out my example in /scripts/solvers/stewart.js to see how you might go about it.
this.logic = function( cube ){ return false };;
}
// This is the method called within Cube.loop() when Cube.isSolving === true.
// It will call Solver.logic() which is the function you need to fill in.
ERNO.Solver.prototype.consider = function( cube ){
// Was our solver passed a valid Cube?
// Kind of important, eh?
if( cube === undefined ){
console.warn( 'A cube [Cube] argument must be specified for Solver.consider().' );
return false;
}
else if( cube instanceof ERNO.Cube === false ){
console.warn( 'The cube argument provided is not a valid Cube.' );
return false;
}
// If we're solving we should really make certain we aren't shuffling!
// Otherwise our logic will never actually run.
// The hook for this is in Cube.loop() so look there to see what's up.
cube.isShuffling = false;
// If the cube is already solved then our job is done before it started.
// If not, we need to try solving it using our current solve method.
if( cube.isSolved() ){
ERNO.Solver.prototype.explain( 'I’ve found that the cube is already solved.' );
return false;
}
else return this.logic( cube );
};
// We should always hit at what the Solver wants to do next
// so we can hault auto-solving and give the user a chance to
// figure out the next move for his/herself.
ERNO.Solver.prototype.hint = function( text ){
console.log(
'%c'+ text +'%c'n',
'background-color: #EEE; color: #333', ''
);
};
// If hinting is text displayed *before* a move is made
// then explaining is text displayed *after* a move is made.
ERNO.Solver.prototype.explain = function( text ){
console.log(
'Solver says: %c '+ text +' %c'n',
'color: #080', ''
);
};
我修改了ERNO.Solver = function(){...
,使其看起来像下面的代码,正如注释所建议的那样,正如它写在示例文件中一样,stewart.js
,我输入了一些测试代码来运行。
window.solver = new Solver();
solver.logic = function( cube ){...
但无济于事,当我cube.solve()
运行该方法或设置标志cube.isSolving == true
时,我的函数似乎没有运行。 如果我用stewart.js
脚本代替我自己的脚本,同样的故事也是如此。 似乎构造函数 window.solver = new Solver()
失败了,因为没有定义Solver()
,但我不确定在哪里可以定义它。 它不是cube
、window
或ERNO
的成员,而、都是这个环境中的对象。
真的无法找到一个好的资源来说明我应该如何设置它。
如果有人知道如何使用这个工具,或者有一个很好的资源,我可以从中学习,那就太好了。 提前谢谢你!
通了,在我放弃了一次之后。 事实证明,我不明白ERNO课程是如何构建的,或者它如何适应大局。 为了使内置函数能够调用Solver()
函数,必须创建该对象的实例,然后附加到window
对象。 之后,代码开箱即用即可完美运行。
定义Solver()
:
ERNO.Solver = function(){...
创建 Solver()
的实例并将其附加到 window
对象:
mySolver = new ERNO.Solver()
window.solver = mySolver
然后,通过调用cube.solve()
,将cube.isSolving
设置为true
,cube.loop()
函数将调用window.solver()
,这将运行ERNO.Solver()
函数定义中编写的代码!! 耶!
ERNO 类的结构非常简单,没有任何构造函数定义。
为了使内置函数调用 Solver() 函数,一个 必须创建该对象的实例并随后附加到 窗口对象。之后,代码开箱即用即可完美运行。
Mark Lundin 制作的求解器函数有点不完整,重点更多放在界面上,以及虚拟立方体的转动过程。可以有很多内存密集型任务,可以附加这些任务以制作更好的求解器。
网站 魔方浏览器 ,非常适合介绍立方体的概念,并且可以进行很多改进,Solver()
。
- 访问布局信息是否也会导致浏览器重排
- 内部分区字体大小获胜'调整浏览器窗口大小时不会随媒体查询而更改
- 如何使用phaser使html5游戏在移动设备浏览器上运行
- 有时数据是't显示在浏览器中
- 使图像在单击时展开到不大于浏览器
- fetch() 函数未在 Ubuntu Chromium 浏览器上定义
- 不同浏览器中的空白字符正则表达式行为
- 在Windows 10中自动执行例行程序(主要与浏览器交互)
- Windows形成web浏览器控件和Javascript更改的DOM
- 如何临时暂停浏览器渲染,然后恢复整个页面
- 使用angularjs向浏览器发送servlet响应(下载功能)
- 是什么让一个“;Uncaught RangeError:超过了最大调用堆栈大小“;错误(Chrome,在其他浏览器中显示
- 谷歌地图API v3不适用于移动浏览器或PhoneGap
- 禁用(而不是隐藏)浏览器滚动条
- jquery代码在Mozilla中有效,但在其他浏览器上无效
- 如何使用modalDialog来显示可以在所有浏览器中工作的弹出窗口
- 当浏览器上的后退按钮到达主页时,我需要删除Class
- 是否可以在浏览器中使用纯JavaScript保存音频流
- jQuery检测浏览器是否支持Zoom
- 使用镶边立方体浏览器