MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Element_Fish.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  Element_Fish.h An element that acts similarly to a Wa-Tor fish
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
27 #ifndef ELEMENT_FISH_H
28 #define ELEMENT_FISH_H
29 
30 #include "Element.h"
31 #include "EventWindow.h"
32 #include "ElementTable.h"
33 #include "itype.h"
34 #include "Atom.h"
35 #include "AbstractElement_WaPat.h"
36 #include "WindowScanner.h"
37 
38 namespace MFM
39 {
40 
41  template <class CC>
43  {
44  // Short names for params
45  typedef typename CC::ATOM_TYPE T;
46  typedef typename CC::PARAM_CONFIG P;
47  enum {
48  R = P::EVENT_WINDOW_RADIUS,
49 
50  INITIAL_DEFAULT_BIRTH_AGE = 20
51  };
52 
53  ElementParameterS32<CC> m_fishBirthAge;
54  ElementParameterBool<CC> m_fishEvolve;
55 
56  public:
57  enum
58  {
59  ELEMENT_VERSION = 1
60  };
61 
62  static Element_Fish THE_INSTANCE;
63  static const u32 TYPE()
64  {
65  return THE_INSTANCE.GetType();
66  }
67 
68  Element_Fish() :
69  AbstractElement_WaPat<CC>(MFM_UUID_FOR("Fish", ELEMENT_VERSION)),
70  m_fishBirthAge(this, "age", "Birth Age",
71  "Number of events for a fish to mature",
72  1, INITIAL_DEFAULT_BIRTH_AGE, 100/*, 1*/),
73  m_fishEvolve(this, "evo", "Evolvable fish",
74  "Is fish birth age set by mutable genes?",
75  false)
76  {
78  Element<CC>::SetName("Fish");
79  }
80 
81  virtual const T & GetDefaultAtom() const
82  {
83  static T defaultAtom(TYPE(),0,0,0);
84 
85  this->SetBirthAge(defaultAtom, (u32) m_fishBirthAge.GetValue());
86  this->SetCurrentAge(defaultAtom, 0);
87 
88  return defaultAtom;
89  }
90 
91  virtual u32 DefaultPhysicsColor() const
92  {
93  return 0xffbbbbaa;
94  }
95 
96  // Non-diffusable
97  virtual u32 Diffusability(EventWindow<CC> & ew, SPoint nowAt, SPoint maybeAt) const
98  {
99  return nowAt.Equals(maybeAt)?Element<CC>::COMPLETE_DIFFUSABILITY:0;
100  }
101 
102  virtual u32 PercentMovable(const T& you,
103  const T& me, const SPoint& offset) const
104  {
105  return 0;
106  }
107 
108  virtual void Behavior(EventWindow<CC>& window) const
109  {
110  T self = window.GetCenterAtom();
111  SPoint emptyRel;
112  u32 emptyCount = 0;
113  u32 age = this->GetCurrentAge(self);
114  WindowScanner<CC> scanner(window);
115 
116  // Don't use genetic birth age (yet): bool reproable = age >= this->GetBirthAge(self);
117  bool reproable = age >= (u32) m_fishBirthAge.GetValue();
118 
119  if (!reproable)
120  {
121  this->SetCurrentAge(self, 1 + age);
122  }
123 
124  emptyCount = scanner.FindEmptyInVonNeumann(emptyRel);
125 
126  if (emptyCount > 0) // Can move
127  {
128  if (reproable) // and leave kid behind
129  {
130  this->SetCurrentAge(self,0);
131  window.SetCenterAtom(self);
132  }
133  else // or leave empty behind
134  {
136  }
137  window.SetRelativeAtom(emptyRel,self); // move or repro
138  }
139  else // Can't move
140  {
141  if (!reproable) // But if immature
142  {
143  window.SetCenterAtom(self); // Can age
144  }
145  }
146  }
147  };
148 
149  template <class CC>
150  Element_Fish<CC> Element_Fish<CC>::THE_INSTANCE;
151 
152 }
153 
154 #endif /* ELEMENT_FISH_H */
u32 GetType() const
Definition: Element.h:290
Definition: Element_Empty.h:41
void SetCenterAtom(const T &atom)
Definition: EventWindow.h:220
bool Equals(const Point< T > &rhs) const
Definition: Point.tcc:205
Definition: Parameter.h:628
void SetName(const char *name)
Definition: Element.h:209
void SetAtomicSymbol(const char *symbol)
Definition: Element.h:193
u32 FindEmptyInVonNeumann(SPoint &outPoint) const
Definition: WindowScanner.tcc:311
virtual u32 Diffusability(EventWindow< CC > &ew, SPoint nowAt, SPoint maybeAt) const
Definition: Element_Fish.h:97
Definition: Parameter.h:593
const T & GetCenterAtom() const
Definition: EventWindow.h:209
Definition: AbstractElement_WaPat.h:39
Definition: Element_Fish.h:42
virtual const T & GetDefaultAtom() const
Definition: Element_Fish.h:81
Definition: ElementTable.h:43
virtual void Behavior(EventWindow< CC > &window) const
Definition: Element_Fish.h:108
Definition: WindowScanner.h:40
bool SetRelativeAtom(const SPoint &offset, const T &atom)
Definition: EventWindow.tcc:15
Definition: Atom.h:43
virtual u32 PercentMovable(const T &you, const T &me, const SPoint &offset) const
Definition: Element_Fish.h:102
virtual u32 DefaultPhysicsColor() const
Definition: Element_Fish.h:91