krampus19/soko/entity.go
Sander Schobers 365e9dbbbb Added solver & optimized state.
Positions are kept by index only.
2020-01-16 07:33:04 +01:00

49 lines
646 B
Go

package soko
type Entity struct {
ID int
Pos int
Typ EntityType
}
type Entities []Entity
func (e Entities) ByID(id int) Entity {
idx := e.IdxById(id)
if idx == -1 {
return Entity{ID: -1}
}
return e[idx]
}
func (e Entities) Clone() Entities {
clone := make(Entities, len(e))
copy(clone, e)
return clone
}
func (e Entities) IdxById(id int) int {
for i, e := range e {
if e.ID == id {
return i
}
}
return -1
}
type Ints []int
func NewInts(n int) Ints {
ids := make(Ints, n)
for i := range ids {
ids[i] = -1
}
return ids
}
func (e Ints) Clone() Ints {
clone := make(Ints, len(e))
copy(clone, e)
return clone
}