2019-01-15 20:25:32 +00:00
|
|
|
package soko
|
|
|
|
|
|
|
|
type Entity struct {
|
|
|
|
ID int
|
2019-01-16 06:33:04 +00:00
|
|
|
Pos int
|
2019-01-15 20:25:32 +00:00
|
|
|
Typ EntityType
|
|
|
|
}
|
|
|
|
|
2019-01-16 06:33:04 +00:00
|
|
|
type Entities []Entity
|
|
|
|
|
|
|
|
func (e Entities) ByID(id int) Entity {
|
|
|
|
idx := e.IdxById(id)
|
|
|
|
if idx == -1 {
|
|
|
|
return Entity{ID: -1}
|
|
|
|
}
|
|
|
|
return e[idx]
|
|
|
|
}
|
2019-01-15 20:25:32 +00:00
|
|
|
|
|
|
|
func (e Entities) Clone() Entities {
|
2019-01-16 06:33:04 +00:00
|
|
|
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
|
|
|
|
}
|
2019-01-15 20:25:32 +00:00
|
|
|
}
|
2019-01-16 06:33:04 +00:00
|
|
|
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)
|
2019-01-15 20:25:32 +00:00
|
|
|
return clone
|
|
|
|
}
|