예제 #1
0
// unmarshalPuzzle: unserialize JSON to a puzzle
func (s *Session) unmarshalPuzzle(bytes []byte) *puzzle.Puzzle {
	var summary *puzzle.Summary
	err := json.Unmarshal(bytes, &summary)
	if err != nil {
		panic(fmt.Errorf("Failed to unmarshal summary: %v", err))
	}
	puzzle, err := puzzle.New(summary)
	if err != nil {
		panic(fmt.Errorf("Failed to create puzzle from summary: %v", err))
	}
	return puzzle
}
예제 #2
0
func TestSolverPage(t *testing.T) {
	p0, e := puzzle.New(rotation4Puzzle1PartialValues)
	if e != nil {
		t.Fatalf("Failed to create p0: %v", e)
	}
	session0, puzzle0 := "httpx-Test0", "test-0"
	body0 := SolverPage(session0, puzzle0, p0.State())
	if !sameAsResultFile(body0, "TestSolverPage0.html") {
		t.Errorf("Test Solver 0: got unexpected result body:\n%v\n", body0)
	}

	p1, e := puzzle.New(oneStarValues)
	if e != nil {
		t.Fatalf("Failed to create p1: %v", e)
	}
	session1, puzzle1 := "https-Test1", "test-1"
	body1 := SolverPage(session1, puzzle1, p1.State())
	if !sameAsResultFile(body1, "TestSolverPage1.html") {
		t.Errorf("Test Solver 1: got unexpected result body:\n%v\n", body1)
	}
}
예제 #3
0
파일: main.go 프로젝트: Metasemi/susen.go
func (session *susenSession) reset(puzzleID string) {
	vals, ok := puzzleValues[puzzleID]
	if ok {
		session.puzzleID = puzzleID
	} else {
		session.puzzleID, vals = defaultPuzzleID, puzzleValues[defaultPuzzleID]
	}
	p, e := puzzle.New(vals)
	if e != nil {
		log.Fatal(e)
	}
	session.steps = []puzzle.Puzzle{p}
	log.Printf("Initialized session %v from puzzle %q.", session.sessionID, session.puzzleID)
}
예제 #4
0
// makePuzzle: make the puzzle described in a puzzle entry
func (pe *puzzleEntry) makePuzzle() *puzzle.Puzzle {
	values := make([]int, len(pe.Values))
	for i, v := range pe.Values {
		values[i] = int(v)
	}
	p, e := puzzle.New(&puzzle.Summary{
		Geometry:   pe.Geometry,
		SideLength: int(pe.SideLength),
		Values:     values,
	})
	if e != nil {
		panic(fmt.Errorf("Failed to create puzzle %q: %v", pe.PuzzleId, e))
	}
	return p
}