/
mineorea.go
74 lines (56 loc) · 1.23 KB
/
mineorea.go
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
package mineorea
import (
"fmt"
"math/rand"
"time"
"sync"
"github.com/manveru/faker"
)
var wg sync.WaitGroup
var gridX int = 10
var gridY int = 10
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
type mineorea struct {
miners int
}
func Server() *mineorea {
return &mineorea{}
}
func newFaker() *faker.Faker {
fake, _ := faker.New("en")
fake.Rand = rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
return fake
}
func (m mineorea) Run() {
nm := rand.Intn(5)
fmt.Println("Resource Sim 0.0.1\n")
miners := make([]*miner, nm)
for i := range miners {
miners[i] = Miner()
wg.Add(1)
fmt.Printf("Miner %v away! Miner has %v kg Capacity.\n", miners[i].name, miners[i].currentStorageCapacity())
// @TODO: Pass a grid and a market into the miners so they can mine the grid clean
go miners[i].mineUntilFull(coal{})
}
wg.Wait()
fmt.Println("\nMining complete!")
}
func seedGrid() [][]resource {
grid := make([][]resource, gridX)
fmt.Println("Seeding Grid")
for x := 0; x < gridX; x++ {
grid[x] = make([]resource, gridY)
for y := 0; y < gridY; y++ {
resource := rand.Intn(4)
if resource > 1 {
grid[x][y] = coal{}
} else {
grid[x][y] = nil
}
}
fmt.Println(grid[x])
}
return grid
}