]> git.scottworley.com Git - planeteer/blobdiff - planeteer.go
Consider not using all the fuel.
[planeteer] / planeteer.go
index 5e406fab68fde9a6823e4a9efe16355b60422780..a3a5a029add7dd798fe37624c8dddc61f68f3dcb 100644 (file)
@@ -110,6 +110,7 @@ type Commodity struct {
 }
 type Planet struct {
        BeaconOn bool
+       Private bool
        /* Use relative prices rather than absolute prices because you
           can get relative prices without traveling to each planet. */
        RelativePrices map[string]int
@@ -336,6 +337,10 @@ func FillCellByArriving(data planet_data, dims []int, table []State, addr []int)
 }
 
 func FillCellBySelling(data planet_data, dims []int, table []State, addr []int) {
+       if data.Planets[data.i2p[addr[Location]]].Private {
+               // Can't do commerce on private planets
+               return
+       }
        if addr[Hold] > 0 {
                // Can't sell and still have cargo
                return
@@ -373,6 +378,10 @@ func FillCellBySelling(data planet_data, dims []int, table []State, addr []int)
 }
 
 func FillCellByBuying(data planet_data, dims []int, table []State, addr []int) {
+       if data.Planets[data.i2p[addr[Location]]].Private {
+               // Can't do commerce on private planets
+               return
+       }
        if addr[Hold] == 0 {
                // Can't buy and then have nothing
                return
@@ -575,15 +584,17 @@ func FindBestState(data planet_data, dims []int, table []State) int {
        addr[BuyFighters] = dims[BuyFighters] - 1
        addr[BuyShields] = dims[BuyShields] - 1
        addr[Visit] = dims[Visit] - 1
-       // Fuel, Hold, UnusedCargo left at 0
+       // Hold and UnusedCargo left at 0
        max_index := -1
        max_value := 0
-       for addr[Location] = 0; addr[Location] < dims[Location]; addr[Location]++ {
-               if len(end()) == 0 || end()[data.i2p[addr[Location]]] {
-                       index := EncodeIndex(dims, addr)
-                       if table[index].value > max_value {
-                               max_value = table[index].value
-                               max_index = index
+       for addr[Fuel] = 0; addr[Fuel] < 2; addr[Fuel]++ {
+               for addr[Location] = 0; addr[Location] < dims[Location]; addr[Location]++ {
+                       if len(end()) == 0 || end()[data.i2p[addr[Location]]] {
+                               index := EncodeIndex(dims, addr)
+                               if table[index].value > max_value {
+                                       max_value = table[index].value
+                                       max_index = index
+                               }
                        }
                }
        }