HOG2
SnakeBird.h
Go to the documentation of this file.
1 //
2 // SnakeBird.h
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 1/26/20.
6 // Copyright © 2020 University of Denver. All rights reserved.
7 //
8 
9 #ifndef SnakeBird_h
10 #define SnakeBird_h
11 
12 #include <stdio.h>
13 #include "SearchEnvironment.h"
14 #include <array>
15 
16 namespace SnakeBird {
17 
18 // 64 bits can hold
19 //
20 //
21 // world is 20x16 (WxH) = 320
22 // world is any x/y, as long as x*y < 512
23 // 1 snake = [5 bits, 4 bits] 9 bits head, 2 bits (4 dir) per segment
24 // 3 snakes = 27 bits + length
25 
26 // uint64_t blockFruit
27 // block: 9 bits each, max 4(?) = 36 bits
28 // fruit: up to 28 - one bit each
29 const uint64_t locationMask = 0x1FF;
30 const uint64_t snakeLenMask = 0x1F;
31 const uint64_t fruitMask = 0x1F;
32 const uint64_t snakeHeadMask = 0x7;
33 const uint64_t snakeBodyMask = 0x3;
34 const uint64_t kOne = 0x1;
35 const int kDead = 510;
36 const int kInGoal = 511;
37 const uint8_t kNothingPushed = 0xFF;
38 //const int kMaxPushedObjects = 3;
39 const int codeSize = 2;
40 
41 enum snakeDir : uint8_t {
42  kLeft=0x0, kRight=0x1, kUp=0x2, kDown=0x3, kNoDirection=0x4
43 };
45  uint64_t snakeBodies; // up to 32 in length
46  uint64_t snakeHeads; // up to 4. 3bits (num snakes) + 9 bits head + 5 bits start location of next. (max coordinate) head means snake left level
47  uint64_t locBlockFruit; // 4*9bit blocks; 28 fruit
48 
51  bool operator==(const SnakeBirdState &s) const {
53  }
54  int GetNumSnakes() const { return snakeHeads&snakeHeadMask; }
55  void SetNumSnakes(int count) { snakeHeads = (snakeHeads&(~snakeHeadMask))|(count&snakeHeadMask); }
56  bool IsDead(int whichSnake) const
57  { return GetSnakeHeadLoc(whichSnake) == kDead; }
58  bool IsInPlay(int whichSnake) const
59  { return GetSnakeHeadLoc(whichSnake) != kDead && GetSnakeHeadLoc(whichSnake) != kInGoal; }
60  int GetSnakeHeadLoc(int whichSnake) const
61  { return (snakeHeads>>(3+whichSnake*14))&0x1FF;}
62  void SetSnakeHeadLoc(int whichSnake, int loc)
63  { snakeHeads &= ~(locationMask<<(3+whichSnake*14));
64  snakeHeads |= ((loc&locationMask)<<(3+whichSnake*14)); }
65  int GetSnakeBodyEnd(int whichSnake) const
66  { return (whichSnake<0)?0:(snakeHeads>>(3+9*(whichSnake+1)+5*whichSnake))&snakeLenMask; }
67  void SetSnakeBodyEnd(int whichSnake, int endOffset)
68  { snakeHeads &= ~(snakeLenMask<<(3+9*(whichSnake+1)+5*whichSnake)); snakeHeads |= ((endOffset&snakeLenMask)<<(3+9*(whichSnake+1)+5*whichSnake)); }
69 
70  void SetSnakeLength(int whichSnake, int len)
71  { //SetSnakeBodyEnd(whichSnake, GetSnakeBodyEnd(whichSnake-1)+len-1);
72  uint64_t oldBody[4]; // max 4 snakes
73  int oldLen[4];
74  for (int x = 0; x < GetNumSnakes(); x++)
75  {
76  oldBody[x] = GetBodyBits(x);
77  oldLen[x] = GetSnakeLength(x);
78  }
79  oldLen[whichSnake] = len;
80  oldBody[whichSnake] &= ((1<<len)-1);
81  //SetSnakeBodyEnd(whichSnake, GetSnakeBodyEnd(whichSnake-1)+len-1);
82  for (int x = whichSnake; x < GetNumSnakes(); x++)
83  SetSnakeBodyEnd(x, GetSnakeBodyEnd(x-1)+oldLen[x]-1);
84  for (int x = whichSnake; x < GetNumSnakes(); x++)
85  SetBodyBits(x, oldBody[x]);
86  }
87  int GetSnakeLength(int whichSnake) const
88  { return GetSnakeBodyEnd(whichSnake)-GetSnakeBodyEnd(whichSnake-1)+1; }
89 
90  snakeDir GetSnakeDir(int whichSnake, int segment) const
91  { return static_cast<snakeDir>((snakeBodies>>(2*segment+2*GetSnakeBodyEnd(whichSnake-1)))&snakeBodyMask); }
92  void SetSnakeDir(int whichSnake, int segment, snakeDir dir)
93  {
94  snakeBodies &= ~(snakeBodyMask<<(2*segment+2*GetSnakeBodyEnd(whichSnake-1)));
95  snakeBodies |= ((static_cast<uint64_t>(dir))<<(2*segment+2*GetSnakeBodyEnd(whichSnake-1)));
96  }
97  // add dir to beginning of snake
98  void InsertSnakeDir(int whichSnake, snakeDir dir)
99  {
100  uint64_t mask = 1;
101  mask <<= (GetSnakeBodyEnd(whichSnake)-GetSnakeBodyEnd(whichSnake-1))*2; // length in bits
102  mask -= 1;
103  mask <<= GetSnakeBodyEnd(whichSnake-1)*2;
104  uint64_t oldSnake = snakeBodies&(mask);
105  oldSnake<<=2;
106  oldSnake |= dir<<(GetSnakeBodyEnd(whichSnake-1)*2);
107  snakeBodies &= (~mask);
108  snakeBodies |= (oldSnake&(mask));
109  }
110  // grow snake by adding dir
111  void InsertSnakeHeadDir(int whichSnake, snakeDir dir)
112  {
113  int start = GetSnakeBodyEnd(whichSnake-1)*2;
114  uint64_t mask = 1; // mask is the low bits to keep
115  mask<<=start;
116  mask -= 1;
117 
118  uint64_t a = (snakeBodies&mask);
119  uint64_t b = (dir<<start);
120  uint64_t c = ((snakeBodies&(~mask))<<(2));
121  snakeBodies = a|b|c;
122  }
123  uint64_t GetBodyBits(int whichSnake) const
124  {
125  uint64_t mask = 1;
126  mask <<= (GetSnakeBodyEnd(whichSnake)-GetSnakeBodyEnd(whichSnake-1))*2; // length in bits
127  mask -= 1;
128  uint64_t result = snakeBodies>>(GetSnakeBodyEnd(whichSnake-1)*2);
129  return result&mask;
130  }
131  void SetBodyBits(int whichSnake, uint64_t bodyBits)
132  {
133  uint64_t mask = 1;
134  mask <<= (GetSnakeBodyEnd(whichSnake)-GetSnakeBodyEnd(whichSnake-1))*2; // length in bits
135  mask -= 1;
136  mask <<= GetSnakeBodyEnd(whichSnake-1)*2;
137  bodyBits <<= GetSnakeBodyEnd(whichSnake-1)*2;
138  snakeBodies &= (~mask);
139  snakeBodies |= bodyBits;
140  }
141  void MakeSnakeLonger(int whichSnake)
142  {
143  uint64_t old[4]; // max 4 snakes
144  for (int x = 0; x < GetNumSnakes(); x++)
145  old[x] = GetBodyBits(x);
146  for (int x = whichSnake; x < GetNumSnakes(); x++)
148  for (int x = whichSnake; x < GetNumSnakes(); x++)
149  SetBodyBits(x, old[x]);
150  }
151  void MakeSnakeLonger(int whichSnake, snakeDir addDir)
152  {
153  uint64_t old[4]; // max 4 snakes
154  for (int x = whichSnake; x < GetNumSnakes(); x++)
155  old[x] = GetBodyBits(x);
156  old[whichSnake] |= ((2*(GetSnakeLength(whichSnake)+1))<<addDir);
157  for (int x = whichSnake; x < GetNumSnakes(); x++)
159  for (int x = whichSnake; x < GetNumSnakes(); x++)
160  SetBodyBits(x, old[x]);
161  }
162  int GetObjectLocation(int whichObstacle) const { return (locBlockFruit>>(9*whichObstacle))&locationMask; }
163  void SetObjectLocation(int whichObstacle, int loc) //{ return (locBlockFruit>>(9*whichObstacle))&locationMask; }
164  { locBlockFruit &= ~(locationMask<<(whichObstacle*9)); locBlockFruit |= ((loc&locationMask)<<(whichObstacle*9)); }
165 
166  // Fruit is 0 if present 1 if not. Thus by default all fruit is present.
167  bool GetFruitPresent(int which) const { return ((locBlockFruit>>(36+which))&0x1)==0; }
168  void ToggleFruitPresent(int which) { locBlockFruit ^= (kOne<<(36+which));}
169  bool KFruitEaten(int k) const
170  {
171  uint64_t mask = (kOne<<(k))-1;
172  return ((locBlockFruit>>36)&mask)==(mask);
173 
174  }
175 };
176 
178  SnakeBirdAction() :bird(0xF), direction(0xF), pushed(0) {}
179  unsigned int bird : 4; // which bird
180  unsigned int direction : 4; // which direction
181  uint8_t pushed; // 8 booleans; supporting 4 snakes & 4 blocks
182  bool operator==(const SnakeBirdAction &a) const
183  {
184  // TODO: need to compare if anything is being pushed
185  return a.bird == bird && a.direction == direction;
186  }
187 };
188 
189 static std::ostream &operator<<(std::ostream &out, const SnakeBirdAction &a)
190 {
191  out << a.bird << " ";
192  switch (a.direction)
193  {
194  case kUp: out << "up"; break;
195  case kDown: out << "down"; break;
196  case kLeft: out << "left"; break;
197  case kRight: out << "right"; break;
198  }
199  return out;
200 }
201 
202 enum SnakeBirdAnimation : uint8_t {
212 };
213 
221 };
222 
223 /*
224  Level files are text
225  * Terrain types in text:
226  * . Empty
227  * G Ground
228  * X Spikes
229  * O Portal
230  * E Exit
231  * F Fruit
232  * 1 [1-4] Parts of object
233  * < Snake heads. Body is on the open side, eg <===
234  * >
235  * ^
236  * V
237  * a-z [snake body in order, all letters must be unique in level]
238  */
239 
240 const uint8_t kCanEnterMask = 0x80;
241 const uint8_t kGroundMask = 0x40;
242 const uint8_t kSnakeMask = 0x10;
243 const uint8_t kBlockMask = 0x20;
244 
245 enum SnakeBirdWorldObject : uint8_t {
246  // can always enter, but may have secondary effects
247  kEmpty = 0x80, // = 128
248  kFruit = 0x81,
249  kExit = 0x82,
250  kPortal1= 0x83,
251  kPortal2= 0x84,
252  kPortal, //figure out where the portals go
253 
254  // cannot ever enter
255  kGround = 0x40, // = 64
256  kSpikes = 0x41, // = 65
257 
258  // for pushing
259  kBlock1 = 0x20,
260  kBlock2 = 0x21,
261  kBlock3 = 0x22,
262  kBlock4 = 0x23,
263 
264  // other snakes
265  kSnake1 = 0x10,
266  kSnake2 = 0x11,
267  kSnake3 = 0x12,
268  kSnake4 = 0x13,
269 
270  // Draw nothing
271  kNothing= 0x0,
272 };
273 
278 };
279 
280 class SnakeBird : public SearchEnvironment<SnakeBirdState, SnakeBirdAction> {
281 public:
282  SnakeBird(int width = 20, int height = 16);
283  void Reset();
284  void BiggerMapHeight();
285  void BiggerMapWidth();
286  void SmallerMapHeight();
287  void SmallerMapWidth();
288  bool Load(const char *filename);
289  bool Save(const char *filename);
290  std::string EncodeLevel() const;
291  bool DecodeLevel(const std::string &);
292  void BeginEditing();
293  void EndEditing();
294 
295  SnakeBirdState GetStart() const;
296  void SetStart(const SnakeBirdState &);
297  void AddSnake(int x, int y, const std::vector<snakeDir> &body);
298  void AddSnakeHead(int x, int y, int whichSnake);
299  snakeDir GetAddingDirection(int x, int y, int endX, int endY);
300  void AddSnakeBody(int x, int y, int whichSnake);
301 
302  void RemoveSnake(int x, int y, int o, int whichSnake);
303  void SetGroundType(int x, int y, SnakeBirdWorldObject o);
304  void RemoveBlock(int x, int y);
305  int GetNumPortals();
306  SnakeBirdWorldObject GetGroundType(int x, int y) const;
307  SnakeBirdWorldObject GetRenderedGroundType(const SnakeBirdState &s, int x, int y);
308  int GetWidth() const { return width; }
309  int GetHeight() const { return height; }
310 
311  void GetSuccessors(const SnakeBirdState &nodeID, std::vector<SnakeBirdState> &neighbors) const;
312  void GetActions(const SnakeBirdState &nodeID, std::vector<SnakeBirdAction> &actions) const;
313  bool LivingState(const SnakeBirdState &s) const { return Render(s); }
314  size_t GetNumFruit() { return fruit.size(); }
315  //SnakeBirdAction GetAction(const SnakeBirdState &s1, const SnakeBirdState &s2) const;
316  void ApplyAction(SnakeBirdState &s, SnakeBirdAction a) const;
317  /* Applys the next portion of the action - not done until returns true. */
318  bool ApplyPartialAction(SnakeBirdState &s, SnakeBirdAction a, SnakeBirdAnimationStep &step) const;
319  bool Legal(SnakeBirdState &s, SnakeBirdAction a);
320  // Cannot undo actions
322  { assert(false); }
323 
325  {
326  s2 = s1;
327  ApplyAction(s2, a);
328  };
329 
330  bool InvertAction(SnakeBirdAction &a) const { return false; }
331 
334  { bValidSearchGoal = true; searchGoal = s; }
335 
337  void ClearGoal()
338  { bValidSearchGoal = false; }
339 
341  bool IsGoalStored() const
342  { return bValidSearchGoal; }
343 
345  double HCost(const SnakeBirdState &node1, const SnakeBirdState &node2) const { return 0; }
346 
347  double GCost(const SnakeBirdState &node1, const SnakeBirdState &node2) const { return 1;}
348  double GCost(const SnakeBirdState &node, const SnakeBirdAction &act) const { return 1;}
349  bool GoalTest(const SnakeBirdState &node, const SnakeBirdState &goal) const { return GoalTest(node); }
350 
352  virtual bool GoalTest(const SnakeBirdState &node) const
353  { for (int x = 0; x < node.GetNumSnakes(); x++) if (node.GetSnakeHeadLoc(x) != kInGoal) return false; return true; }
354 
355  uint64_t GetActionHash(SnakeBirdAction act) const {return (act.bird<<2)|act.direction;}
356  uint64_t GetStateHash(const SnakeBirdState &node) const
357  {
358  //return node.snakeHeads^(node.snakeBodies>>11)^(node.snakeBodies<<17)^node.locBlockFruit;
359  return node.snakeHeads^(node.snakeBodies)^node.locBlockFruit;
360  }
361 
362  void OpenGLDraw() const {}
363  void OpenGLDraw(const SnakeBirdState&) const {}
365  void OpenGLDraw(const SnakeBirdState&, const SnakeBirdState&, float) const {}
366  void OpenGLDraw(const SnakeBirdState&, const SnakeBirdAction&) const {};
367  void GLLabelState(const SnakeBirdState&, const char *) const {} // draw label over state
368  void GLDrawLine(const SnakeBirdState &x, const SnakeBirdState &y) const {}
369  void GLDrawPath(const std::vector<SnakeBirdState> &x) const {}
370 
371 
372  void Draw(Graphics::Display &display) const;
373  void DrawObjects(Graphics::Display &display, double time = 0) const;
374  void DrawObject(Graphics::Display &display, int x, int y, SnakeBirdWorldObject o, double time = 0) const;
375  void Draw(Graphics::Display &display, int x, int y, float width = 1.0) const;
376  void Draw(Graphics::Display &display, double time) const;
377  void Draw(Graphics::Display &display, const SnakeBirdState&) const;
378  void Draw(Graphics::Display &display, const SnakeBirdState&, int active) const;
379  void Draw(Graphics::Display &display, const SnakeBirdState&, int active, double globalTime) const;
380  void Draw(Graphics::Display &display, const SnakeBirdState&, const SnakeBirdState&,
381  int active, double percentComplete, double globalTime) const;
382  void DrawLine(Graphics::Display &display, const SnakeBirdState &x, const SnakeBirdState &y, float width = 1.0) const;
383  void DrawLabel(Graphics::Display &display, int x, int y, const char *str);
384  void DrawSmallLabel(Graphics::Display &display, int x, int y, const char *str);
385 
386  // Allows us to draw text overlay
387  float GetRadius() const;
388  bool GetPointFromCoordinate(Graphics::point p, int &x, int &y);
389 private:
390  std::string Code(int) const;
391  int DeCode(const std::string &s, size_t offset) const;
392  void SetGroundType(int index, SnakeBirdWorldObject o);
393  bool Render(const SnakeBirdState &s) const;
394  bool CanPush(const SnakeBirdState &s, int snake, SnakeBirdWorldObject obj, snakeDir dir,
395  SnakeBirdAction &a) const;
396  bool IsOnSpikes(const SnakeBirdState &s, int which) const;
397 
398  // Apply Move helper functions
399  // check if snakebirds can teleport - return true if one did
400  TeleportResult HandleTeleports(SnakeBirdState &s, SnakeBirdAction &a,
401  snakeDir lastAction, snakeDir opposite, SnakeBirdAnimationStep step) const;
402  SnakeBirdAnimation DoFirstMovement(const SnakeBirdAction &a, int offset, snakeDir opposite, SnakeBirdState &s) const;
403  // returns true if a snake fell
405 
406 
407  int GetFruitOffset(int index) const;
408 public:
409  int GetIndex(int x, int y) const;
410  int GetX(int index) const;
411  int GetY(int index) const;
412 private:
413  int Distance(int index1, int index2);
414  Graphics::point GetCenter(int x, int y) const;
415 
416  void DrawSnakeEnteringGoal(Graphics::Display &display, const SnakeBirdState &s,
417  int snake, bool isActive, double percentComplete) const;
418  void DrawTranslatingSnake(Graphics::Display &display, const SnakeBirdState &old, const SnakeBirdState &s,
419  int snake, bool isActive, double percentComplete) const;
420  void DrawMovingSnake(Graphics::Display &display, const SnakeBirdState &old, const SnakeBirdState &s,
421  int snake, bool isActive, double percentComplete) const;
422  void DrawSnakeSegment(Graphics::Display &display, Graphics::point p, const rgbColor &color, bool head, bool tail, bool awake, snakeDir dirFrom, snakeDir dirTo, int whichSnake, bool isDead) const;
423 
424  // Member variables
425  int width, height;
426 
427  std::array<SnakeBirdWorldObject, 512> world; // static world
428  mutable std::array<SnakeBirdWorldObject, 512> render;
429 
430  std::vector<int> fruit;
431 
432  std::array<std::vector<int>, 4> objects; // offsets from base location
433  std::array<bool, 4> objectFullyConnected;
434  int portal1Loc, portal2Loc;
435  int exitLoc;
437  bool editing;
438 // int lastSnake;
439  // std::array<
440 };
441 
442 }
443 
444 namespace std {
445 template <>
446 struct hash<SnakeBird::SnakeBirdState>
447 {
448  std::size_t operator()(const SnakeBird::SnakeBirdState &k) const
449  {
450  return k.snakeHeads^(k.snakeBodies)^k.locBlockFruit;
451  }
452 };
453 
454 }
455 
456 
457 #endif /* SnakeBird_h */
SnakeBird::SnakeBird::startState
SnakeBirdState startState
Definition: SnakeBird.h:436
SnakeBird::SnakeBirdState::GetObjectLocation
int GetObjectLocation(int whichObstacle) const
Definition: SnakeBird.h:162
SnakeBird::kPortal
@ kPortal
Definition: SnakeBird.h:252
SnakeBird::kSnake4
@ kSnake4
Definition: SnakeBird.h:268
Graphics::point
Definition: Graphics.h:32
SnakeBird::kNoDirection
@ kNoDirection
Definition: SnakeBird.h:42
SnakeBird::SnakeBird::GetActionHash
uint64_t GetActionHash(SnakeBirdAction act) const
Definition: SnakeBird.h:355
SnakeBird::SnakeBirdState::GetBodyBits
uint64_t GetBodyBits(int whichSnake) const
Definition: SnakeBird.h:123
SnakeBird::kNothing
@ kNothing
Definition: SnakeBird.h:271
rgbColor
A color; r/g/b are between 0...1.
Definition: Colors.h:17
SnakeBird::SnakeBirdState::SetNumSnakes
void SetNumSnakes(int count)
Definition: SnakeBird.h:55
SnakeBird::SnakeBird::GetHeight
int GetHeight() const
Definition: SnakeBird.h:309
SnakeBird::SnakeBirdState
Definition: SnakeBird.h:44
SnakeBird::kPortal2
@ kPortal2
Definition: SnakeBird.h:251
SnakeBird::SnakeBird::GLDrawLine
void GLDrawLine(const SnakeBirdState &x, const SnakeBirdState &y) const
Definition: SnakeBird.h:368
SnakeBird::SnakeBird::GCost
double GCost(const SnakeBirdState &node1, const SnakeBirdState &node2) const
Definition: SnakeBird.h:347
SnakeBird::SnakeBird::StoreGoal
void StoreGoal(SnakeBirdState &s)
Stores the goal for use by single-state HCost.
Definition: SnakeBird.h:333
SnakeBird::SnakeBirdState::SetSnakeLength
void SetSnakeLength(int whichSnake, int len)
Definition: SnakeBird.h:70
SnakeBird::kOne
const uint64_t kOne
Definition: SnakeBird.h:34
SnakeBird::SnakeBird::objects
std::array< std::vector< int >, 4 > objects
Definition: SnakeBird.h:432
SnakeBird::kNeedsInitialization
@ kNeedsInitialization
Definition: SnakeBird.h:211
SnakeBird::SnakeBird::ClearGoal
void ClearGoal()
Clears the goal from memory.
Definition: SnakeBird.h:337
SnakeBird::SnakeBirdState::ToggleFruitPresent
void ToggleFruitPresent(int which)
Definition: SnakeBird.h:168
SnakeBird::snakeLenMask
const uint64_t snakeLenMask
Definition: SnakeBird.h:30
SnakeBird::SnakeBirdState::Reset
void Reset()
Definition: SnakeBird.h:50
SnakeBird::kDown
@ kDown
Definition: SnakeBird.h:42
SnakeBird::SnakeBird::GLDrawPath
void GLDrawPath(const std::vector< SnakeBirdState > &x) const
Definition: SnakeBird.h:369
SnakeBird::kLeft
@ kLeft
Definition: SnakeBird.h:42
SnakeBird::SnakeBirdState::GetSnakeLength
int GetSnakeLength(int whichSnake) const
Definition: SnakeBird.h:87
SnakeBird::kSnakeMask
const uint8_t kSnakeMask
Definition: SnakeBird.h:242
SnakeBird::SnakeBirdAnimationStep::anim
SnakeBirdAnimation anim
Definition: SnakeBird.h:217
SnakeBird::snakeBodyMask
const uint64_t snakeBodyMask
Definition: SnakeBird.h:33
SnakeBird::SnakeBird::HCost
double HCost(const SnakeBirdState &node1, const SnakeBirdState &node2) const
Heuristic value between two arbitrary nodes.
Definition: SnakeBird.h:345
SnakeBird::TeleportResult
TeleportResult
Definition: SnakeBird.h:274
SnakeBird::kSpikes
@ kSpikes
Definition: SnakeBird.h:256
SnakeBird::kBlockMask
const uint8_t kBlockMask
Definition: SnakeBird.h:243
SnakeBird::SnakeBird::GetNumFruit
size_t GetNumFruit()
Definition: SnakeBird.h:314
SnakeBird::snakeHeadMask
const uint64_t snakeHeadMask
Definition: SnakeBird.h:32
SnakeBird::SnakeBirdState::IsInPlay
bool IsInPlay(int whichSnake) const
Definition: SnakeBird.h:58
SnakeBird::SnakeBird::GoalTest
bool GoalTest(const SnakeBirdState &node, const SnakeBirdState &goal) const
Definition: SnakeBird.h:349
width
int width
Definition: SFML_HOG.cpp:54
SnakeBird::SnakeBird::OpenGLDraw
void OpenGLDraw(const SnakeBirdState &) const
Definition: SnakeBird.h:363
SnakeBird::SnakeBird::OpenGLDraw
void OpenGLDraw() const
Definition: SnakeBird.h:362
SnakeBird::SnakeBirdAction::direction
unsigned int direction
Definition: SnakeBird.h:180
SnakeBird::fruitMask
const uint64_t fruitMask
Definition: SnakeBird.h:31
SnakeBird::SnakeBirdAnimationStep::Reset
void Reset()
Definition: SnakeBird.h:216
SnakeBird::SnakeBirdState::SetObjectLocation
void SetObjectLocation(int whichObstacle, int loc)
Definition: SnakeBird.h:163
SnakeBird::SnakeBirdState::SetSnakeHeadLoc
void SetSnakeHeadLoc(int whichSnake, int loc)
Definition: SnakeBird.h:62
SnakeBird::kMovement
@ kMovement
Definition: SnakeBird.h:203
SnakeBird
Definition: SnakeBird.cpp:14
SnakeBird::SnakeBird::GLLabelState
void GLLabelState(const SnakeBirdState &, const char *) const
Definition: SnakeBird.h:367
SnakeBird::kNoTeleport
@ kNoTeleport
Definition: SnakeBird.h:275
SnakeBird::SnakeBird::objectFullyConnected
std::array< bool, 4 > objectFullyConnected
Definition: SnakeBird.h:433
SnakeBird::SnakeBirdState::SetSnakeBodyEnd
void SetSnakeBodyEnd(int whichSnake, int endOffset)
Definition: SnakeBird.h:67
SnakeBird::kExit
@ kExit
Definition: SnakeBird.h:249
SnakeBird::SnakeBirdState::MakeSnakeLonger
void MakeSnakeLonger(int whichSnake)
Definition: SnakeBird.h:141
SnakeBird::kPortal1
@ kPortal1
Definition: SnakeBird.h:250
SnakeBird::SnakeBird::GetStateHash
uint64_t GetStateHash(const SnakeBirdState &node) const
Definition: SnakeBird.h:356
SnakeBird::SnakeBirdState::MakeSnakeLonger
void MakeSnakeLonger(int whichSnake, snakeDir addDir)
Definition: SnakeBird.h:151
SnakeBird::SnakeBirdState::GetSnakeDir
snakeDir GetSnakeDir(int whichSnake, int segment) const
Definition: SnakeBird.h:90
SnakeBird::SnakeBird::world
std::array< SnakeBirdWorldObject, 512 > world
Definition: SnakeBird.h:427
SnakeBird::SnakeBirdState::operator==
bool operator==(const SnakeBirdState &s) const
Definition: SnakeBird.h:51
SnakeBird::locationMask
const uint64_t locationMask
Definition: SnakeBird.h:29
SnakeBird::SnakeBirdAction::pushed
uint8_t pushed
Definition: SnakeBird.h:181
SnakeBird::kFall
@ kFall
Definition: SnakeBird.h:204
loc
Definition: MapGenerators.cpp:296
SnakeBird::kRight
@ kRight
Definition: SnakeBird.h:42
SnakeBird::SnakeBirdAnimationStep::a
SnakeBirdAction a
Definition: SnakeBird.h:218
SnakeBird::kPauseWhenDead
@ kPauseWhenDead
Definition: SnakeBird.h:210
SnakeBird::SnakeBirdState::SetSnakeDir
void SetSnakeDir(int whichSnake, int segment, snakeDir dir)
Definition: SnakeBird.h:92
GetX
int GetX(int loc)
Definition: Fling.h:67
SnakeBird::SnakeBirdWorldObject
SnakeBirdWorldObject
Definition: SnakeBird.h:245
SnakeBird::SnakeBirdState::InsertSnakeDir
void InsertSnakeDir(int whichSnake, snakeDir dir)
Definition: SnakeBird.h:98
SnakeBird::SnakeBirdAnimationStep::animationDuration
double animationDuration
Definition: SnakeBird.h:219
Graphics::Display
Definition: Graphics.h:146
SnakeBird::SnakeBirdState::snakeHeads
uint64_t snakeHeads
Definition: SnakeBird.h:46
SnakeBird::kFruit
@ kFruit
Definition: SnakeBird.h:248
SnakeBird::SnakeBirdAnimationStep::SnakeBirdAnimationStep
SnakeBirdAnimationStep()
Definition: SnakeBird.h:215
SnakeBird::SnakeBird::portal2Loc
int portal2Loc
Definition: SnakeBird.h:434
SnakeBird::SnakeBirdState::IsDead
bool IsDead(int whichSnake) const
Definition: SnakeBird.h:56
SnakeBird::kTeleport
@ kTeleport
Definition: SnakeBird.h:206
SnakeBird::kSnake3
@ kSnake3
Definition: SnakeBird.h:267
SnakeBird::SnakeBirdAnimationStep
Definition: SnakeBird.h:214
SnakeBird::SnakeBird::fruit
std::vector< int > fruit
Definition: SnakeBird.h:430
SnakeBird::SnakeBirdState::SetBodyBits
void SetBodyBits(int whichSnake, uint64_t bodyBits)
Definition: SnakeBird.h:131
SnakeBird::SnakeBirdAnimation
SnakeBirdAnimation
Definition: SnakeBird.h:202
SnakeBird::SnakeBird::width
int width
Definition: SnakeBird.h:425
SnakeBird::codeSize
const int codeSize
Definition: SnakeBird.h:39
SnakeBird::kBlock3
@ kBlock3
Definition: SnakeBird.h:261
SnakeBird::kInGoal
const int kInGoal
Definition: SnakeBird.h:36
SnakeBird::operator<<
static std::ostream & operator<<(std::ostream &out, const SnakeBirdAction &a)
Definition: SnakeBird.h:189
SnakeBird::kWentInGoal
@ kWentInGoal
Definition: SnakeBird.h:207
SnakeBird::SnakeBirdState::GetNumSnakes
int GetNumSnakes() const
Definition: SnakeBird.h:54
SnakeBird::kEmpty
@ kEmpty
Definition: SnakeBird.h:247
height
int height
Definition: SFML_HOG.cpp:54
SnakeBird::SnakeBirdAnimationStep::teleportCount
int teleportCount
Definition: SnakeBird.h:220
SnakeBird::SnakeBirdState::locBlockFruit
uint64_t locBlockFruit
Definition: SnakeBird.h:47
SnakeBird::SnakeBirdState::KFruitEaten
bool KFruitEaten(int k) const
Definition: SnakeBird.h:169
SnakeBird::kUp
@ kUp
Definition: SnakeBird.h:42
SnakeBird::kSnake2
@ kSnake2
Definition: SnakeBird.h:266
SnakeBird::kTeleportToExit
@ kTeleportToExit
Definition: SnakeBird.h:277
SnakeBird::SnakeBird::IsGoalStored
bool IsGoalStored() const
Returns true if the goal is stored and false otherwise.
Definition: SnakeBird.h:341
SnakeBird::kTeleportSuccess
@ kTeleportSuccess
Definition: SnakeBird.h:276
SnakeBird::SnakeBird::UndoAction
void UndoAction(SnakeBirdState &s, SnakeBirdAction a) const
Definition: SnakeBird.h:321
SnakeBird::SnakeBird::OpenGLDraw
void OpenGLDraw(const SnakeBirdState &, const SnakeBirdState &, float) const
Draw the transition at some percentage 0...1 between two states.
Definition: SnakeBird.h:365
SnakeBird::kSnake1
@ kSnake1
Definition: SnakeBird.h:265
SnakeBird::SnakeBirdAction::SnakeBirdAction
SnakeBirdAction()
Definition: SnakeBird.h:178
SnakeBird::kDead
const int kDead
Definition: SnakeBird.h:35
SnakeBird::kGroundMask
const uint8_t kGroundMask
Definition: SnakeBird.h:241
SnakeBird::kNothingPushed
const uint8_t kNothingPushed
Definition: SnakeBird.h:37
SnakeBird::kInitialTeleport
@ kInitialTeleport
Definition: SnakeBird.h:205
SnakeBird::SnakeBirdState::InsertSnakeHeadDir
void InsertSnakeHeadDir(int whichSnake, snakeDir dir)
Definition: SnakeBird.h:111
SnakeBird::kFellInGoal
@ kFellInGoal
Definition: SnakeBird.h:208
SnakeBird::kBlock4
@ kBlock4
Definition: SnakeBird.h:262
SnakeBird::kGround
@ kGround
Definition: SnakeBird.h:255
SnakeBird::SnakeBirdAction::bird
unsigned int bird
Definition: SnakeBird.h:179
SnakeBird::snakeDir
snakeDir
Definition: SnakeBird.h:41
std
Definition: CanonicalGraphEnvironment.h:26
SnakeBird::SnakeBird::LivingState
bool LivingState(const SnakeBirdState &s) const
Definition: SnakeBird.h:313
SnakeBird::SnakeBirdAction::operator==
bool operator==(const SnakeBirdAction &a) const
Definition: SnakeBird.h:182
SnakeBird::kBlock1
@ kBlock1
Definition: SnakeBird.h:259
SnakeBird::SnakeBird::exitLoc
int exitLoc
Definition: SnakeBird.h:435
SnakeBird::SnakeBird::editing
bool editing
Definition: SnakeBird.h:437
SnakeBird::SnakeBird::InvertAction
bool InvertAction(SnakeBirdAction &a) const
Definition: SnakeBird.h:330
SnakeBird::SnakeBird::OpenGLDraw
void OpenGLDraw(const SnakeBirdState &, const SnakeBirdAction &) const
Definition: SnakeBird.h:366
SnakeBird::SnakeBirdState::GetFruitPresent
bool GetFruitPresent(int which) const
Definition: SnakeBird.h:167
SnakeBird::SnakeBird::GCost
double GCost(const SnakeBirdState &node, const SnakeBirdAction &act) const
Definition: SnakeBird.h:348
SnakeBird::kCanEnterMask
const uint8_t kCanEnterMask
Definition: SnakeBird.h:240
SnakeBird::SnakeBird::GetNextState
void GetNextState(const SnakeBirdState &s1, SnakeBirdAction a, SnakeBirdState &s2) const
Definition: SnakeBird.h:324
std::hash< SnakeBird::SnakeBirdState >::operator()
std::size_t operator()(const SnakeBird::SnakeBirdState &k) const
Definition: SnakeBird.h:448
SnakeBird::SnakeBirdAction
Definition: SnakeBird.h:177
SnakeBird::SnakeBirdState::GetSnakeHeadLoc
int GetSnakeHeadLoc(int whichSnake) const
Definition: SnakeBird.h:60
SnakeBird::kDoneAnimation
@ kDoneAnimation
Definition: SnakeBird.h:209
SnakeBird::SnakeBird::GetWidth
int GetWidth() const
Definition: SnakeBird.h:308
GetY
int GetY(int loc)
Definition: Fling.h:68
SnakeBird::SnakeBirdState::SnakeBirdState
SnakeBirdState()
Definition: SnakeBird.h:49
SearchEnvironment
Definition: SearchEnvironment.h:30
SnakeBird::kBlock2
@ kBlock2
Definition: SnakeBird.h:260
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
SearchEnvironment.h
SnakeBird::SnakeBirdState::GetSnakeBodyEnd
int GetSnakeBodyEnd(int whichSnake) const
Definition: SnakeBird.h:65
SnakeBird::SnakeBird::GoalTest
virtual bool GoalTest(const SnakeBirdState &node) const
Goal Test if the goal is stored.
Definition: SnakeBird.h:352
SnakeBird::SnakeBird::render
std::array< SnakeBirdWorldObject, 512 > render
Definition: SnakeBird.h:428
SnakeBird::SnakeBirdState::snakeBodies
uint64_t snakeBodies
Definition: SnakeBird.h:45