예제 #1
0
func scrambleGenerator() <-chan []gocube.Move {
	rand.Seed(time.Now().UnixNano())
	ch := make(chan []gocube.Move)
	go func() {
		p1Moves := gocube.NewPhase1Moves()
		p1Heuristic := gocube.NewPhase1Heuristic(p1Moves)
		p2Moves := gocube.NewPhase2Moves()
		p2Heuristic := gocube.NewPhase2Heuristic(p2Moves, false)
		tables := gocube.SolverTables{p1Heuristic, p1Moves, p2Heuristic, p2Moves}

		for {
			state := gocube.RandomCubieCube()
			solver := gocube.NewSolverTables(state, 30, tables)
			timeout := time.After(time.Second * 30)
			solution := <-solver.Solutions()

		SolutionLoop:
			for {
				select {
				case sol, ok := <-solver.Solutions():
					if !ok {
						break SolutionLoop
					}
					solution = sol
				case <-timeout:
					break SolutionLoop
				}
			}
			solver.Stop()

			ch <- solution
		}
	}()
	return ch
}
예제 #2
0
파일: main.go 프로젝트: chai2010/gocube
func main() {
	if len(os.Args) < 2 {
		fmt.Fprintln(os.Stderr, "Usage: scrambler <count> [maxlen=30]")
		os.Exit(1)
	}
	count, err := strconv.Atoi(os.Args[1])
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	maxLen := 30
	if len(os.Args) > 2 {
		maxLen, err = strconv.Atoi(os.Args[2])
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
	}

	p1Moves := gocube.NewPhase1Moves()
	p1Heuristic := gocube.NewPhase1Heuristic(p1Moves)
	p2Moves := gocube.NewPhase2Moves()
	p2Heuristic := gocube.NewPhase2Heuristic(p2Moves, false)
	tables := gocube.SolverTables{p1Heuristic, p1Moves, p2Heuristic, p2Moves}
	for i := 0; i < count; i++ {
		state := gocube.RandomCubieCube()
		solver := gocube.NewSolverTables(state, maxLen, tables)
		for solution := range solver.Solutions() {
			str := fmt.Sprint(solution)
			fmt.Println(str[1 : len(str)-1])
			solver.Stop()
			break
		}
	}
}
예제 #3
0
파일: main.go 프로젝트: chai2010/gocube
func main() {
	// Get input.
	sc, err := gocube.InputStickerCube()
	if err != nil {
		fmt.Println("Failed to read stickers:", err)
		os.Exit(1)
	}
	cc, err := sc.CubieCube()
	if err != nil {
		fmt.Println("Invalid stickers:", err)
		os.Exit(1)
	}

	fmt.Println("Generating data...")
	moves := gocube.NewPhase1Moves()
	heuristic := gocube.NewPhase1Heuristic(moves)

	fmt.Println("Searching...")
	solver := gocube.NewPhase1Solver(cc.Phase1Cube(), heuristic, moves)
	for solution := range solver.Solutions() {
		fmt.Println(solution.Moves, "-", len(solution.Moves), "moves")
	}
}