Beispiel #1
0
func parseHTMLCell(n *html.Node) (Cell, error) {
	switch v, _ := htmlutil.GetAttr(n, "class"); v {
	case "whitegrey":
		return &ValueCell{Val: bitset.Interval(1, 9)}, nil
	case "grey":
		return &ClueCell{}, nil
	case "infocellgrey":
		if v, h, err := getClues(n); err != nil {
			return nil, err
		} else {
			return &ClueCell{VClue: v, HClue: h}, nil
		}
	default:
		return nil, gridErr("Unknown or missing cell class")
	}
}
Beispiel #2
0
func NewGrid(h, w int) *Grid {
	if h < 2 || w < 2 {
		panic("A grid must be at least 2x2")
	}
	g := &Grid{cells: make([][]Cell, h), h: h, w: w}
	g.cells[0] = make([]Cell, w)
	for j := range g.cells[0] {
		g.cells[0][j] = &ClueCell{}
	}
	for i := 1; i < h; i++ {
		g.cells[i] = make([]Cell, w)
		g.cells[i][0] = &ClueCell{}
		for j := 1; j < w; j++ {
			g.cells[i][j] = &ValueCell{Val: bitset.Interval(1, 9)}
		}
	}
	return g
}
Beispiel #3
0
func parseCell(s string) Cell {
	if len(s) != 5 {
		return nil
	}
	if s == "     " {
		return &ValueCell{Val: bitset.Interval(1, 9)}
	}
	if s[2] == '\\' {
		if v, h := parseClue(s[:2]), parseClue(s[3:]); v == errClue || h == errClue {
			return nil
		} else {
			return &ClueCell{VClue: v, HClue: h}
		}
	}
	e, err := strconv.Atoi(s)
	if err != nil || e < 1 || 9 < e {
		return nil
	}
	return &ValueCell{Val: bitset.Set(bitset.Element(e))}
}