Esempio n. 1
0
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
		}
	}
}
Esempio n. 2
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
}