+ for other[Edens] = addr[Edens] + 1; other[Edens] < dims[Edens]; other[Edens]++ {
+ for other[Location] = 0; other[Location] < dims[Location]; other[Location]++ {
+ UpdateCell(table, my_index, EncodeIndex(dims, other), 0)
+ }
+ }
+ other[Location] = addr[Location]
+ other[Edens] = addr[Edens]
+}
+
+func FillCellBySelling(data planet_data, dims []int, table []State, addr []int) {
+ if addr[Hold] > 0 {
+ // Can't sell and still have cargo
+ return
+ }
+ if addr[UnusedCargo] > 0 {
+ // Can't sell everything and still have 'unused' holds
+ return
+ }
+ my_index := EncodeIndex(dims, addr)
+ other := make([]int, NumDimensions)
+ copy(other, addr)
+ planet := data.i2p[addr[Location]]
+ for other[Hold] = 0; other[Hold] < dims[Hold]; other[Hold]++ {
+ commodity := data.i2c[other[Hold]]
+ if !data.Commodities[commodity].CanSell {
+ // TODO: Dump cargo
+ continue
+ }
+ relative_price, available := data.Planets[planet].RelativePrices[commodity]
+ if !available {
+ continue
+ }
+ base_price := data.Commodities[commodity].BasePrice
+ absolute_price := relative_price * base_price
+ sell_price := int(float64(absolute_price) * 0.9)
+
+ for other[UnusedCargo] = 0; other[UnusedCargo] < dims[UnusedCargo]; other[UnusedCargo]++ {
+
+ quantity := *hold - other[UnusedCargo] // TODO: Partial sales
+ sale_value := quantity * sell_price
+ UpdateCell(table, my_index, EncodeIndex(dims, other), sale_value)
+ }
+ }
+ other[UnusedCargo] = addr[UnusedCargo]
+}
+
+func FillCellByBuying(data planet_data, dims []int, table []State, addr []int) {
+ if addr[Hold] == 0 {
+ // Can't buy and then have nothing
+ return
+ }
+ my_index := EncodeIndex(dims, addr)
+ other := make([]int, NumDimensions)
+ copy(other, addr)
+ planet := data.i2p[addr[Location]]
+ commodity := data.i2c[addr[Hold]]
+ if !data.Commodities[commodity].CanSell {
+ return
+ }
+ relative_price, available := data.Planets[planet].RelativePrices[commodity]
+ if !available {
+ return
+ }
+ base_price := data.Commodities[commodity].BasePrice
+ absolute_price := relative_price * base_price
+ quantity := *hold - addr[UnusedCargo]
+ total_price := quantity * absolute_price
+ other[Hold] = 0
+ UpdateCell(table, my_index, EncodeIndex(dims, other), -total_price)
+}
+
+func FillCellByMisc(data planet_data, dims []int, table []State, addr []int) {