-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.go
More file actions
75 lines (62 loc) · 1.7 KB
/
simulator.go
File metadata and controls
75 lines (62 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"github.com/Pyroarsonist/map-gonerator/helpers"
)
type Hero struct {
coordinate TileCoordinate
hp int
}
type Trip struct {
hero Hero
destination TileCoordinate
day int
tileMap TileMap
}
func (tileMap TileMap) createRandomTrip(maxHP int) Trip {
r := helpers.GetRandomGenerator()
heroCoordinate := tileMap.GetRandomCoordinate()
destinationCoordinate := tileMap.GetRandomCoordinate()
for {
if !(destinationCoordinate.width == heroCoordinate.width && destinationCoordinate.height == heroCoordinate.height) {
break
}
destinationCoordinate = tileMap.GetRandomCoordinate()
}
return Trip{
hero: Hero{
coordinate: heroCoordinate,
hp: r.Intn(maxHP),
},
destination: destinationCoordinate,
day: 0,
tileMap: tileMap,
}
}
func simulateTrip(tileMap TileMap, config Config) {
fmt.Println("Simulating trip...")
trip := tileMap.createRandomTrip(config.maxHP)
trip.start()
}
func (trip *Trip) cleanupTrip() {
tileMap := trip.tileMap
tileMap[trip.hero.coordinate.height][trip.hero.coordinate.width].setHeroStartLocation()
tileMap[trip.destination.height][trip.destination.width].setDestinationPresence()
}
func (trip *Trip) start() {
trip.cleanupTrip()
renderedMapString := trip.tileMap.RenderedMap().convertRenderedMapToString()
printToConsole(renderedMapString)
fmt.Println("Starting trip")
trip.simulateWithAlgorithm(Greedy)
renderedMapString = trip.tileMap.RenderedMap().convertRenderedMapToString()
printToConsole(renderedMapString)
fmt.Println("Days gone:", trip.day)
fmt.Println("HP remaining:", trip.hero.hp)
}
func (hero *Hero) hpLoss(value int) {
hero.hp -= value
if hero.hp < 0 {
hero.hp = 0
}
}