Commit 8168ad21 authored by Boris Mühmer's avatar Boris Mühmer
Browse files

renamed fishes and sharks to generic terms

parent a75d6b3c
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -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
@@ -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),
@@ -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{
@@ -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
@@ -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