1 /* Planeteer: Give trade route advice for Planets: The Exploration of Space
2 * Copyright (C) 2011 Scott Worley <sworley@chkno.net>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Affero General Public License for more details.
13 * You should have received a copy of the GNU Affero General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import "encoding/json"
23 import "runtime/pprof"
26 var funds = flag.Int("funds", 0,
29 var start = flag.String("start", "",
30 "The planet to start at")
32 var flight_plan_string = flag.String("flight_plan", "",
33 "Your hyper-holes for the day, comma-separated.")
35 var end_string = flag.String("end", "",
36 "A comma-separated list of acceptable ending planets.")
38 var planet_data_file = flag.String("planet_data_file", "planet-data",
39 "The file to read planet data from")
41 var fuel = flag.Int("fuel", 16, "Hyper Jump power left")
43 var hold = flag.Int("hold", 300, "Size of your cargo hold")
45 var start_hold = flag.String("start_hold", "", "Start with a hold full of cargo")
47 var start_edens = flag.Int("start_edens", 0,
48 "How many Eden Warp Units are you starting with?")
50 var end_edens = flag.Int("end_edens", 0,
51 "How many Eden Warp Units would you like to keep (not use)?")
53 var cloak = flag.Bool("cloak", false,
54 "Make sure to end with a Device of Cloaking")
56 var drones = flag.Int("drones", 0, "Buy this many Fighter Drones")
58 var batteries = flag.Int("batteries", 0, "Buy this many Shield Batterys")
60 var drone_price = flag.Int("drone_price", 0, "Today's Fighter Drone price")
62 var battery_price = flag.Int("battery_price", 0, "Today's Shield Battery price")
64 var visit_string = flag.String("visit", "",
65 "A comma-separated list of planets to make sure to visit")
67 var tomorrow_weight = flag.Float64("tomorrow_weight", 1.0,
68 "Weight for the expected value of tomorrow's trading. 0.0 - 1.0")
70 var extra_stats = flag.Bool("extra_stats", true,
71 "Show additional information of possible interest")
73 var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
75 var visit_cache []string
77 func visit() []string {
78 if visit_cache == nil {
79 if *visit_string == "" {
82 visit_cache = strings.Split(*visit_string, ",")
87 var flight_plan_cache []string
89 func flight_plan() []string {
90 if flight_plan_cache == nil {
91 if *flight_plan_string == "" {
94 flight_plan_cache = strings.Split(*flight_plan_string, ",")
96 return flight_plan_cache
99 var end_cache map[string]bool
101 func end() map[string]bool {
102 if end_cache == nil {
103 if *end_string == "" {
106 m := make(map[string]bool)
107 for _, p := range strings.Split(*end_string, ",") {
115 type Commodity struct {
124 /* Use relative prices rather than absolute prices because you
125 can get relative prices without traveling to each planet. */
126 RelativePrices map[string]int
128 type planet_data struct {
129 Commodities map[string]Commodity
130 Planets map[string]Planet
131 p2i, c2i map[string]int // Generated; not read from file
132 i2p, i2c []string // Generated; not read from file
135 func json_slurp(filename string, receptacle interface{}) error {
136 f, err := os.Open(filename)
141 err = json.NewDecoder(f).Decode(receptacle)
148 func ReadData() planet_data {
150 err := json_slurp(*planet_data_file, &data)
157 /* This program operates by filling in a state table representing the best
158 * possible trips you could make; the ones that makes you the most money.
159 * This is feasible because we don't look at all the possible trips.
160 * We define a list of things that are germane to this game and then only
161 * consider the best outcome in each possible game state.
163 * Each cell in the table represents a state in the game. In each cell,
164 * we track two things: 1. the most money you could possibly have while in
165 * that state and 2. one possible way to get into that state with that
168 * A basic analysis can be done with a two-dimensional table: location and
169 * fuel. planeteer-1.0 used this two-dimensional table. This version
170 * adds features mostly by adding dimensions to this table.
172 * Note that the sizes of each dimension are data driven. Many dimensions
173 * collapse to one possible value (ie, disappear) if the corresponding
174 * feature is not enabled.
176 * The order of the dimensions in the list of constants below determines
177 * their layout in RAM. The cargo-based 'dimensions' are not completely
178 * independent -- some combinations are illegal and not used. They are
179 * handled as three dimensions rather than one for simplicity. Placing
180 * these dimensions first causes the unused cells in the table to be
181 * grouped together in large blocks. This keeps the unused cells from
182 * polluting cache lines, and if the spans of unused cells are large
183 * enough, allows the memory manager to swap out entire pages.
185 * If the table gets too big to fit in RAM:
186 * * Combine the Edens, Cloaks, and UnusedCargo dimensions. Of the
187 * 24 combinations, only 15 are legal: a 38% savings.
188 * * Reduce the size of the Fuel dimension to 3. Explicit iteration
189 * only ever needs to look backwards 2 units, so the logical values
190 * can rotate through the same 3 physical addresses. This would be
191 * good for an 82% savings. Note that explicit iteration went away
193 * * Reduce the size of the Edens dimension from 3 to 2, for the
194 * same reasons as Fuel above. 33% savings.
195 * * Buy more ram. (Just sayin'. It's cheaper than you think.)
199 // The official list of dimensions:
201 // Name Num Size Description
202 Edens = iota // 1 3 # of Eden warp units (0 - 2 typically)
203 Cloaks // 2 1-2 # of Devices of Cloaking (0 or 1)
204 UnusedCargo // 3 4 # of unused cargo spaces (0 - 3 typically)
205 Fuel // 4 17 Hyper jump power left (0 - 16)
206 Location // 5 26 Location (which planet)
207 Hold // 6 15 Cargo bay contents (a *Commodity or nil)
208 Traded // 7 2 Traded yet?
209 BuyFighters // 8 1-2 Errand: Buy fighter drones
210 BuyShields // 9 1-2 Errand: Buy shield batteries
211 Visit // 10 1-2**N Visit: Stop by these N planets in the route
216 func bint(b bool) int {
223 func DimensionSizes(data planet_data) LogicalIndex {
224 eden_capacity := data.Commodities["Eden Warp Units"].Limit
225 if *start_edens > eden_capacity {
226 eden_capacity = *start_edens
228 cloak_capacity := bint(*cloak)
229 dims := make(LogicalIndex, NumDimensions)
230 dims[Edens] = eden_capacity + 1
231 dims[Cloaks] = cloak_capacity + 1
232 dims[UnusedCargo] = eden_capacity + cloak_capacity + 1
233 dims[Fuel] = *fuel + 1
234 dims[Location] = len(data.Planets)
235 dims[Hold] = len(data.Commodities) + 1
237 dims[BuyFighters] = bint(*drones > 0) + 1
238 dims[BuyShields] = bint(*batteries > 0) + 1
239 dims[Visit] = 1 << uint(len(visit()))
241 // Remind myself to add a line above when adding new dimensions
242 for i, dim := range dims {
251 type PhysicalIndex int32
252 type LogicalIndex []int
254 func StateTableSize(dims LogicalIndex) int {
256 for _, size := range dims {
268 FROM_ROOT = -2147483647 + iota
271 VALUE_BEING_EVALUATED
275 func EncodeIndex(dims, addr LogicalIndex) PhysicalIndex {
277 if addr[0] > dims[0] {
280 for i := 1; i < NumDimensions; i++ {
281 if addr[i] < 0 || addr[i] >= dims[i] {
284 index = index*dims[i] + addr[i]
286 return PhysicalIndex(index)
289 func DecodeIndex(dims LogicalIndex, index PhysicalIndex) LogicalIndex {
290 scratch := int(index)
291 addr := make(LogicalIndex, NumDimensions)
292 for i := NumDimensions - 1; i > 0; i-- {
293 addr[i] = scratch % dims[i]
300 func PlanetIndex(data planet_data, name string) int {
301 index, ok := data.p2i[name]
303 panic("Unknown planet " + name)
308 func CommodityIndex(data planet_data, name string) int {
309 index, ok := data.c2i[name]
311 panic("Unknown commodity " + name)
316 func CreateStateTable(data planet_data, dims LogicalIndex) []State {
317 table := make([]State, StateTableSize(dims))
318 for i := range table {
319 table[i].value = VALUE_UNINITIALIZED
320 table[i].from = FROM_UNINITIALIZED
323 addr := make(LogicalIndex, NumDimensions)
325 addr[Edens] = *start_edens
326 addr[Location] = PlanetIndex(data, *start)
327 if *start_hold != "" {
328 addr[Hold] = CommodityIndex(data, *start_hold)
330 start_index := EncodeIndex(dims, addr)
331 table[start_index].value = Value(*funds)
332 table[start_index].from = FROM_ROOT
337 /* CellValue fills in the one cell at address addr by looking at all
338 * the possible ways to reach this cell and selecting the best one. */
340 func Consider(data planet_data, dims LogicalIndex, table []State, there LogicalIndex, value_difference int, best_value *Value, best_source LogicalIndex) {
341 there_value := CellValue(data, dims, table, there)
342 if value_difference < 0 && Value(-value_difference) > there_value {
343 /* Can't afford this transition */
346 possible_value := there_value + Value(value_difference)
347 if possible_value > *best_value {
348 *best_value = possible_value
349 copy(best_source, there)
353 var cell_filled_count int
355 func CellValue(data planet_data, dims LogicalIndex, table []State, addr LogicalIndex) Value {
356 my_index := EncodeIndex(dims, addr)
357 if table[my_index].value == VALUE_BEING_EVALUATED {
358 panic("Circular dependency")
360 if table[my_index].value != VALUE_UNINITIALIZED {
361 return table[my_index].value
363 table[my_index].value = VALUE_BEING_EVALUATED
365 best_value := Value(VALUE_RUBISH)
366 best_source := make(LogicalIndex, NumDimensions)
367 other := make(LogicalIndex, NumDimensions)
369 planet := data.i2p[addr[Location]]
372 if addr[Traded] == 0 { /* Can't have traded immediately after traveling. */
373 other[Traded] = 1 /* Travel from states that have done trading. */
375 /* Travel here via a 2-fuel unit jump */
376 if data.Planets[data.i2p[addr[Location]]].BeaconOn && addr[Fuel]+2 < dims[Fuel] {
377 other[Fuel] = addr[Fuel] + 2
378 hole_index := (dims[Fuel] - 1) - (addr[Fuel] + 2)
379 if hole_index >= len(flight_plan()) || addr[Location] != PlanetIndex(data, flight_plan()[hole_index]) {
380 for other[Location] = 0; other[Location] < dims[Location]; other[Location]++ {
381 Consider(data, dims, table, other, 0, &best_value, best_source)
384 other[Location] = addr[Location]
385 other[Fuel] = addr[Fuel]
388 /* Travel here via a 1-fuel unit jump (a hyper hole) */
389 if addr[Fuel]+1 < dims[Fuel] {
390 hole_index := (dims[Fuel] - 1) - (addr[Fuel] + 1)
391 if hole_index < len(flight_plan()) && addr[Location] == PlanetIndex(data, flight_plan()[hole_index]) {
392 other[Fuel] = addr[Fuel] + 1
393 for other[Location] = 0; other[Location] < dims[Location]; other[Location]++ {
394 Consider(data, dims, table, other, 0, &best_value, best_source)
396 other[Location] = addr[Location]
397 other[Fuel] = addr[Fuel]
401 /* Travel here via Eden Warp Unit */
402 if addr[Edens]+1 < dims[Edens] && (addr[Hold] == 0 || addr[UnusedCargo] > 0) {
403 _, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Eden Warp Units"]
405 other[Edens] = addr[Edens] + 1
406 if other[Hold] != 0 {
407 other[UnusedCargo] = addr[UnusedCargo] - 1
409 for other[Location] = 0; other[Location] < dims[Location]; other[Location]++ {
410 Consider(data, dims, table, other, 0, &best_value, best_source)
412 other[Location] = addr[Location]
413 other[UnusedCargo] = addr[UnusedCargo]
414 other[Edens] = addr[Edens]
417 other[Traded] = addr[Traded]
421 if addr[Traded] == 1 {
424 /* Consider not trading */
425 Consider(data, dims, table, other, 0, &best_value, best_source)
427 if !data.Planets[data.i2p[addr[Location]]].Private {
430 if addr[Hold] == 0 && addr[UnusedCargo] == 0 {
431 for other[Hold] = 0; other[Hold] < dims[Hold]; other[Hold]++ {
432 commodity := data.i2c[other[Hold]]
433 if !data.Commodities[commodity].CanSell {
436 relative_price, available := data.Planets[planet].RelativePrices[commodity]
441 base_price := data.Commodities[commodity].BasePrice
442 absolute_price := float64(base_price) * float64(relative_price) / 100.0
443 sell_price := int(absolute_price * 0.9)
445 for other[UnusedCargo] = 0; other[UnusedCargo] < dims[UnusedCargo]; other[UnusedCargo]++ {
446 quantity := *hold - (other[UnusedCargo] + other[Cloaks] + other[Edens])
447 sale_value := quantity * sell_price
448 Consider(data, dims, table, other, sale_value, &best_value, best_source)
451 other[UnusedCargo] = addr[UnusedCargo]
452 other[Hold] = addr[Hold]
456 other[Traded] = addr[Traded] /* Buy after selling */
458 commodity := data.i2c[addr[Hold]]
459 if data.Commodities[commodity].CanSell {
460 relative_price, available := data.Planets[planet].RelativePrices[commodity]
462 base_price := data.Commodities[commodity].BasePrice
463 absolute_price := int(float64(base_price) * float64(relative_price) / 100.0)
464 quantity := *hold - (addr[UnusedCargo] + addr[Cloaks] + addr[Edens])
465 total_price := quantity * absolute_price
467 other[UnusedCargo] = 0
468 Consider(data, dims, table, other, -total_price, &best_value, best_source)
469 other[UnusedCargo] = addr[UnusedCargo]
470 other[Hold] = addr[Hold]
475 other[Traded] = addr[Traded]
478 /* Buy a Device of Cloaking */
479 if addr[Cloaks] == 1 && addr[UnusedCargo] < dims[UnusedCargo]-1 {
480 relative_price, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Device Of Cloakings"]
482 absolute_price := int(float64(data.Commodities["Device Of Cloakings"].BasePrice) * float64(relative_price) / 100.0)
484 if other[Hold] != 0 {
485 other[UnusedCargo] = addr[UnusedCargo] + 1
487 Consider(data, dims, table, other, -absolute_price, &best_value, best_source)
488 other[UnusedCargo] = addr[UnusedCargo]
489 other[Cloaks] = addr[Cloaks]
493 /* Buy Fighter Drones */
494 if addr[BuyFighters] == 1 {
495 relative_price, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Fighter Drones"]
497 absolute_price := int(float64(data.Commodities["Fighter Drones"].BasePrice) * float64(relative_price) / 100.0)
498 other[BuyFighters] = 0
499 Consider(data, dims, table, other, -absolute_price**drones, &best_value, best_source)
500 other[BuyFighters] = addr[BuyFighters]
504 /* Buy Shield Batteries */
505 if addr[BuyShields] == 1 {
506 relative_price, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Shield Batterys"]
508 absolute_price := int(float64(data.Commodities["Shield Batterys"].BasePrice) * float64(relative_price) / 100.0)
509 other[BuyShields] = 0
510 Consider(data, dims, table, other, -absolute_price**batteries, &best_value, best_source)
511 other[BuyShields] = addr[BuyShields]
515 /* Visit this planet */
516 for i := uint(0); i < uint(len(visit())); i++ {
517 if addr[Visit]&(1<<i) != 0 && visit()[i] == data.i2p[addr[Location]] {
518 other[Visit] = addr[Visit] & ^(1 << i)
519 Consider(data, dims, table, other, 0, &best_value, best_source)
522 other[Visit] = addr[Visit]
524 /* Buy Eden warp units */
525 eden_limit := data.Commodities["Eden Warp Units"].Limit
526 if addr[Edens] > 0 && addr[Edens] <= eden_limit {
527 relative_price, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Eden Warp Units"]
529 absolute_price := int(float64(data.Commodities["Eden Warp Units"].BasePrice) * float64(relative_price) / 100.0)
530 for quantity := addr[Edens]; quantity > 0; quantity-- {
531 other[Edens] = addr[Edens] - quantity
533 other[UnusedCargo] = addr[UnusedCargo] + quantity
535 if other[UnusedCargo] < dims[UnusedCargo] {
536 Consider(data, dims, table, other, -absolute_price*quantity, &best_value, best_source)
539 other[Edens] = addr[Edens]
540 other[UnusedCargo] = addr[UnusedCargo]
544 // Check that we didn't lose track of any temporary modifications to other.
545 for i := 0; i < NumDimensions; i++ {
546 if addr[i] != other[i] {
551 // Sanity check: This cell was in state BEING_EVALUATED
552 // the whole time that it was being evaluated.
553 if table[my_index].value != VALUE_BEING_EVALUATED {
557 // Record our findings
558 table[my_index].value = best_value
559 table[my_index].from = EncodeIndex(dims, best_source)
563 if cell_filled_count&0xfff == 0 {
564 print(fmt.Sprintf("\r%3.1f%%", 100*float64(cell_filled_count)/float64(StateTableSize(dims))))
567 return table[my_index].value
570 func FinalState(dims LogicalIndex) LogicalIndex {
571 addr := make(LogicalIndex, NumDimensions)
572 addr[Edens] = *end_edens
573 addr[Cloaks] = dims[Cloaks] - 1
574 addr[BuyFighters] = dims[BuyFighters] - 1
575 addr[BuyShields] = dims[BuyShields] - 1
576 addr[Visit] = dims[Visit] - 1
579 addr[UnusedCargo] = 0
580 // Fuel and Location are determined by FindBestState
584 func FindBestState(data planet_data, dims LogicalIndex, table []State, addr LogicalIndex) PhysicalIndex {
585 max_index := PhysicalIndex(-1)
591 for addr[Fuel] = 0; addr[Fuel] <= max_fuel; addr[Fuel]++ {
592 for addr[Location] = 0; addr[Location] < dims[Location]; addr[Location]++ {
593 planet := data.i2p[addr[Location]]
594 if len(end()) == 0 || end()[planet] {
595 index := EncodeIndex(dims, addr)
596 today_value := CellValue(data, dims, table, addr)
597 tomorrow_value := *tomorrow_weight * float64(*hold+data.Planets[planet].TomorrowValue)
598 value := float64(today_value) + tomorrow_value
599 if value > max_value {
609 func Commas(n Value) string {
617 s = fmt.Sprintf(",%03d", r) + s
621 s = fmt.Sprint(r) + s
625 func FighterAndShieldCost(data planet_data, dims LogicalIndex, table []State, best PhysicalIndex) {
626 if *drones == 0 && *batteries == 0 {
631 final_state := FinalState(dims)
632 final_state[BuyFighters] = 0
633 alt_best := FindBestState(data, dims, table, final_state)
634 cost := table[alt_best].value - table[best].value
635 fmt.Printf("\rDrones were %.2f each\n", float64(cost)/float64(*drones))
638 final_state := FinalState(dims)
639 final_state[BuyShields] = 0
640 alt_best := FindBestState(data, dims, table, final_state)
641 cost := table[alt_best].value - table[best].value
642 fmt.Printf("\rBatteries were %.2f each\n", float64(cost)/float64(*batteries))
646 func EndEdensCost(data planet_data, dims LogicalIndex, table []State, best PhysicalIndex) {
651 final_state := FinalState(dims)
652 for extra_edens := 1; extra_edens <= *end_edens; extra_edens++ {
653 final_state[Edens] = *end_edens - extra_edens
654 alt_best := FindBestState(data, dims, table, final_state)
655 extra_funds := table[alt_best].value - table[best].value
656 fmt.Println("\rUse", extra_edens, "extra edens, make an extra",
657 Commas(extra_funds), "(",
658 Commas(extra_funds/Value(extra_edens)), "per eden)")
662 func VisitCost(data planet_data, dims LogicalIndex, table []State, best PhysicalIndex) {
663 if dims[Visit] == 1 {
667 final_state := FinalState(dims)
668 for i := uint(0); i < uint(len(visit())); i++ {
669 all_bits := dims[Visit] - 1
670 final_state[Visit] = all_bits & ^(1 << i)
671 alt_best := FindBestState(data, dims, table, final_state)
672 cost := table[alt_best].value - table[best].value
673 fmt.Printf("\r%11v Cost to visit %v\n", Commas(cost), visit()[i])
677 func EndLocationCost(data planet_data, dims LogicalIndex, table []State, best PhysicalIndex) {
682 final_state := FinalState(dims)
683 save_end_string := *end_string
686 alt_best := FindBestState(data, dims, table, final_state)
687 cost := table[alt_best].value - table[best].value
688 fmt.Printf("\r%11v Cost of --end %v\n", Commas(cost), save_end_string)
689 *end_string = save_end_string
692 func DescribePath(data planet_data, dims LogicalIndex, table []State, start PhysicalIndex) []string {
693 var description []string
694 for index := start; table[index].from > FROM_ROOT; index = table[index].from {
695 if table[index].from == FROM_UNINITIALIZED {
699 addr := DecodeIndex(dims, index)
700 prev := DecodeIndex(dims, table[index].from)
701 if addr[Fuel] != prev[Fuel] {
702 from := data.i2p[prev[Location]]
703 to := data.i2p[addr[Location]]
704 line += fmt.Sprintf("Jump from %v to %v (%v hyper jump units)", from, to, prev[Fuel]-addr[Fuel])
706 if addr[Edens] == prev[Edens]-1 {
707 from := data.i2p[prev[Location]]
708 to := data.i2p[addr[Location]]
709 line += fmt.Sprintf("Eden warp from %v to %v", from, to)
711 if addr[Hold] != prev[Hold] {
713 quantity := *hold - (prev[UnusedCargo] + prev[Edens] + prev[Cloaks])
714 line += fmt.Sprintf("Sell %v %v", quantity, data.i2c[prev[Hold]])
715 } else if prev[Hold] == 0 {
716 quantity := *hold - (addr[UnusedCargo] + addr[Edens] + addr[Cloaks])
717 line += fmt.Sprintf("Buy %v %v", quantity, data.i2c[addr[Hold]])
719 panic("Switched cargo?")
723 if addr[Cloaks] == 1 && prev[Cloaks] == 0 {
724 // TODO: Dump cloaks, convert from cargo?
725 line += "Buy a Cloak"
727 if addr[Edens] > prev[Edens] {
728 line += fmt.Sprint("Buy ", addr[Edens]-prev[Edens], " Eden Warp Units")
730 if addr[BuyShields] == 1 && prev[BuyShields] == 0 {
731 line += fmt.Sprint("Buy ", *batteries, " Shield Batterys")
733 if addr[BuyFighters] == 1 && prev[BuyFighters] == 0 {
734 line += fmt.Sprint("Buy ", *drones, " Fighter Drones")
736 if addr[Visit] != prev[Visit] {
737 // TODO: verify that the bit chat changed is addr[Location]
738 line += fmt.Sprint("Visit ", data.i2p[addr[Location]])
740 if line == "" && addr[Hold] == prev[Hold] && addr[Traded] != prev[Traded] {
741 // The Traded dimension is for housekeeping. It doesn't directly
742 // correspond to in-game actions, so don't report transitions.
746 line = fmt.Sprint(prev, " -> ", addr)
748 description = append(description, fmt.Sprintf("%13v ", Commas(table[index].value))+line)
753 // (Example of a use case for generics in Go)
754 func IndexPlanets(m *map[string]Planet, start_at int) (map[string]int, []string) {
755 e2i := make(map[string]int, len(*m)+start_at)
756 i2e := make([]string, len(*m)+start_at)
765 func IndexCommodities(m *map[string]Commodity, start_at int) (map[string]int, []string) {
766 e2i := make(map[string]int, len(*m)+start_at)
767 i2e := make([]string, len(*m)+start_at)
779 if *start == "" || *funds == 0 {
780 print("--start and --funds are required. --help for more\n")
783 if *cpuprofile != "" {
784 f, err := os.Create(*cpuprofile)
788 pprof.StartCPUProfile(f)
789 defer pprof.StopCPUProfile()
792 if *drone_price > 0 {
793 temp := data.Commodities["Fighter Drones"]
794 temp.BasePrice = *drone_price
795 data.Commodities["Fighter Drones"] = temp
797 if *battery_price > 0 {
798 temp := data.Commodities["Shield Batterys"]
799 temp.BasePrice = *battery_price
800 data.Commodities["Shield Batterys"] = temp
802 data.p2i, data.i2p = IndexPlanets(&data.Planets, 0)
803 data.c2i, data.i2c = IndexCommodities(&data.Commodities, 1)
804 dims := DimensionSizes(data)
805 table := CreateStateTable(data, dims)
806 final_state := FinalState(dims)
807 best := FindBestState(data, dims, table, final_state)
810 print("Cannot achieve success criteria\n")
813 description := DescribePath(data, dims, table, best)
814 for i := len(description) - 1; i >= 0; i-- {
815 fmt.Println(description[i])
819 FighterAndShieldCost(data, dims, table, best)
820 EndEdensCost(data, dims, table, best)
821 VisitCost(data, dims, table, best)
822 EndLocationCost(data, dims, table, best)