Ejemplo n.º 1
0
func GetMap(size int, heur int) (*board.Board, error) {
	var err error

	if size < 3 {
		size = 3
	}
	b := board.New(size, heur)
	sVal := Get_slice(size)
	for i := 0; i < b.Size; i++ {
		for j := 0; j < b.Size; j++ {
			sVal, b.Tiles[i*b.Size+j] = Get_Value(sVal)
			if b.Tiles[i*b.Size+j] == 0 {
				b.BR = i
				b.BC = j
			}
		}
	}
	if b.CheckBoard() == false {
		b, err = GetMap(size, heur)
		if err != nil {
			return nil, err
		}
	}
	return b, nil
}
Ejemplo n.º 2
0
func main() {
	var b *board.Board
	svr2 := new(solver_2.Solver)
	svr3 := new(solver_3.Solver)
	solv, heur := 0, 0

	flag.Parse()
	plog.Activate(showInfo, showWarning, showError, verbose)
	if size, inp, err := chooseInput(file, stdin); err != nil {
		fmt.Println(err)
		plog.Info.Println("generating map")
		rand.Seed(time.Now().Unix())
		solv, heur = askHeur()
		b, err = generate.GetMap(mapSize, heur)
		handleErr(err)
	} else {
		solv, heur = askHeur()
		b = board.New(size, heur)
		err := b.Input(inp)
		if err != nil {
			fmt.Println(err)
			return
		}
	}
	fmt.Printf("Map %d*%d is solvable.\n", b.Size, b.Size)
	fmt.Println(b)
	if solv == 1 {
		s := solver.New(b)
		s.Solve()
	} else if solv == 2 {
		svr2.Solve_init(b, heur)
		svr2.Solve()
	} else if solv == 3 {
		svr3.Solve_init(b, heur)
		svr3.Solve()
	}
	return
}