// Slice in a specific direction func (b *Board) fieldsInSlot(row, col, offset int, dir direction, slot gap) []*Field { util.LogDebug("Picking fields [%d, %d] in %s", slot.start+offset, slot.end+offset, dir.toString()) if dir == ROW { return b.Fields[row][slot.start+offset : slot.end+offset+1] } return b.getColumn(col, slot.start+offset, slot.end+offset+1) }
func LoadConfig(path string) { if path == "" { util.LogDebug("Loaded default config.") conf = defaultConfig() return } f, err := os.Open(path) if err != nil { panic(err) } defer f.Close() stat, err := f.Stat() if err != nil { panic(err) } rawContent := make([]byte, stat.Size()) _, err = f.Read(rawContent) if err != nil { panic(err) } conf = loadConfigFromBytes(rawContent) }
func loadConfigFromBytes(rawContent []byte) config { conf = defaultConfig() err := json.Unmarshal(rawContent, &conf) if err != nil { panic(err) } util.LogDebug("Loaded config: %#v", conf) return conf }
func (g *Game) measureTurnTime() { elapsed := 0.0 start := time.Now() ticker := time.NewTicker(time.Second) for { select { case now := <-ticker.C: elapsed = now.Sub(start).Seconds() util.LogDebug("Tick: %f", elapsed) // report tick for _, reporter := range g.views { reporter.ReportElapsedTime(elapsed) } if elapsed >= float64(conf.TurnDurationSec) { ticker.Stop() g.endTurn <- 1 } case <-g.endTurn: return } } }