使用镶边立方体浏览器

Using the chrome cube explorer

本文关键字:立方体 浏览器      更新时间:2023-09-26

我正在寻找一些使用过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(),但我不确定在哪里可以定义它。 它不是cubewindowERNO的成员,而、都是这个环境中的对象。

真的无法找到一个好的资源来说明我应该如何设置它。

如果有人知道如何使用这个工具,或者有一个很好的资源,我可以从中学习,那就太好了。 提前谢谢你!

我想

通了,在我放弃了一次之后。 事实证明,我不明白ERNO课程是如何构建的,或者它如何适应大局。 为了使内置函数能够调用Solver()函数,必须创建该对象的实例,然后附加到window对象。 之后,代码开箱即用即可完美运行。

定义Solver()

ERNO.Solver = function(){...

创建 Solver() 的实例并将其附加到 window 对象:

mySolver = new ERNO.Solver()
window.solver = mySolver

然后,通过调用cube.solve(),将cube.isSolving设置为truecube.loop()函数将调用window.solver(),这将运行ERNO.Solver()函数定义中编写的代码!! 耶!

ERNO 类的结构非常简单,没有任何构造函数定义。

为了使内置函数调用 Solver() 函数,一个 必须创建该对象的实例并随后附加到 窗口对象。之后,代码开箱即用即可完美运行。

Mark Lundin 制作的求解器函数有点不完整,重点更多放在界面上,以及虚拟立方体的转动过程。可以有很多内存密集型任务,可以附加这些任务以制作更好的求解器。

网站 魔方浏览器 ,非常适合介绍立方体的概念,并且可以进行很多改进,Solver()