/
arena.go
61 lines (50 loc) · 1.07 KB
/
arena.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
package tron
import (
"fmt"
)
type motoPosition map[Color]Square
type arena struct {
moto map[Color]Moto
pos motoPosition
squares [][]Square
winner Moto
}
//Loop on each moto. Determine where they are going next
// If two moto collide, crash them both
// If the next position is colored, crash
// Else, color it
//If a moto crashed, remove it's color line
func (a arena) ProcessTurn() error {
fmt.Println("Processing turn!")
// for c, m := range a.moto {
// }
return nil
}
func (a arena) Join(m Moto) error {
if _, found := a.moto[m.Color()]; !found {
a.moto[m.Color()] = m
return nil
} else {
return fmt.Errorf("Moto %s already exist in this arena", m.Color())
}
}
func (a arena) MotoCount() int {
return len(a.moto)
}
func (a arena) Winner() Moto {
return a.winner
}
func NewArena(size int) Arena {
a := arena{
moto: map[Color]Moto{},
pos: motoPosition{},
squares: make([][]Square, size),
}
for x := 0; x < size; x++ {
a.squares[x] = make([]Square, size)
for y := 0; y < size; y++ {
a.squares[x][y] = newSquare(x, y)
}
}
return a
}