package main import ( "log" "math/rand" ) func BigBang(config YTConfig) ([]YTSector, error) { var result []YTSector = make([]YTSector, config.Sectors)[0:0] log.Printf("Config.Sector: %d, Result: len=%d cap=%d", config.Sectors, len(result), cap(result)) var err error _ = err // Fill the universe for sec_num := range make([]byte, config.Sectors) { result = append(result, YTSector{ Sector: YTSectorType(sec_num + 1), }) } // Warps var num_sectors int // Number of sectors/warps from this sector var sectors []YTSectorType // Collection of sectors (to be added to the current sector) var sec YTSectorType // Current sector being added var already bool // is the sector already there var added bool // have we added a sector? for sec_num, _ := range result { sectors = []YTSectorType{} num_sectors = rand.Intn(5) + 1 for _ = range make([]byte, num_sectors) { added = false for !added { sec = YTSectorType(rand.Intn(config.Sectors-1) + 1) already = false for _, s := range sectors { if s == sec { already = true break } } if !already { sectors = append(sectors, sec) //log.Printf("%d > %d", sector.Sector, sec) added = true break } } } // Cross link for _, s := range sectors { result[sec_num].Sectors = append(result[sec_num].Sectors, s) result[s-1].Sectors = append(result[s-1].Sectors, YTSectorType(sec_num)) //log.Printf("%d > %v", sector.Sector, sector.Sectors) //log.Printf("%d < %v", s, result[s].Sectors) } } return result, nil }