X-Git-Url: http://git.scottworley.com/planeteer/blobdiff_plain/2f4a9ae81a1a4802acbba08e84f645a5d7b0cd52..c67c206aab4588c5264e33d78571882c2c8f8f31:/planeteer.go diff --git a/planeteer.go b/planeteer.go index 4dbb27b..ca90a02 100644 --- a/planeteer.go +++ b/planeteer.go @@ -178,7 +178,7 @@ func DimensionSizes(data planet_data) []int { dims[UnusedCargo] = eden_capacity + cloak_capacity + 1 dims[Fuel] = *fuel + 1 dims[Location] = len(data.Planets) - dims[Hold] = len(data.Commodities) + dims[Hold] = len(data.Commodities) + 1 dims[NeedFighters] = bint(*drones > 0) + 1 dims[NeedShields] = bint(*batteries > 0) + 1 dims[Visit] = 1 << uint(len(visit())) @@ -319,8 +319,8 @@ func FillCellBySelling(data planet_data, dims []int, table []State, addr []int) continue } base_price := data.Commodities[commodity].BasePrice - absolute_price := relative_price * base_price - sell_price := int(float64(absolute_price) * 0.9) + absolute_price := float64(base_price) * float64(relative_price) / 100.0 + sell_price := int(absolute_price * 0.9) for other[UnusedCargo] = 0; other[UnusedCargo] < dims[UnusedCargo]; other[UnusedCargo]++ { @@ -350,7 +350,7 @@ func FillCellByBuying(data planet_data, dims []int, table []State, addr []int) { return } base_price := data.Commodities[commodity].BasePrice - absolute_price := relative_price * base_price + absolute_price := int(float64(base_price) * float64(relative_price) / 100.0) quantity := *hold - addr[UnusedCargo] total_price := quantity * absolute_price other[Hold] = 0 @@ -430,7 +430,7 @@ func FillStateTable1(data planet_data, dims []int, table []State) { <-barrier } work_done++ - fmt.Printf("\r%3.0f%%", 100*work_done/work_units) + print(fmt.Sprintf("\r%3.0f%%", 100*work_done/work_units)) } } print("\n") @@ -456,9 +456,21 @@ func FindBestState(data planet_data, dims []int, table []State) int { return max_index } +func Commas(n int) (s string) { + r := n % 1000 + n /= 1000 + for n > 0 { + s = fmt.Sprintf(",%03d", r) + s + r = n % 1000 + n /= 1000 + } + s = fmt.Sprint(r) + s + return +} + func DescribePath(data planet_data, dims []int, table []State, start int) (description []string) { for index := start; index > 0 && table[index].from > 0; index = table[index].from { - line := fmt.Sprintf("%10v", table[index].value) + line := fmt.Sprintf("%13v", Commas(table[index].value)) addr := DecodeIndex(dims, index) prev := DecodeIndex(dims, table[index].from) if addr[Location] != prev[Location] { @@ -526,6 +538,6 @@ func main() { best, DecodeIndex(dims, best), table[best].value) description := DescribePath(data, dims, table, best) for i := len(description) - 1; i >= 0; i-- { - print(description[i], "\n") + fmt.Println(description[i]) } }