feat: dungeon generation — BSP rooms, room types, fog of war

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 23:50:43 +09:00
parent 4fdd7a1ad0
commit 8849bf5220
4 changed files with 161 additions and 0 deletions

42
dungeon/generator_test.go Normal file
View File

@@ -0,0 +1,42 @@
package dungeon
import "testing"
func TestGenerateFloor(t *testing.T) {
floor := GenerateFloor(1)
if len(floor.Rooms) < 5 || len(floor.Rooms) > 8 {
t.Errorf("Room count: got %d, want 5~8", len(floor.Rooms))
}
bossCount := 0
for _, r := range floor.Rooms {
if r.Type == RoomBoss {
bossCount++
}
}
if bossCount != 1 {
t.Errorf("Boss rooms: got %d, want 1", bossCount)
}
visited := make(map[int]bool)
var dfs func(int)
dfs = func(idx int) {
if visited[idx] { return }
visited[idx] = true
for _, n := range floor.Rooms[idx].Neighbors { dfs(n) }
}
dfs(0)
if len(visited) != len(floor.Rooms) {
t.Errorf("Not all rooms connected: reachable %d / %d", len(visited), len(floor.Rooms))
}
}
func TestRoomTypeProbability(t *testing.T) {
counts := make(map[RoomType]int)
n := 10000
for i := 0; i < n; i++ {
counts[RandomRoomType()]++
}
combatPct := float64(counts[RoomCombat]) / float64(n) * 100
if combatPct < 40 || combatPct > 50 {
t.Errorf("Combat room probability: got %.1f%%, want ~45%%", combatPct)
}
}