Git Product home page Git Product logo

tpr-4x4x4-solver's Introduction

TPR-4x4x4-Solver

4x4x4 Solver = Three-Phase-Reduction Solver + 3x3x3 Solver

Usage

  • sh make.sh # generate threephase.jar
  • java -cp .:threephase.jar:twophase.jar test N # solving N random-state scrambled cubes.

Solve a specific cube from the command line

  • java -cp .:threephase.jar:twophase.jar solver UUURUUUFUUUFUUUFRRRBRRRBRRRBRRRBRRRDFFFDFFFDFFFDDDDBDDDBDDDBDDDLFFFFLLLLLLLLLLLLULLLUBBBUBBBUBBB

Performance

  • Command: "java -cp .:threephase.jar:twophase.jar test 2000"
  • GUI demo: "java -cp .:threephase.jar:twophase.jar ui.MainProgram"
  • Processor: Intel Core i7 2670QM
  • Average solution length: 44.39 moves(face turn metric).
  • Average solving time: 250 ms.
  • Memory: <= 30M with min2phase package.
  • Initialization time: 6s~7s
  • Solution Length Distribution:
  • 40 5
  • 41 32
  • 42 99
  • 43 275
  • 44 590
  • 45 658
  • 46 309
  • 47 32

Note

  • At its first executing, about 20M's tables will be generated and written to disk (md5(threephase.data) = 0ee2f10d29af8ada724a1426275512c5).

Algorithm

TODO

  • Speeding up initialization.
  • Solution format.
  • Many bugs which might cause ArrayIndexOutOfBoundsException.

License GPLv3

Copyright (C) 2023  Shuang Chen

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

License MIT

Copyright (c) 2023 Chen Shuang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

tpr-4x4x4-solver's People

Contributors

cs0x7f avatar dwalton76 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tpr-4x4x4-solver's Issues

Inverse solution

Add an option to print the inverse solution.
This is not obvious, as Bruce pointed out on the speedsolving forum:
if when solving you end up with a non standard orientation (not white on top, green on front), then inversing the solution is not enough, as people will start scrambling with white on top and green on front, so they won't obtain the wanted position.

Freezed search with wrong position

Hello, with the following position, the search is broken but nothing happens, there is no warning, neither error :

java -cp .:threephase.jar:twophase.jar solver UUUUUUUUUUUUUUUFLLLLLLLLLLLLLLLLFFFRFFFFFFFFFFFFURRRRRRRRRRRRRRRBBBBBBBBBBBBBBBBDDDDDDDDDDDDDDDD

Cancelling moves between stages

I've seen some scrambles like:

U2 F' L2 F' D2 F' L2 B U2 B2 L' U2 F' D F2 L R2 D L' U2 Uw2 B Uw2 R' F Uw2 Rw2 L F2 U2 B Uw2 Uw' D Rw2 R' U2 L U' Fw' Uw L2 Uw2 Rw F'

There's a Uw2 Uw' in here. Here's a hacked version of FullCube.java that causes this problem:

public FullCube(Random r) {
        //<<<edge = new EdgeCube(r);
        //<<<center = new CenterCube(r);
        //<<<corner = new CornerCube(r);

        edge = new EdgeCube(r);//<<<
        //edge.ep = new byte[] {10, 18, 2,  21, 12, 15, 17, 22, 4,  14, 1,  11, 8,  6,  5,  19, 20, 3,  16, 7,  9,  13, 0,  23};
        edge.ep = new byte[] { 2,   15,  10,  23,  7,   1,   11,  13,  12,  6,   20,  16,  3,   5,   9,   19,  14,  18,  22,  8,   17,  0,   4,   21 };
        center = new CenterCube(r);//<<<
        center.ct = new byte[] { 5, 2,   1,   0,   1,   0 ,  4,   5  , 1,   3,   4,   3,   2,   2,   4,   0,   1,   5,   4,   5,   3,   3,   0,   2 };
        corner = new CornerCube(34651, 1086);//<<<
    }

From looking at Search.java's run(), it looks like no effort is made to cancel moves between stages. This is something that would be nice to have. Alternatively, we could resurrect TNoodle's TurnBuilder in CubeScrambler.java to hack around this @clementgallet

Does TRP put edges in different orbits?

I'm a bit confused by search2. How does it achieve:
"1. Orient corresponding low and high edges the same way. Make sure that the number of misoriented edges is a multiple of 4. (Instead of requiring that all edges are oriented correctly, we require only that a low edge and its corresponding high edge be oriented the same way: both correctly or both incorrectly.) " (Taken from http://cubezzz.dyndns.org/drupal/?q=node/view/73#comment-2588)
I think this text means that the pairs of edges have to be in different orbits.

All I can see from Centres2.java is that it cares about 'parity' and flips parity on slice moves. I don't see any mention of orbits.

Wrong position throws error

Hello, given anything like :

java -cp .:threephase.jar:twophase.jar solver ANY_TEXT

Raises :

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 8
	at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
	at java.base/java.lang.String.charAt(String.java:712)
	at cs.threephase.Search.solution(Search.java:134)
	at solver.main(solver.java:42)

It should return something like Wrong position.
Regards.

optimal solver "chokes" on very short scrambles

When presented with scrambles of length 4, the Search#solution method sometimes comes up with unnecessarily long results:

Lw2 F2 R' 3Fw solved as F2 B' Uw2 U2 F2 D F2 U2
Fw B L2 3Fw' solved as D2 Fw' B R2 B R2 B2
D2 Dw2 3Bw2 U solved as F2 Uw2 U2 F2 U' F2

I would expect the code to be able to find the "reverse solutions" of length 4. This is currently keeping us from using your optimal solver in TNoodle because we use scrambles of length 4 in our CI sanity checks.

Is there a common pattern to these scrambles that would allow you to fix such corner cases?
I can provide you with more samples if you'd like. The code I'm using is the most recent as of writing this issue.

How does phase2 pruning work?

Hi Chen,
First of all let me say that your solver is amazing, the short solutions that it produces in such a short amount of time are very impressive. I have been trying to reverse engineer how your solver works so that I can implement what you've done in my solver at https://github.com/dwalton76/rubiks-cube-NxNxN-solver . I have the basics working but currently I only find one solution for phase1 because my phase2 is too slow for me to evaluate hundreds of phase1 solutions to find the best phase1 + phase2 combination. It works but I do not find solutions as short as your solver.

I forked your repo and have been adding debugs to figure out how things work, specifically how you are able to run 500 phase2 searches so quickly. One thing I have yet to figure out is how your phase2 pruning works, specifically this section:
https://github.com/dwalton76/TPR-4x4x4-Solver/blob/debug/src/Search.java#L318-L324

            if (prun >= maxl) {
                // TODO what is this doing?
                if (prun > maxl) {
                    m = skipAxis2[m];
                }
                continue;
            }

So if the prun cost is the maxl we just continue to the next step (m++ in the for loop) but if it is above maxl it skips certain moves via skipAxis2. I looked at skipAxis2 but cannot follow what it is doing.

Any words of wisdom on how this works?

Thanks
Daniel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.