Loading wator.go +8 −8 Original line number Diff line number Diff line Loading @@ -134,10 +134,10 @@ func (w *Wator) Next() error { c := w.current // fish swim and breed processFishes(w, c, n) processFood(w, c, n) // shark hunt and breed processSharks(w, c, n) processHunters(w, c, n) // do some house keeping... w.last = c Loading @@ -157,7 +157,7 @@ func (w *Wator) position(x int, y int) position { return position{nx, ny} } func fishNeighours(w *Wator, o *Playfield, p position) []position { func foodNeighours(w *Wator, o *Playfield, p position) []position { var eps []position for _, ap := range []position{ w.position(p.x+1, p.y), Loading @@ -172,7 +172,7 @@ func fishNeighours(w *Wator, o *Playfield, p position) []position { return eps } func sharkNeighbours(w *Wator, o *Playfield, p position) ([]position, []position) { func hunterNeighbours(w *Wator, o *Playfield, p position) ([]position, []position) { var fps []position // fish positions var eps []position // empty positions for _, ap := range []position{ Loading @@ -199,11 +199,11 @@ func randomNeighbour(ps []position) (position, bool) { return ps[rand.Intn(l)], true } func processFishes(w *Wator, c *Playfield, n *Playfield) error { func processFood(w *Wator, c *Playfield, n *Playfield) error { for p, f := range c.Food { f.SetAge(f.Age() + 1) var np position eps := fishNeighours(w, c, p) // find empty neighbours eps := foodNeighours(w, c, p) // find empty neighbours ep, moved := randomNeighbour(eps) // randomly select an empty neighbour if moved { np = ep Loading @@ -226,12 +226,12 @@ func processFishes(w *Wator, c *Playfield, n *Playfield) error { return nil } func processSharks(w *Wator, c *Playfield, n *Playfield) error { func processHunters(w *Wator, c *Playfield, n *Playfield) error { for p, s := range c.Hunters { s.SetAge(s.Age() + 1) s.SetAte(s.Ate() + 1) var np position eps, fps := sharkNeighbours(w, c, p) eps, fps := hunterNeighbours(w, c, p) fp, fMoved := randomNeighbour(fps) if fMoved { // shark ate fish Loading Loading
wator.go +8 −8 Original line number Diff line number Diff line Loading @@ -134,10 +134,10 @@ func (w *Wator) Next() error { c := w.current // fish swim and breed processFishes(w, c, n) processFood(w, c, n) // shark hunt and breed processSharks(w, c, n) processHunters(w, c, n) // do some house keeping... w.last = c Loading @@ -157,7 +157,7 @@ func (w *Wator) position(x int, y int) position { return position{nx, ny} } func fishNeighours(w *Wator, o *Playfield, p position) []position { func foodNeighours(w *Wator, o *Playfield, p position) []position { var eps []position for _, ap := range []position{ w.position(p.x+1, p.y), Loading @@ -172,7 +172,7 @@ func fishNeighours(w *Wator, o *Playfield, p position) []position { return eps } func sharkNeighbours(w *Wator, o *Playfield, p position) ([]position, []position) { func hunterNeighbours(w *Wator, o *Playfield, p position) ([]position, []position) { var fps []position // fish positions var eps []position // empty positions for _, ap := range []position{ Loading @@ -199,11 +199,11 @@ func randomNeighbour(ps []position) (position, bool) { return ps[rand.Intn(l)], true } func processFishes(w *Wator, c *Playfield, n *Playfield) error { func processFood(w *Wator, c *Playfield, n *Playfield) error { for p, f := range c.Food { f.SetAge(f.Age() + 1) var np position eps := fishNeighours(w, c, p) // find empty neighbours eps := foodNeighours(w, c, p) // find empty neighbours ep, moved := randomNeighbour(eps) // randomly select an empty neighbour if moved { np = ep Loading @@ -226,12 +226,12 @@ func processFishes(w *Wator, c *Playfield, n *Playfield) error { return nil } func processSharks(w *Wator, c *Playfield, n *Playfield) error { func processHunters(w *Wator, c *Playfield, n *Playfield) error { for p, s := range c.Hunters { s.SetAge(s.Age() + 1) s.SetAte(s.Ate() + 1) var np position eps, fps := sharkNeighbours(w, c, p) eps, fps := hunterNeighbours(w, c, p) fp, fMoved := randomNeighbour(fps) if fMoved { // shark ate fish Loading