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, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 import "encoding/json"
24 import "runtime/pprof"
27 var funds = flag.Int("funds", 0,
30 var start = flag.String("start", "",
31 "The planet to start at")
33 var flight_plan_string = flag.String("flight_plan", "",
34 "Your hyper-holes for the day, comma-separated.")
36 var end_string = flag.String("end", "",
37 "A comma-separated list of acceptable ending planets.")
39 var planet_data_file = flag.String("planet_data_file", "planet-data",
40 "The file to read planet data from")
42 var fuel = flag.Int("fuel", 16, "Hyper Jump power left")
44 var hold = flag.Int("hold", 300, "Size of your cargo hold")
46 var start_hold = flag.String("start_hold", "", "Start with a hold full of cargo")
48 var start_edens = flag.Int("start_edens", 0,
49 "How many Eden Warp Units are you starting with?")
51 var end_edens = flag.Int("end_edens", 0,
52 "How many Eden Warp Units would you like to keep (not use)?")
54 var cloak = flag.Bool("cloak", false,
55 "Make sure to end with a Device of Cloaking")
57 var drones = flag.Int("drones", 0, "Buy this many Fighter Drones")
59 var batteries = flag.Int("batteries", 0, "Buy this many Shield Batterys")
61 var drone_price = flag.Int("drone_price", 0, "Today's Fighter Drone price")
63 var battery_price = flag.Int("battery_price", 0, "Today's Shield Battery price")
65 var visit_string = flag.String("visit", "",
66 "A comma-separated list of planets to make sure to visit")
68 var tomorrow_weight = flag.Float64("tomorrow_weight", 1.0,
69 "Weight for the expected value of tomorrow's trading. 0.0 - 1.0")
71 var extra_stats = flag.Bool("extra_stats", true,
72 "Show additional information of possible interest")
74 var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
76 var visit_cache []string
78 func visit() []string {
79 if visit_cache == nil {
80 if *visit_string == "" {
83 visit_cache = strings.Split(*visit_string, ",")
88 var flight_plan_cache []string
90 func flight_plan() []string {
91 if flight_plan_cache == nil {
92 if *flight_plan_string == "" {
95 flight_plan_cache = strings.Split(*flight_plan_string, ",")
97 return flight_plan_cache
100 var end_cache map[string]bool
102 func end() map[string]bool {
103 if end_cache == nil {
104 if *end_string == "" {
107 m := make(map[string]bool)
108 for _, p := range strings.Split(*end_string, ",") {
116 type Commodity struct {
125 /* Use relative prices rather than absolute prices because you
126 can get relative prices without traveling to each planet. */
127 RelativePrices map[string]int
129 type planet_data struct {
130 Commodities map[string]Commodity
131 Planets map[string]Planet
132 p2i, c2i map[string]int // Generated; not read from file
133 i2p, i2c []string // Generated; not read from file
136 func json_slurp(filename string, receptacle interface{}) error {
137 f, err := os.Open(filename)
142 err = json.NewDecoder(f).Decode(receptacle)
149 func ReadData() planet_data {
151 err := json_slurp(*planet_data_file, &data)
158 /* This program operates by filling in a state table representing the best
159 * possible trips you could make; the ones that makes you the most money.
160 * This is feasible because we don't look at all the possible trips.
161 * We define a list of things that are germane to this game and then only
162 * consider the best outcome in each possible game state.
164 * Each cell in the table represents a state in the game. In each cell,
165 * we track two things: 1. the most money you could possibly have while in
166 * that state and 2. one possible way to get into that state with that
169 * A basic analysis can be done with a two-dimensional table: location and
170 * fuel. planeteer-1.0 used this two-dimensional table. This version
171 * adds features mostly by adding dimensions to this table.
173 * Note that the sizes of each dimension are data driven. Many dimensions
174 * collapse to one possible value (ie, disappear) if the corresponding
175 * feature is not enabled.
177 * The order of the dimensions in the list of constants below determines
178 * their layout in RAM. The cargo-based 'dimensions' are not completely
179 * independent -- some combinations are illegal and not used. They are
180 * handled as three dimensions rather than one for simplicity. Placing
181 * these dimensions first causes the unused cells in the table to be
182 * grouped together in large blocks. This keeps the unused cells from
183 * polluting cache lines, and if the spans of unused cells are large
184 * enough, allows the memory manager to swap out entire pages.
186 * If the table gets too big to fit in RAM:
187 * * Combine the Edens, Cloaks, and UnusedCargo dimensions. Of the
188 * 24 combinations, only 15 are legal: a 38% savings.
189 * * Reduce the size of the Fuel dimension to 3. Explicit iteration
190 * only ever needs to look backwards 2 units, so the logical values
191 * can rotate through the same 3 physical addresses. This would be
192 * good for an 82% savings. Note that explicit iteration went away
194 * * Reduce the size of the Edens dimension from 3 to 2, for the
195 * same reasons as Fuel above. 33% savings.
196 * * Buy more ram. (Just sayin'. It's cheaper than you think.)
200 // The official list of dimensions:
202 // Name Num Size Description
203 Edens = iota // 1 3 # of Eden warp units (0 - 2 typically)
204 Cloaks // 2 1-2 # of Devices of Cloaking (0 or 1)
205 UnusedCargo // 3 4 # of unused cargo spaces (0 - 3 typically)
206 Fuel // 4 17 Hyper jump power left (0 - 16)
207 Location // 5 26 Location (which planet)
208 Hold // 6 15 Cargo bay contents (a *Commodity or nil)
209 Traded // 7 2 Traded yet?
210 BuyFighters // 8 1-2 Errand: Buy fighter drones
211 BuyShields // 9 1-2 Errand: Buy shield batteries
212 Visit // 10 1-2**N Visit: Stop by these N planets in the route
217 func bint(b bool) int {
224 func DimensionSizes(data planet_data) LogicalIndex {
225 eden_capacity := data.Commodities["Eden Warp Units"].Limit
226 if *start_edens > eden_capacity {
227 eden_capacity = *start_edens
229 cloak_capacity := bint(*cloak)
230 dims := make(LogicalIndex, NumDimensions)
231 dims[Edens] = eden_capacity + 1
232 dims[Cloaks] = cloak_capacity + 1
233 dims[UnusedCargo] = eden_capacity + cloak_capacity + 1
234 dims[Fuel] = *fuel + 1
235 dims[Location] = len(data.Planets)
236 dims[Hold] = len(data.Commodities) + 1
238 dims[BuyFighters] = bint(*drones > 0) + 1
239 dims[BuyShields] = bint(*batteries > 0) + 1
240 dims[Visit] = 1 << uint(len(visit()))
242 // Remind myself to add a line above when adding new dimensions
243 for i, dim := range dims {
252 type PhysicalIndex int32
253 type LogicalIndex []int
255 func StateTableSize(dims LogicalIndex) int {
257 for _, size := range dims {
269 FROM_ROOT = -2147483647 + iota
272 VALUE_BEING_EVALUATED
276 func EncodeIndex(dims, addr LogicalIndex) PhysicalIndex {
278 if addr[0] > dims[0] {
281 for i := 1; i < NumDimensions; i++ {
282 if addr[i] < 0 || addr[i] >= dims[i] {
285 index = index*dims[i] + addr[i]
287 return PhysicalIndex(index)
290 func DecodeIndex(dims LogicalIndex, index PhysicalIndex) LogicalIndex {
291 scratch := int(index)
292 addr := make(LogicalIndex, NumDimensions)
293 for i := NumDimensions - 1; i > 0; i-- {
294 addr[i] = scratch % dims[i]
301 func PlanetIndex(data planet_data, name string) int {
302 index, ok := data.p2i[name]
304 panic("Unknown planet " + name)
309 func CommodityIndex(data planet_data, name string) int {
310 index, ok := data.c2i[name]
312 panic("Unknown commodity " + name)
317 func CreateStateTable(data planet_data, dims LogicalIndex) []State {
318 table := make([]State, StateTableSize(dims))
319 for i := range table {
320 table[i].value = VALUE_UNINITIALIZED
321 table[i].from = FROM_UNINITIALIZED
324 addr := make(LogicalIndex, NumDimensions)
326 addr[Edens] = *start_edens
327 addr[Location] = PlanetIndex(data, *start)
328 if *start_hold != "" {
329 addr[Hold] = CommodityIndex(data, *start_hold)
331 start_index := EncodeIndex(dims, addr)
332 table[start_index].value = Value(*funds)
333 table[start_index].from = FROM_ROOT
338 /* CellValue fills in the one cell at address addr by looking at all
339 * the possible ways to reach this cell and selecting the best one. */
341 func Consider(data planet_data, dims LogicalIndex, table []State, there LogicalIndex, value_difference int, best_value *Value, best_source LogicalIndex) {
342 there_value := CellValue(data, dims, table, there)
343 if value_difference < 0 && Value(-value_difference) > there_value {
344 /* Can't afford this transition */
347 possible_value := there_value + Value(value_difference)
348 if possible_value > *best_value {
349 *best_value = possible_value
350 copy(best_source, there)
354 var cell_filled_count int
356 func CellValue(data planet_data, dims LogicalIndex, table []State, addr LogicalIndex) Value {
357 my_index := EncodeIndex(dims, addr)
358 if table[my_index].value == VALUE_BEING_EVALUATED {
359 panic("Circular dependency")
361 if table[my_index].value != VALUE_UNINITIALIZED {
362 return table[my_index].value
364 table[my_index].value = VALUE_BEING_EVALUATED
366 best_value := Value(VALUE_RUBISH)
367 best_source := make(LogicalIndex, NumDimensions)
368 other := make(LogicalIndex, NumDimensions)
370 planet := data.i2p[addr[Location]]
373 if addr[Traded] == 0 { /* Can't have traded immediately after traveling. */
374 other[Traded] = 1 /* Travel from states that have done trading. */
376 /* Travel here via a 2-fuel unit jump */
377 if data.Planets[data.i2p[addr[Location]]].BeaconOn && addr[Fuel]+2 < dims[Fuel] {
378 other[Fuel] = addr[Fuel] + 2
379 hole_index := (dims[Fuel] - 1) - (addr[Fuel] + 2)
380 if hole_index >= len(flight_plan()) || addr[Location] != PlanetIndex(data, flight_plan()[hole_index]) {
381 for other[Location] = 0; other[Location] < dims[Location]; other[Location]++ {
382 Consider(data, dims, table, other, 0, &best_value, best_source)
385 other[Location] = addr[Location]
386 other[Fuel] = addr[Fuel]
389 /* Travel here via a 1-fuel unit jump (a hyper hole) */
390 if addr[Fuel]+1 < dims[Fuel] {
391 hole_index := (dims[Fuel] - 1) - (addr[Fuel] + 1)
392 if hole_index < len(flight_plan()) && addr[Location] == PlanetIndex(data, flight_plan()[hole_index]) {
393 other[Fuel] = addr[Fuel] + 1
394 for other[Location] = 0; other[Location] < dims[Location]; other[Location]++ {
395 Consider(data, dims, table, other, 0, &best_value, best_source)
397 other[Location] = addr[Location]
398 other[Fuel] = addr[Fuel]
402 /* Travel here via Eden Warp Unit */
403 if addr[Edens]+1 < dims[Edens] && (addr[Hold] == 0 || addr[UnusedCargo] > 0) {
404 _, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Eden Warp Units"]
406 other[Edens] = addr[Edens] + 1
407 if other[Hold] != 0 {
408 other[UnusedCargo] = addr[UnusedCargo] - 1
410 for other[Location] = 0; other[Location] < dims[Location]; other[Location]++ {
411 Consider(data, dims, table, other, 0, &best_value, best_source)
413 other[Location] = addr[Location]
414 other[UnusedCargo] = addr[UnusedCargo]
415 other[Edens] = addr[Edens]
418 other[Traded] = addr[Traded]
422 if addr[Traded] == 1 {
425 /* Consider not trading */
426 Consider(data, dims, table, other, 0, &best_value, best_source)
428 if !data.Planets[data.i2p[addr[Location]]].Private {
431 if addr[Hold] == 0 && addr[UnusedCargo] == 0 {
432 for other[Hold] = 0; other[Hold] < dims[Hold]; other[Hold]++ {
433 commodity := data.i2c[other[Hold]]
434 if !data.Commodities[commodity].CanSell {
437 relative_price, available := data.Planets[planet].RelativePrices[commodity]
442 base_price := data.Commodities[commodity].BasePrice
443 absolute_price := float64(base_price) * float64(relative_price) / 100.0
444 sell_price := int(absolute_price * 0.9)
446 for other[UnusedCargo] = 0; other[UnusedCargo] < dims[UnusedCargo]; other[UnusedCargo]++ {
447 quantity := *hold - (other[UnusedCargo] + other[Cloaks] + other[Edens])
448 sale_value := quantity * sell_price
449 Consider(data, dims, table, other, sale_value, &best_value, best_source)
452 other[UnusedCargo] = addr[UnusedCargo]
453 other[Hold] = addr[Hold]
457 other[Traded] = addr[Traded] /* Buy after selling */
459 commodity := data.i2c[addr[Hold]]
460 if data.Commodities[commodity].CanSell {
461 relative_price, available := data.Planets[planet].RelativePrices[commodity]
463 base_price := data.Commodities[commodity].BasePrice
464 absolute_price := int(float64(base_price) * float64(relative_price) / 100.0)
465 quantity := *hold - (addr[UnusedCargo] + addr[Cloaks] + addr[Edens])
466 total_price := quantity * absolute_price
468 other[UnusedCargo] = 0
469 Consider(data, dims, table, other, -total_price, &best_value, best_source)
470 other[UnusedCargo] = addr[UnusedCargo]
471 other[Hold] = addr[Hold]
476 other[Traded] = addr[Traded]
479 /* Buy a Device of Cloaking */
480 if addr[Cloaks] == 1 && addr[UnusedCargo] < dims[UnusedCargo]-1 {
481 relative_price, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Device Of Cloakings"]
483 absolute_price := int(float64(data.Commodities["Device Of Cloakings"].BasePrice) * float64(relative_price) / 100.0)
485 if other[Hold] != 0 {
486 other[UnusedCargo] = addr[UnusedCargo] + 1
488 Consider(data, dims, table, other, -absolute_price, &best_value, best_source)
489 other[UnusedCargo] = addr[UnusedCargo]
490 other[Cloaks] = addr[Cloaks]
494 /* Buy Fighter Drones */
495 if addr[BuyFighters] == 1 {
496 relative_price, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Fighter Drones"]
498 absolute_price := int(float64(data.Commodities["Fighter Drones"].BasePrice) * float64(relative_price) / 100.0)
499 other[BuyFighters] = 0
500 Consider(data, dims, table, other, -absolute_price**drones, &best_value, best_source)
501 other[BuyFighters] = addr[BuyFighters]
505 /* Buy Shield Batteries */
506 if addr[BuyShields] == 1 {
507 relative_price, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Shield Batterys"]
509 absolute_price := int(float64(data.Commodities["Shield Batterys"].BasePrice) * float64(relative_price) / 100.0)
510 other[BuyShields] = 0
511 Consider(data, dims, table, other, -absolute_price**batteries, &best_value, best_source)
512 other[BuyShields] = addr[BuyShields]
516 /* Visit this planet */
517 for i := uint(0); i < uint(len(visit())); i++ {
518 if addr[Visit]&(1<<i) != 0 && visit()[i] == data.i2p[addr[Location]] {
519 other[Visit] = addr[Visit] & ^(1 << i)
520 Consider(data, dims, table, other, 0, &best_value, best_source)
523 other[Visit] = addr[Visit]
525 /* Buy Eden warp units */
526 eden_limit := data.Commodities["Eden Warp Units"].Limit
527 if addr[Edens] > 0 && addr[Edens] <= eden_limit {
528 relative_price, available := data.Planets[data.i2p[addr[Location]]].RelativePrices["Eden Warp Units"]
530 absolute_price := int(float64(data.Commodities["Eden Warp Units"].BasePrice) * float64(relative_price) / 100.0)
531 for quantity := addr[Edens]; quantity > 0; quantity-- {
532 other[Edens] = addr[Edens] - quantity
534 other[UnusedCargo] = addr[UnusedCargo] + quantity
536 if other[UnusedCargo] < dims[UnusedCargo] {
537 Consider(data, dims, table, other, -absolute_price*quantity, &best_value, best_source)
540 other[Edens] = addr[Edens]
541 other[UnusedCargo] = addr[UnusedCargo]
545 // Check that we didn't lose track of any temporary modifications to other.
546 for i := 0; i < NumDimensions; i++ {
547 if addr[i] != other[i] {
552 // Sanity check: This cell was in state BEING_EVALUATED
553 // the whole time that it was being evaluated.
554 if table[my_index].value != VALUE_BEING_EVALUATED {
558 // Record our findings
559 table[my_index].value = best_value
560 table[my_index].from = EncodeIndex(dims, best_source)
564 if cell_filled_count&0xfff == 0 {
565 print(fmt.Sprintf("\r%3.1f%%", 100*float64(cell_filled_count)/float64(StateTableSize(dims))))
568 return table[my_index].value
571 func FinalState(dims LogicalIndex) LogicalIndex {
572 addr := make(LogicalIndex, NumDimensions)
573 addr[Edens] = *end_edens
574 addr[Cloaks] = dims[Cloaks] - 1
575 addr[BuyFighters] = dims[BuyFighters] - 1
576 addr[BuyShields] = dims[BuyShields] - 1
577 addr[Visit] = dims[Visit] - 1
580 addr[UnusedCargo] = 0
581 // Fuel and Location are determined by FindBestState
585 func FindBestState(data planet_data, dims LogicalIndex, table []State, addr LogicalIndex) PhysicalIndex {
586 max_index := PhysicalIndex(-1)
592 for addr[Fuel] = 0; addr[Fuel] <= max_fuel; addr[Fuel]++ {
593 for addr[Location] = 0; addr[Location] < dims[Location]; addr[Location]++ {
594 planet := data.i2p[addr[Location]]
595 if len(end()) == 0 || end()[planet] {
596 index := EncodeIndex(dims, addr)
597 today_value := CellValue(data, dims, table, addr)
598 tomorrow_value := *tomorrow_weight * float64(*hold+data.Planets[planet].TomorrowValue)
599 value := float64(today_value) + tomorrow_value
600 if value > max_value {
610 func Commas(n Value) string {
618 s = fmt.Sprintf(",%03d", r) + s
622 s = fmt.Sprint(r) + s
626 func FighterAndShieldCost(data planet_data, dims LogicalIndex, table []State, best PhysicalIndex) {
627 if *drones == 0 && *batteries == 0 {
632 final_state := FinalState(dims)
633 final_state[BuyFighters] = 0
634 alt_best := FindBestState(data, dims, table, final_state)
635 cost := table[alt_best].value - table[best].value
636 fmt.Printf("\rDrones were %.2f each\n", float64(cost)/float64(*drones))
639 final_state := FinalState(dims)
640 final_state[BuyShields] = 0
641 alt_best := FindBestState(data, dims, table, final_state)
642 cost := table[alt_best].value - table[best].value
643 fmt.Printf("\rBatteries were %.2f each\n", float64(cost)/float64(*batteries))
647 func EndEdensCost(data planet_data, dims LogicalIndex, table []State, best PhysicalIndex) {
652 final_state := FinalState(dims)
653 for extra_edens := 1; extra_edens <= *end_edens; extra_edens++ {
654 final_state[Edens] = *end_edens - extra_edens
655 alt_best := FindBestState(data, dims, table, final_state)
656 extra_funds := table[alt_best].value - table[best].value
657 fmt.Println("\rUse", extra_edens, "extra edens, make an extra",
658 Commas(extra_funds), "(",
659 Commas(extra_funds/Value(extra_edens)), "per eden)")
663 func VisitCost(data planet_data, dims LogicalIndex, table []State, best PhysicalIndex) {
664 if dims[Visit] == 1 {
668 final_state := FinalState(dims)
669 for i := uint(0); i < uint(len(visit())); i++ {
670 all_bits := dims[Visit] - 1
671 final_state[Visit] = all_bits & ^(1 << i)
672 alt_best := FindBestState(data, dims, table, final_state)
673 cost := table[alt_best].value - table[best].value
674 fmt.Printf("\r%11v Cost to visit %v\n", Commas(cost), visit()[i])
678 func EndLocationCost(data planet_data, dims LogicalIndex, table []State, best PhysicalIndex) {
683 final_state := FinalState(dims)
684 save_end_string := *end_string
687 alt_best := FindBestState(data, dims, table, final_state)
688 cost := table[alt_best].value - table[best].value
689 fmt.Printf("\r%11v Cost of --end %v\n", Commas(cost), save_end_string)
690 *end_string = save_end_string
693 func DescribePath(data planet_data, dims LogicalIndex, table []State, start PhysicalIndex) []string {
694 var description []string
695 for index := start; table[index].from > FROM_ROOT; index = table[index].from {
696 if table[index].from == FROM_UNINITIALIZED {
700 addr := DecodeIndex(dims, index)
701 prev := DecodeIndex(dims, table[index].from)
702 if addr[Fuel] != prev[Fuel] {
703 from := data.i2p[prev[Location]]
704 to := data.i2p[addr[Location]]
705 line += fmt.Sprintf("Jump from %v to %v (%v hyper jump units)", from, to, prev[Fuel]-addr[Fuel])
707 if addr[Edens] == prev[Edens]-1 {
708 from := data.i2p[prev[Location]]
709 to := data.i2p[addr[Location]]
710 line += fmt.Sprintf("Eden warp from %v to %v", from, to)
712 if addr[Hold] != prev[Hold] {
714 quantity := *hold - (prev[UnusedCargo] + prev[Edens] + prev[Cloaks])
715 line += fmt.Sprintf("Sell %v %v", quantity, data.i2c[prev[Hold]])
716 } else if prev[Hold] == 0 {
717 quantity := *hold - (addr[UnusedCargo] + addr[Edens] + addr[Cloaks])
718 line += fmt.Sprintf("Buy %v %v", quantity, data.i2c[addr[Hold]])
720 panic("Switched cargo?")
724 if addr[Cloaks] == 1 && prev[Cloaks] == 0 {
725 // TODO: Dump cloaks, convert from cargo?
726 line += "Buy a Cloak"
728 if addr[Edens] > prev[Edens] {
729 line += fmt.Sprint("Buy ", addr[Edens]-prev[Edens], " Eden Warp Units")
731 if addr[BuyShields] == 1 && prev[BuyShields] == 0 {
732 line += fmt.Sprint("Buy ", *batteries, " Shield Batterys")
734 if addr[BuyFighters] == 1 && prev[BuyFighters] == 0 {
735 line += fmt.Sprint("Buy ", *drones, " Fighter Drones")
737 if addr[Visit] != prev[Visit] {
738 // TODO: verify that the bit chat changed is addr[Location]
739 line += fmt.Sprint("Visit ", data.i2p[addr[Location]])
741 if line == "" && addr[Hold] == prev[Hold] && addr[Traded] != prev[Traded] {
742 // The Traded dimension is for housekeeping. It doesn't directly
743 // correspond to in-game actions, so don't report transitions.
747 line = fmt.Sprint(prev, " -> ", addr)
749 description = append(description, fmt.Sprintf("%13v ", Commas(table[index].value))+line)
754 // (Example of a use case for generics in Go)
755 func IndexPlanets(m *map[string]Planet, start_at int) (map[string]int, []string) {
756 e2i := make(map[string]int, len(*m)+start_at)
757 i2e := make([]string, len(*m)+start_at)
766 func IndexCommodities(m *map[string]Commodity, start_at int) (map[string]int, []string) {
767 e2i := make(map[string]int, len(*m)+start_at)
768 i2e := make([]string, len(*m)+start_at)
780 if *start == "" || *funds == 0 {
781 print("--start and --funds are required. --help for more\n")
784 if *cpuprofile != "" {
785 f, err := os.Create(*cpuprofile)
789 pprof.StartCPUProfile(f)
790 defer pprof.StopCPUProfile()
793 if *drone_price > 0 {
794 temp := data.Commodities["Fighter Drones"]
795 temp.BasePrice = *drone_price
796 data.Commodities["Fighter Drones"] = temp
798 if *battery_price > 0 {
799 temp := data.Commodities["Shield Batterys"]
800 temp.BasePrice = *battery_price
801 data.Commodities["Shield Batterys"] = temp
803 data.p2i, data.i2p = IndexPlanets(&data.Planets, 0)
804 data.c2i, data.i2c = IndexCommodities(&data.Commodities, 1)
805 dims := DimensionSizes(data)
806 table := CreateStateTable(data, dims)
807 final_state := FinalState(dims)
808 best := FindBestState(data, dims, table, final_state)
811 print("Cannot achieve success criteria\n")
814 description := DescribePath(data, dims, table, best)
815 for i := len(description) - 1; i >= 0; i-- {
816 fmt.Println(description[i])
820 FighterAndShieldCost(data, dims, table, best)
821 EndEdensCost(data, dims, table, best)
822 VisitCost(data, dims, table, best)
823 EndLocationCost(data, dims, table, best)