feat: add daily challenge seed generation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-25 16:01:17 +09:00
parent 5ff82120ff
commit cd0d6c1c4c
2 changed files with 53 additions and 0 deletions

11
game/daily.go Normal file
View File

@@ -0,0 +1,11 @@
package game
import (
"crypto/sha256"
"encoding/binary"
)
func DailySeed(date string) int64 {
h := sha256.Sum256([]byte("catacombs:" + date))
return int64(binary.BigEndian.Uint64(h[:8]))
}

42
game/daily_test.go Normal file
View File

@@ -0,0 +1,42 @@
package game
import (
"math/rand"
"testing"
"github.com/tolelom/catacombs/dungeon"
)
func TestDailySeed(t *testing.T) {
// Same date produces the same seed
seed1 := DailySeed("2026-03-25")
seed2 := DailySeed("2026-03-25")
if seed1 != seed2 {
t.Errorf("same date should produce same seed: got %d and %d", seed1, seed2)
}
// Different date produces a different seed
seed3 := DailySeed("2026-03-26")
if seed1 == seed3 {
t.Errorf("different dates should produce different seeds: both got %d", seed1)
}
}
func TestDailyFloorDeterminism(t *testing.T) {
seed := DailySeed("2026-03-25")
// Generate floor twice with the same seed
floor1 := dungeon.GenerateFloor(1, rand.New(rand.NewSource(seed)))
floor2 := dungeon.GenerateFloor(1, rand.New(rand.NewSource(seed)))
if len(floor1.Rooms) != len(floor2.Rooms) {
t.Fatalf("room count mismatch: %d vs %d", len(floor1.Rooms), len(floor2.Rooms))
}
for i, r1 := range floor1.Rooms {
r2 := floor2.Rooms[i]
if r1.Type != r2.Type {
t.Errorf("room %d type mismatch: %d vs %d", i, r1.Type, r2.Type)
}
}
}