-
Notifications
You must be signed in to change notification settings - Fork 1
/
ggol_structs.go
59 lines (46 loc) · 1.95 KB
/
ggol_structs.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
package ggol
import "fmt"
// This error will be thrown when you try to create a new game with invalid size.
type ErrUnitsIsInvalid struct {
}
// Tell you that the size is invalid.
func (e *ErrUnitsIsInvalid) Error() string {
return fmt.Sprintf("Given units is not valid, the cells in every row should be equal.")
}
// This error will be thrown when you're trying to set or get an unit with invalid coordinate.
type ErrCoordinateIsInvalid struct {
Coordinate *Coordinate
}
// Tell you that the coordinate is invalid.
func (e *ErrCoordinateIsInvalid) Error() string {
return fmt.Sprintf("Coordinate (%v, %v) is outside the border.", e.Coordinate.X, e.Coordinate.Y)
}
// This error will be thrown when the X or Y of "from coordinate" is less than X or Y of "to coordinate" in the area.
type ErrAreaIsInvalid struct {
Area *Area
}
func (e *ErrAreaIsInvalid) Error() string {
return fmt.Sprintf("Area with from coordinate (%v, %v) and end coordiante (%v, %v) is not valid.", e.Area.From.X, e.Area.From.Y, e.Area.To.X, e.Area.To.Y)
}
// Coordniate tells you the position of an unit in the game.
type Coordinate struct {
X int
Y int
}
// Area indicates an area within two coordinates.
type Area struct {
From Coordinate
To Coordinate
}
// The size of the game.
type Size struct {
Width int
Height int
}
// This function will be passed into NextUnitGenerator, this is how you can adajcent units in NextUnitGenerator.
// Also, 2nd argument "isCrossBorder" tells you if the adjacent unit is on ohter side of the map.
type AdjacentUnitGetter[T any] func(originCoord *Coordinate, relativeCoord *Coordinate) (unit *T, isCrossBorder bool)
// NextUnitGenerator tells the game how you're gonna generate next status of the given unit.
type NextUnitGenerator[T any] func(coord *Coordinate, unit *T, getAdjacentUnit AdjacentUnitGetter[T]) (nextUnit *T)
// UnitsIteratorCallback will be called when iterating through units.
type UnitsIteratorCallback[T any] func(coord *Coordinate, unit *T)