game.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: game.cpp
  3. // Purpose: Life! game logic
  4. // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
  5. // Modified by:
  6. // Created: Jan/2000
  7. // Copyright: (c) 2000, Guillermo Rodriguez Garcia
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // ==========================================================================
  11. // headers, declarations, constants
  12. // ==========================================================================
  13. // For compilers that support precompilation, includes "wx/wx.h".
  14. #include "wx/wxprec.h"
  15. #ifdef __BORLANDC__
  16. #pragma hdrstop
  17. #endif
  18. #ifndef WX_PRECOMP
  19. #include "wx/wx.h"
  20. #endif
  21. #include "wx/log.h"
  22. #include "wx/module.h"
  23. #include "game.h"
  24. #include <string.h> // for memset
  25. #define CELLSARRAYSIZE 1024 // static array for BeginFind & co.
  26. #define ALLOCBOXES 16 // number of cellboxes to alloc at once
  27. #define MAXDEAD 8 // tics before removing cellbox from list
  28. // ==========================================================================
  29. // CellBox
  30. // ==========================================================================
  31. #define HASH(x, y) (((x >> 3) & 0x7f) << 7) + ((y >> 3) & 0x7f)
  32. #define HASHSIZE 16384 // hash table size (do not change!)
  33. #define CELLBOX 8 // cells in a cellbox (do not change!)
  34. class LifeCellBox
  35. {
  36. public:
  37. // members
  38. inline bool IsAlive(int dx, int dy) const;
  39. inline bool SetCell(int dx, int dy, bool alive);
  40. // attributes
  41. wxInt32 m_x, m_y; // position in universe
  42. wxUint32 m_live1, m_live2; // alive cells (1 bit per cell)
  43. wxUint32 m_old1, m_old2; // old values for m_live1, 2
  44. wxUint32 m_on[8]; // neighbouring info
  45. wxUint32 m_dead; // been dead for n generations
  46. LifeCellBox *m_up, *m_dn, *m_lf, *m_rt; // neighbour CellBoxes
  47. LifeCellBox *m_prev, *m_next; // in linked list
  48. LifeCellBox *m_hprev, *m_hnext; // in hash table
  49. };
  50. // IsAlive:
  51. // Returns whether cell dx, dy in this box is alive
  52. //
  53. bool LifeCellBox::IsAlive(int dx, int dy) const
  54. {
  55. if (dy > 3)
  56. return (m_live2 & 1 << ((dy - 4) * 8 + dx)) ? true : false ;
  57. else
  58. return (m_live1 & 1 << ((dy) * 8 + dx)) ? true : false ;
  59. }
  60. // SetCell:
  61. // Sets cell dx, dy in this box to 'alive', returns true if
  62. // the previous value was different, false if it was the same.
  63. //
  64. bool LifeCellBox::SetCell(int dx, int dy, bool alive)
  65. {
  66. if (IsAlive(dx, dy) != alive)
  67. {
  68. if (dy > 3)
  69. m_live2 ^= 1 << ((dy - 4) * 8 + dx);
  70. else
  71. m_live1 ^= 1 << ((dy) * 8 + dx);
  72. // reset this here to avoid updating problems
  73. m_dead = 0;
  74. return true;
  75. }
  76. else
  77. return false;
  78. }
  79. // ==========================================================================
  80. // Life
  81. // ==========================================================================
  82. // --------------------------------------------------------------------------
  83. // Ctor and dtor
  84. // --------------------------------------------------------------------------
  85. Life::Life()
  86. {
  87. // pattern description
  88. m_name = wxEmptyString;
  89. m_rules = wxEmptyString;
  90. m_description = wxEmptyString;
  91. // pattern data
  92. m_numcells = 0;
  93. m_boxes = new LifeCellBox *[HASHSIZE];
  94. m_head = NULL;
  95. m_available = NULL;
  96. for (int i = 0; i < HASHSIZE; i++)
  97. m_boxes[i] = NULL;
  98. // state vars for BeginFind & FindMore
  99. m_cells = new LifeCell[CELLSARRAYSIZE];
  100. m_ncells = 0;
  101. m_findmore = false;
  102. m_changed = false;
  103. }
  104. Life::~Life()
  105. {
  106. Clear();
  107. delete[] m_boxes;
  108. delete[] m_cells;
  109. }
  110. // Clear:
  111. // Clears the board, freeing all storage.
  112. //
  113. void Life::Clear()
  114. {
  115. LifeCellBox *c, *nc;
  116. // clear the hash table pointers
  117. for (int i = 0; i < HASHSIZE; i++)
  118. m_boxes[i] = NULL;
  119. // free used boxes
  120. c = m_head;
  121. while (c)
  122. {
  123. nc = c->m_next;
  124. delete c;
  125. c = nc;
  126. }
  127. m_head = NULL;
  128. // free available boxes
  129. c = m_available;
  130. while (c)
  131. {
  132. nc = c->m_next;
  133. delete c;
  134. c = nc;
  135. }
  136. m_available = NULL;
  137. // reset state
  138. m_name = wxEmptyString;
  139. m_rules = wxEmptyString;
  140. m_description = wxEmptyString;
  141. m_numcells = 0;
  142. }
  143. // --------------------------------------------------------------------------
  144. // Test and set individual cells
  145. // --------------------------------------------------------------------------
  146. // IsAlive:
  147. // Returns whether cell (x, y) is alive.
  148. //
  149. bool Life::IsAlive(wxInt32 x, wxInt32 y)
  150. {
  151. LifeCellBox *c = LinkBox(x, y, false);
  152. return (c && c->IsAlive( x - c->m_x, y - c->m_y ));
  153. }
  154. // SetCell:
  155. // Sets or clears cell (x, y), according to the 'alive' param.
  156. //
  157. void Life::SetCell(wxInt32 x, wxInt32 y, bool alive)
  158. {
  159. LifeCellBox *c = LinkBox(x, y);
  160. wxUint32 dx = x - c->m_x;
  161. wxUint32 dy = y - c->m_y;
  162. if (c->SetCell(dx, dy, alive))
  163. {
  164. if (alive)
  165. m_numcells++;
  166. else
  167. m_numcells--;
  168. }
  169. }
  170. void Life::SetPattern(const LifePattern& pattern)
  171. {
  172. wxArrayString data = pattern.m_shape;
  173. wxString line;
  174. long x = 0,
  175. y = 0;
  176. Clear();
  177. for (size_t n = 0; n < data.GetCount(); n++)
  178. {
  179. line = data[n];
  180. if ( (line.GetChar(0) != wxT('*')) &&
  181. (line.GetChar(0) != wxT('.')) )
  182. {
  183. // assume that it is a digit or a minus sign
  184. line.BeforeFirst(wxT(' ')).ToLong(&x);
  185. line.AfterFirst(wxT(' ')).ToLong(&y);
  186. }
  187. else
  188. {
  189. // pattern data
  190. for (size_t k = 0; k < line.Len(); k++)
  191. SetCell(x + k, y, line.GetChar(k) == wxT('*'));
  192. y++;
  193. }
  194. }
  195. m_name = pattern.m_name;
  196. m_rules = pattern.m_rules;
  197. m_description = pattern.m_description;
  198. }
  199. // --------------------------------------------------------------------------
  200. // Cellbox management functions
  201. // --------------------------------------------------------------------------
  202. // CreateBox:
  203. // Creates a box in x, y, either taking it from the list
  204. // of available boxes, or allocating a new one.
  205. //
  206. LifeCellBox* Life::CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv)
  207. {
  208. LifeCellBox *c;
  209. // if there are no available boxes, alloc a few more
  210. if (!m_available)
  211. for (int i = 1; i <= ALLOCBOXES; i++)
  212. {
  213. c = new LifeCellBox();
  214. if (!c)
  215. {
  216. // TODO: handle memory errors. Note that right now, if we
  217. // couldn't allocate at least one cellbox, we will crash
  218. // before leaving CreateBox(). Probably we should try to
  219. // allocate some boxes *before* the m_available list goes
  220. // empty, so that we have a margin to handle errors
  221. // gracefully.
  222. wxLogFatalError(_("Out of memory! Aborting..."));
  223. // NOTREACHED
  224. }
  225. c->m_next = m_available;
  226. m_available = c;
  227. }
  228. // take a cellbox from the list of available boxes
  229. c = m_available;
  230. m_available = c->m_next;
  231. // reset everything
  232. memset((void *) c, 0, sizeof(LifeCellBox));
  233. c->m_x = x;
  234. c->m_y = y;
  235. // insert c in the list
  236. c->m_next = m_head;
  237. m_head = c;
  238. if (c->m_next) c->m_next->m_prev = c;
  239. // insert c in the hash table
  240. c->m_hnext = m_boxes[hv];
  241. m_boxes[hv] = c;
  242. if (c->m_hnext) c->m_hnext->m_hprev = c;
  243. return c;
  244. }
  245. // LinkBox:
  246. // Returns a pointer to the box (x, y); if it didn't exist yet,
  247. // it returns NULL or creates a new one, depending on the value
  248. // of the 'create' parameter.
  249. //
  250. LifeCellBox* Life::LinkBox(wxInt32 x, wxInt32 y, bool create)
  251. {
  252. wxUint32 hv;
  253. LifeCellBox *c;
  254. x &= 0xfffffff8;
  255. y &= 0xfffffff8;
  256. hv = HASH(x, y);
  257. // search in the hash table
  258. for (c = m_boxes[hv]; c; c = c->m_hnext)
  259. if ((c->m_x == x) && (c->m_y == y)) return c;
  260. // if not found, and (create == true), create a new one
  261. return create? CreateBox(x, y, hv) : (LifeCellBox*) NULL;
  262. }
  263. // KillBox:
  264. // Removes this box from the list and the hash table and
  265. // puts it in the list of available boxes.
  266. //
  267. void Life::KillBox(LifeCellBox *c)
  268. {
  269. wxUint32 hv = HASH(c->m_x, c->m_y);
  270. // remove from the list
  271. if (c != m_head)
  272. c->m_prev->m_next = c->m_next;
  273. else
  274. m_head = c->m_next;
  275. // remove from the hash table
  276. if (c != m_boxes[hv])
  277. c->m_hprev->m_hnext = c->m_hnext;
  278. else
  279. m_boxes[hv] = c->m_hnext;
  280. // update neighbours
  281. if (c->m_next) c->m_next->m_prev = c->m_prev;
  282. if (c->m_hnext) c->m_hnext->m_hprev = c->m_hprev;
  283. if (c->m_up) c->m_up->m_dn = NULL;
  284. if (c->m_dn) c->m_dn->m_up = NULL;
  285. if (c->m_lf) c->m_lf->m_rt = NULL;
  286. if (c->m_rt) c->m_rt->m_lf = NULL;
  287. // append to the list of available boxes
  288. c->m_next = m_available;
  289. m_available = c;
  290. }
  291. // --------------------------------------------------------------------------
  292. // Navigation
  293. // --------------------------------------------------------------------------
  294. LifeCell Life::FindCenter()
  295. {
  296. double sx, sy;
  297. int n;
  298. sx = 0.0;
  299. sy = 0.0;
  300. n = 0;
  301. LifeCellBox *c;
  302. for (c = m_head; c; c = c->m_next)
  303. if (!c->m_dead)
  304. {
  305. sx += c->m_x;
  306. sy += c->m_y;
  307. n++;
  308. }
  309. if (n > 0)
  310. {
  311. sx = (sx / n) + CELLBOX / 2;
  312. sy = (sy / n) + CELLBOX / 2;
  313. }
  314. LifeCell cell;
  315. cell.i = (wxInt32) sx;
  316. cell.j = (wxInt32) sy;
  317. return cell;
  318. }
  319. LifeCell Life::FindNorth()
  320. {
  321. wxInt32 x = 0, y = 0;
  322. bool first = true;
  323. LifeCellBox *c;
  324. for (c = m_head; c; c = c->m_next)
  325. if (!c->m_dead && ((first) || (c->m_y < y)))
  326. {
  327. x = c->m_x;
  328. y = c->m_y;
  329. first = false;
  330. }
  331. LifeCell cell;
  332. cell.i = first? 0 : x + CELLBOX / 2;
  333. cell.j = first? 0 : y + CELLBOX / 2;
  334. return cell;
  335. }
  336. LifeCell Life::FindSouth()
  337. {
  338. wxInt32 x = 0, y = 0;
  339. bool first = true;
  340. LifeCellBox *c;
  341. for (c = m_head; c; c = c->m_next)
  342. if (!c->m_dead && ((first) || (c->m_y > y)))
  343. {
  344. x = c->m_x;
  345. y = c->m_y;
  346. first = false;
  347. }
  348. LifeCell cell;
  349. cell.i = first? 0 : x + CELLBOX / 2;
  350. cell.j = first? 0 : y + CELLBOX / 2;
  351. return cell;
  352. }
  353. LifeCell Life::FindWest()
  354. {
  355. wxInt32 x = 0, y = 0;
  356. bool first = true;
  357. LifeCellBox *c;
  358. for (c = m_head; c; c = c->m_next)
  359. if (!c->m_dead && ((first) || (c->m_x < x)))
  360. {
  361. x = c->m_x;
  362. y = c->m_y;
  363. first = false;
  364. }
  365. LifeCell cell;
  366. cell.i = first? 0 : x + CELLBOX / 2;
  367. cell.j = first? 0 : y + CELLBOX / 2;
  368. return cell;
  369. }
  370. LifeCell Life::FindEast()
  371. {
  372. wxInt32 x = 0, y = 0;
  373. bool first = true;
  374. LifeCellBox *c;
  375. for (c = m_head; c; c = c->m_next)
  376. if (!c->m_dead && ((first) || (c->m_x > x)))
  377. {
  378. x = c->m_x;
  379. y = c->m_y;
  380. first = false;
  381. }
  382. LifeCell cell;
  383. cell.i = first? 0 : x + CELLBOX / 2;
  384. cell.j = first? 0 : y + CELLBOX / 2;
  385. return cell;
  386. }
  387. // --------------------------------------------------------------------------
  388. // FindMore & co.
  389. // --------------------------------------------------------------------------
  390. // DoLine:
  391. // Post eight cells to the cell arrays - leave out the fourth
  392. // argument (or pass 0, the default value) to post alive cells
  393. // only, else it will post cells which have changed.
  394. //
  395. void Life::DoLine(wxInt32 x, wxInt32 y, wxUint32 live, wxUint32 old)
  396. {
  397. wxUint32 diff = (live ^ old) & 0xff;
  398. if (!diff) return;
  399. for (wxInt32 k = 8; k; k--, x++)
  400. {
  401. if (diff & 0x01)
  402. {
  403. m_cells[m_ncells].i = x;
  404. m_cells[m_ncells].j = y;
  405. m_ncells++;
  406. }
  407. diff >>= 1;
  408. }
  409. }
  410. void Life::BeginFind(wxInt32 x0, wxInt32 y0, wxInt32 x1, wxInt32 y1, bool changed)
  411. {
  412. // TODO: optimize for the case where the maximum number of
  413. // cellboxes that fit in the specified viewport is smaller
  414. // than the current total of boxes; iterating over the list
  415. // should then be faster than searching in the hash table.
  416. m_x0 = m_x = x0 & 0xfffffff8;
  417. m_y0 = m_y = y0 & 0xfffffff8;
  418. m_x1 = (x1 + 7) & 0xfffffff8;
  419. m_y1 = (y1 + 7) & 0xfffffff8;
  420. m_findmore = true;
  421. m_changed = changed;
  422. }
  423. bool Life::FindMore(LifeCell *cells[], size_t *ncells)
  424. {
  425. LifeCellBox *c;
  426. *cells = m_cells;
  427. m_ncells = 0;
  428. if (m_changed)
  429. {
  430. for ( ; m_y <= m_y1; m_y += 8, m_x = m_x0)
  431. for ( ; m_x <= m_x1; m_x += 8)
  432. {
  433. if ((c = LinkBox(m_x, m_y, false)) == NULL)
  434. continue;
  435. // check whether there is enough space left in the array
  436. if (m_ncells > (CELLSARRAYSIZE - 64))
  437. {
  438. *ncells = m_ncells;
  439. return false;
  440. }
  441. DoLine(m_x, m_y , c->m_live1, c->m_old1 );
  442. DoLine(m_x, m_y + 1, c->m_live1 >> 8, c->m_old1 >> 8 );
  443. DoLine(m_x, m_y + 2, c->m_live1 >> 16, c->m_old1 >> 16);
  444. DoLine(m_x, m_y + 3, c->m_live1 >> 24, c->m_old1 >> 24);
  445. DoLine(m_x, m_y + 4, c->m_live2, c->m_old2 );
  446. DoLine(m_x, m_y + 5, c->m_live2 >> 8, c->m_old2 >> 8 );
  447. DoLine(m_x, m_y + 6, c->m_live2 >> 16, c->m_old2 >> 16);
  448. DoLine(m_x, m_y + 7, c->m_live2 >> 24, c->m_old2 >> 24);
  449. }
  450. }
  451. else
  452. {
  453. for ( ; m_y <= m_y1; m_y += 8, m_x = m_x0)
  454. for ( ; m_x <= m_x1; m_x += 8)
  455. {
  456. if ((c = LinkBox(m_x, m_y, false)) == NULL)
  457. continue;
  458. // check whether there is enough space left in the array
  459. if (m_ncells > (CELLSARRAYSIZE - 64))
  460. {
  461. *ncells = m_ncells;
  462. return false;
  463. }
  464. DoLine(m_x, m_y , c->m_live1 );
  465. DoLine(m_x, m_y + 1, c->m_live1 >> 8 );
  466. DoLine(m_x, m_y + 2, c->m_live1 >> 16);
  467. DoLine(m_x, m_y + 3, c->m_live1 >> 24);
  468. DoLine(m_x, m_y + 4, c->m_live2 );
  469. DoLine(m_x, m_y + 5, c->m_live2 >> 8 );
  470. DoLine(m_x, m_y + 6, c->m_live2 >> 16);
  471. DoLine(m_x, m_y + 7, c->m_live2 >> 24);
  472. }
  473. }
  474. *ncells = m_ncells;
  475. m_findmore = false;
  476. return true;
  477. }
  478. // --------------------------------------------------------------------------
  479. // Evolution engine
  480. // --------------------------------------------------------------------------
  481. extern unsigned char *g_tab;
  482. extern int g_tab1[];
  483. extern int g_tab2[];
  484. // NextTic:
  485. // Advance one step in evolution :-)
  486. //
  487. bool Life::NextTic()
  488. {
  489. LifeCellBox *c, *up, *dn, *lf, *rt;
  490. wxUint32 t1, t2, t3, t4;
  491. bool changed = false;
  492. m_numcells = 0;
  493. // Stage 1:
  494. // Compute neighbours of each cell
  495. //
  496. // WARNING: unrolled loops and lengthy code follows!
  497. //
  498. c = m_head;
  499. while (c)
  500. {
  501. if (! (c->m_live1 || c->m_live2))
  502. {
  503. c = c->m_next;
  504. continue;
  505. }
  506. up = c->m_up;
  507. dn = c->m_dn;
  508. lf = c->m_lf;
  509. rt = c->m_rt;
  510. // up
  511. t1 = c->m_live1 & 0x000000ff;
  512. if (t1)
  513. {
  514. if (!up)
  515. {
  516. up = LinkBox(c->m_x, c->m_y - 8);
  517. up->m_dn = c;
  518. }
  519. t2 = g_tab1[t1];
  520. up->m_on[7] += t2;
  521. c->m_on[1] += t2;
  522. c->m_on[0] += g_tab2[t1];
  523. }
  524. // down
  525. t1 = (c->m_live2 & 0xff000000) >> 24;
  526. if (t1)
  527. {
  528. if (!dn)
  529. {
  530. dn = LinkBox(c->m_x, c->m_y + 8);
  531. dn->m_up = c;
  532. }
  533. t2 = g_tab1[t1];
  534. dn->m_on[0] += t2;
  535. c->m_on[6] += t2;
  536. c->m_on[7] += g_tab2[t1];
  537. }
  538. t1 = c->m_live1;
  539. t2 = c->m_live2;
  540. // left
  541. if (t1 & 0x01010101)
  542. {
  543. if (!lf)
  544. {
  545. lf = LinkBox(c->m_x - 8, c->m_y);
  546. lf->m_rt = c;
  547. }
  548. if (t1 & 0x00000001)
  549. {
  550. if (!lf->m_up)
  551. {
  552. lf->m_up = LinkBox(c->m_x - 8, c->m_y - 8);
  553. lf->m_up->m_dn = lf;
  554. }
  555. lf->m_up->m_on[7] += 0x10000000;
  556. lf->m_on[0] += 0x10000000;
  557. lf->m_on[1] += 0x10000000;
  558. }
  559. if (t1 & 0x00000100)
  560. {
  561. lf->m_on[0] += 0x10000000;
  562. lf->m_on[1] += 0x10000000;
  563. lf->m_on[2] += 0x10000000;
  564. }
  565. if (t1 & 0x00010000)
  566. {
  567. lf->m_on[1] += 0x10000000;
  568. lf->m_on[2] += 0x10000000;
  569. lf->m_on[3] += 0x10000000;
  570. }
  571. if (t1 & 0x01000000)
  572. {
  573. lf->m_on[2] += 0x10000000;
  574. lf->m_on[3] += 0x10000000;
  575. lf->m_on[4] += 0x10000000;
  576. }
  577. }
  578. if (t2 & 0x01010101)
  579. {
  580. if (!lf)
  581. {
  582. lf = LinkBox(c->m_x - 8, c->m_y);
  583. lf->m_rt = c;
  584. }
  585. if (t2 & 0x00000001)
  586. {
  587. lf->m_on[3] += 0x10000000;
  588. lf->m_on[4] += 0x10000000;
  589. lf->m_on[5] += 0x10000000;
  590. }
  591. if (t2 & 0x00000100)
  592. {
  593. lf->m_on[4] += 0x10000000;
  594. lf->m_on[5] += 0x10000000;
  595. lf->m_on[6] += 0x10000000;
  596. }
  597. if (t2 & 0x00010000)
  598. {
  599. lf->m_on[5] += 0x10000000;
  600. lf->m_on[6] += 0x10000000;
  601. lf->m_on[7] += 0x10000000;
  602. }
  603. if (t2 & 0x01000000)
  604. {
  605. if (!lf->m_dn)
  606. {
  607. lf->m_dn = LinkBox(c->m_x - 8, c->m_y + 8);
  608. lf->m_dn->m_up = lf;
  609. }
  610. lf->m_on[6] += 0x10000000;
  611. lf->m_on[7] += 0x10000000;
  612. lf->m_dn->m_on[0] += 0x10000000;
  613. }
  614. }
  615. // right
  616. if (t1 & 0x80808080)
  617. {
  618. if (!rt)
  619. {
  620. rt = LinkBox(c->m_x + 8, c->m_y);
  621. rt->m_lf = c;
  622. }
  623. if (t1 & 0x00000080)
  624. {
  625. if (!rt->m_up)
  626. {
  627. rt->m_up = LinkBox(c->m_x + 8, c->m_y - 8);
  628. rt->m_up->m_dn = rt;
  629. }
  630. rt->m_up->m_on[7] += 0x00000001;
  631. rt->m_on[0] += 0x00000001;
  632. rt->m_on[1] += 0x00000001;
  633. }
  634. if (t1 & 0x00008000)
  635. {
  636. rt->m_on[0] += 0x00000001;
  637. rt->m_on[1] += 0x00000001;
  638. rt->m_on[2] += 0x00000001;
  639. }
  640. if (t1 & 0x00800000)
  641. {
  642. rt->m_on[1] += 0x00000001;
  643. rt->m_on[2] += 0x00000001;
  644. rt->m_on[3] += 0x00000001;
  645. }
  646. if (t1 & 0x80000000)
  647. {
  648. rt->m_on[2] += 0x00000001;
  649. rt->m_on[3] += 0x00000001;
  650. rt->m_on[4] += 0x00000001;
  651. }
  652. }
  653. if (t2 & 0x80808080)
  654. {
  655. if (!rt)
  656. {
  657. rt = LinkBox(c->m_x + 8, c->m_y);
  658. rt->m_lf = c;
  659. }
  660. if (t2 & 0x00000080)
  661. {
  662. rt->m_on[3] += 0x00000001;
  663. rt->m_on[4] += 0x00000001;
  664. rt->m_on[5] += 0x00000001;
  665. }
  666. if (t2 & 0x00008000)
  667. {
  668. rt->m_on[4] += 0x00000001;
  669. rt->m_on[5] += 0x00000001;
  670. rt->m_on[6] += 0x00000001;
  671. }
  672. if (t2 & 0x00800000)
  673. {
  674. rt->m_on[5] += 0x00000001;
  675. rt->m_on[6] += 0x00000001;
  676. rt->m_on[7] += 0x00000001;
  677. }
  678. if (t2 & 0x80000000)
  679. {
  680. if (!rt->m_dn)
  681. {
  682. rt->m_dn = LinkBox(c->m_x + 8, c->m_y + 8);
  683. rt->m_dn->m_up = rt;
  684. }
  685. rt->m_on[6] += 0x00000001;
  686. rt->m_on[7] += 0x00000001;
  687. rt->m_dn->m_on[0] += 0x00000001;
  688. }
  689. }
  690. // inner cells
  691. int i;
  692. for (i = 1; i <= 3; i++)
  693. {
  694. t1 = ((c->m_live1) >> (i * 8)) & 0x000000ff;
  695. if (t1)
  696. {
  697. c->m_on[i - 1] += g_tab1[t1];
  698. c->m_on[i ] += g_tab2[t1];
  699. c->m_on[i + 1] += g_tab1[t1];
  700. }
  701. }
  702. for (i = 0; i <= 2; i++)
  703. {
  704. t1 = ((c->m_live2) >> (i * 8)) & 0x000000ff;
  705. if (t1)
  706. {
  707. c->m_on[i + 3] += g_tab1[t1];
  708. c->m_on[i + 4] += g_tab2[t1];
  709. c->m_on[i + 5] += g_tab1[t1];
  710. }
  711. }
  712. c->m_up = up;
  713. c->m_dn = dn;
  714. c->m_lf = lf;
  715. c->m_rt = rt;
  716. c = c->m_next;
  717. }
  718. // Stage 2:
  719. // Stabilize
  720. //
  721. c = m_head;
  722. while (c)
  723. {
  724. t1 = 0;
  725. t2 = 0;
  726. t3 = c->m_live1;
  727. c->m_old1 = t3;
  728. t4 = c->m_on[0];
  729. t1 |= g_tab[ ((t4 & 0x0000ffff) << 4 ) + ((t3 ) & 0xf) ];
  730. t1 |= g_tab[ ((t4 & 0xffff0000) >> 12) + ((t3 >> 4 ) & 0xf) ] << 4;
  731. t4 = c->m_on[1];
  732. t1 |= g_tab[ ((t4 & 0x0000ffff) << 4 ) + ((t3 >> 8 ) & 0xf) ] << 8;
  733. t1 |= g_tab[ ((t4 & 0xffff0000) >> 12) + ((t3 >> 12) & 0xf) ] << 12;
  734. t4 = c->m_on[2];
  735. t1 |= g_tab[ ((t4 & 0x0000ffff) << 4 ) + ((t3 >> 16) & 0xf) ] << 16;
  736. t1 |= g_tab[ ((t4 & 0xffff0000) >> 12) + ((t3 >> 20) & 0xf) ] << 20;
  737. t4 = c->m_on[3];
  738. t1 |= g_tab[ ((t4 & 0x0000ffff) << 4 ) + ((t3 >> 24) & 0xf) ] << 24;
  739. t1 |= g_tab[ ((t4 & 0xffff0000) >> 12) + ((t3 >> 28) & 0xf) ] << 28;
  740. t3 = c->m_live2;
  741. c->m_old2 = t3;
  742. t4 = c->m_on[4];
  743. t2 |= g_tab[ ((t4 & 0x0000ffff) << 4 ) + ((t3 ) & 0xf) ];
  744. t2 |= g_tab[ ((t4 & 0xffff0000) >> 12) + ((t3 >> 4 ) & 0xf) ] << 4;
  745. t4 = c->m_on[5];
  746. t2 |= g_tab[ ((t4 & 0x0000ffff) << 4 ) + ((t3 >> 8 ) & 0xf) ] << 8;
  747. t2 |= g_tab[ ((t4 & 0xffff0000) >> 12) + ((t3 >> 12) & 0xf) ] << 12;
  748. t4 = c->m_on[6];
  749. t2 |= g_tab[ ((t4 & 0x0000ffff) << 4 ) + ((t3 >> 16) & 0xf) ] << 16;
  750. t2 |= g_tab[ ((t4 & 0xffff0000) >> 12) + ((t3 >> 20) & 0xf) ] << 20;
  751. t4 = c->m_on[7];
  752. t2 |= g_tab[ ((t4 & 0x0000ffff) << 4 ) + ((t3 >> 24) & 0xf) ] << 24;
  753. t2 |= g_tab[ ((t4 & 0xffff0000) >> 12) + ((t3 >> 28) & 0xf) ] << 28;
  754. c->m_on[0] = c->m_on[1] = c->m_on[2] = c->m_on[3] =
  755. c->m_on[4] = c->m_on[5] = c->m_on[6] = c->m_on[7] = 0;
  756. c->m_live1 = t1;
  757. c->m_live2 = t2;
  758. // count alive cells
  759. #if 1
  760. wxUint32 t1_, t2_;
  761. t1_ = (t1 & 0x55555555) + (t1 >> 1 & 0x55555555);
  762. t1_ = (t1_ & 0x33333333) + (t1_ >> 2 & 0x33333333);
  763. t2_ = (t2 & 0x55555555) + (t2 >> 1 & 0x55555555);
  764. t2_ = (t2_ & 0x33333333) + (t2_ >> 2 & 0x33333333) + t1_;
  765. t2_ = (t2_ & 0x0F0F0F0F) + (t2_ >> 4 & 0x0F0F0F0F);
  766. t2_ = (t2_ & 0x00FF00FF) + (t2_ >> 8 & 0x00FF00FF);
  767. m_numcells += (t2_ & 0xFF) + (t2_ >> 16 & 0xFF);
  768. #else
  769. // Original, slower code
  770. for (int i = 0; i < 32; i++)
  771. {
  772. if (t1 & (1 << i)) m_numcells++;
  773. if (t2 & (1 << i)) m_numcells++;
  774. }
  775. #endif
  776. changed |= ((t1 ^ c->m_old1) || (t2 ^ c->m_old2));
  777. // mark, and discard if necessary, dead boxes
  778. if (t1 || t2)
  779. {
  780. c->m_dead = 0;
  781. c = c->m_next;
  782. }
  783. else
  784. {
  785. LifeCellBox *aux = c->m_next;
  786. if (c->m_dead++ > MAXDEAD)
  787. KillBox(c);
  788. c = aux;
  789. }
  790. }
  791. return changed;
  792. }
  793. // ==========================================================================
  794. // LifeModule
  795. // ==========================================================================
  796. // A module to pregenerate lookup tables without having to do it
  797. // from the application.
  798. class LifeModule: public wxModule
  799. {
  800. DECLARE_DYNAMIC_CLASS(LifeModule)
  801. public:
  802. LifeModule() {};
  803. bool OnInit();
  804. void OnExit();
  805. };
  806. IMPLEMENT_DYNAMIC_CLASS(LifeModule, wxModule)
  807. bool LifeModule::OnInit()
  808. {
  809. // see below
  810. g_tab = new unsigned char [0xfffff];
  811. if (!g_tab) return false;
  812. for (wxUint32 i = 0; i < 0xfffff; i++)
  813. {
  814. wxUint32 val = i >> 4;
  815. wxUint32 old = i & 0x0000f;
  816. wxUint32 live = 0;
  817. for (int j = 0; j < 4; j++)
  818. {
  819. live >>= 1;
  820. if (((val & 0xf) == 3) || (((val & 0xf) == 2) && (old & 0x1)))
  821. live |= 0x8;
  822. old >>= 1;
  823. val >>= 4;
  824. }
  825. g_tab[i] = (unsigned char) live;
  826. }
  827. return true;
  828. }
  829. void LifeModule::OnExit()
  830. {
  831. delete [] g_tab;
  832. }
  833. // This table converts from number of neighbors (like in on[]) to
  834. // bits, for a set of four cells. It takes as index a five-digit
  835. // hexadecimal value (0xNNNNB) where Ns hold number of neighbors
  836. // for each cell and B holds their previous state.
  837. //
  838. unsigned char *g_tab;
  839. // This table converts from bits (like in live1, live2) to number
  840. // of neighbors for each cell in the upper or lower row.
  841. //
  842. int g_tab1[]=
  843. {
  844. 0x00000000,
  845. 0x00000011,
  846. 0x00000111,
  847. 0x00000122,
  848. 0x00001110,
  849. 0x00001121,
  850. 0x00001221,
  851. 0x00001232,
  852. 0x00011100,
  853. 0x00011111,
  854. 0x00011211,
  855. 0x00011222,
  856. 0x00012210,
  857. 0x00012221,
  858. 0x00012321,
  859. 0x00012332,
  860. 0x00111000,
  861. 0x00111011,
  862. 0x00111111,
  863. 0x00111122,
  864. 0x00112110,
  865. 0x00112121,
  866. 0x00112221,
  867. 0x00112232,
  868. 0x00122100,
  869. 0x00122111,
  870. 0x00122211,
  871. 0x00122222,
  872. 0x00123210,
  873. 0x00123221,
  874. 0x00123321,
  875. 0x00123332,
  876. 0x01110000,
  877. 0x01110011,
  878. 0x01110111,
  879. 0x01110122,
  880. 0x01111110,
  881. 0x01111121,
  882. 0x01111221,
  883. 0x01111232,
  884. 0x01121100,
  885. 0x01121111,
  886. 0x01121211,
  887. 0x01121222,
  888. 0x01122210,
  889. 0x01122221,
  890. 0x01122321,
  891. 0x01122332,
  892. 0x01221000,
  893. 0x01221011,
  894. 0x01221111,
  895. 0x01221122,
  896. 0x01222110,
  897. 0x01222121,
  898. 0x01222221,
  899. 0x01222232,
  900. 0x01232100,
  901. 0x01232111,
  902. 0x01232211,
  903. 0x01232222,
  904. 0x01233210,
  905. 0x01233221,
  906. 0x01233321,
  907. 0x01233332,
  908. 0x11100000,
  909. 0x11100011,
  910. 0x11100111,
  911. 0x11100122,
  912. 0x11101110,
  913. 0x11101121,
  914. 0x11101221,
  915. 0x11101232,
  916. 0x11111100,
  917. 0x11111111,
  918. 0x11111211,
  919. 0x11111222,
  920. 0x11112210,
  921. 0x11112221,
  922. 0x11112321,
  923. 0x11112332,
  924. 0x11211000,
  925. 0x11211011,
  926. 0x11211111,
  927. 0x11211122,
  928. 0x11212110,
  929. 0x11212121,
  930. 0x11212221,
  931. 0x11212232,
  932. 0x11222100,
  933. 0x11222111,
  934. 0x11222211,
  935. 0x11222222,
  936. 0x11223210,
  937. 0x11223221,
  938. 0x11223321,
  939. 0x11223332,
  940. 0x12210000,
  941. 0x12210011,
  942. 0x12210111,
  943. 0x12210122,
  944. 0x12211110,
  945. 0x12211121,
  946. 0x12211221,
  947. 0x12211232,
  948. 0x12221100,
  949. 0x12221111,
  950. 0x12221211,
  951. 0x12221222,
  952. 0x12222210,
  953. 0x12222221,
  954. 0x12222321,
  955. 0x12222332,
  956. 0x12321000,
  957. 0x12321011,
  958. 0x12321111,
  959. 0x12321122,
  960. 0x12322110,
  961. 0x12322121,
  962. 0x12322221,
  963. 0x12322232,
  964. 0x12332100,
  965. 0x12332111,
  966. 0x12332211,
  967. 0x12332222,
  968. 0x12333210,
  969. 0x12333221,
  970. 0x12333321,
  971. 0x12333332,
  972. 0x11000000,
  973. 0x11000011,
  974. 0x11000111,
  975. 0x11000122,
  976. 0x11001110,
  977. 0x11001121,
  978. 0x11001221,
  979. 0x11001232,
  980. 0x11011100,
  981. 0x11011111,
  982. 0x11011211,
  983. 0x11011222,
  984. 0x11012210,
  985. 0x11012221,
  986. 0x11012321,
  987. 0x11012332,
  988. 0x11111000,
  989. 0x11111011,
  990. 0x11111111,
  991. 0x11111122,
  992. 0x11112110,
  993. 0x11112121,
  994. 0x11112221,
  995. 0x11112232,
  996. 0x11122100,
  997. 0x11122111,
  998. 0x11122211,
  999. 0x11122222,
  1000. 0x11123210,
  1001. 0x11123221,
  1002. 0x11123321,
  1003. 0x11123332,
  1004. 0x12110000,
  1005. 0x12110011,
  1006. 0x12110111,
  1007. 0x12110122,
  1008. 0x12111110,
  1009. 0x12111121,
  1010. 0x12111221,
  1011. 0x12111232,
  1012. 0x12121100,
  1013. 0x12121111,
  1014. 0x12121211,
  1015. 0x12121222,
  1016. 0x12122210,
  1017. 0x12122221,
  1018. 0x12122321,
  1019. 0x12122332,
  1020. 0x12221000,
  1021. 0x12221011,
  1022. 0x12221111,
  1023. 0x12221122,
  1024. 0x12222110,
  1025. 0x12222121,
  1026. 0x12222221,
  1027. 0x12222232,
  1028. 0x12232100,
  1029. 0x12232111,
  1030. 0x12232211,
  1031. 0x12232222,
  1032. 0x12233210,
  1033. 0x12233221,
  1034. 0x12233321,
  1035. 0x12233332,
  1036. 0x22100000,
  1037. 0x22100011,
  1038. 0x22100111,
  1039. 0x22100122,
  1040. 0x22101110,
  1041. 0x22101121,
  1042. 0x22101221,
  1043. 0x22101232,
  1044. 0x22111100,
  1045. 0x22111111,
  1046. 0x22111211,
  1047. 0x22111222,
  1048. 0x22112210,
  1049. 0x22112221,
  1050. 0x22112321,
  1051. 0x22112332,
  1052. 0x22211000,
  1053. 0x22211011,
  1054. 0x22211111,
  1055. 0x22211122,
  1056. 0x22212110,
  1057. 0x22212121,
  1058. 0x22212221,
  1059. 0x22212232,
  1060. 0x22222100,
  1061. 0x22222111,
  1062. 0x22222211,
  1063. 0x22222222,
  1064. 0x22223210,
  1065. 0x22223221,
  1066. 0x22223321,
  1067. 0x22223332,
  1068. 0x23210000,
  1069. 0x23210011,
  1070. 0x23210111,
  1071. 0x23210122,
  1072. 0x23211110,
  1073. 0x23211121,
  1074. 0x23211221,
  1075. 0x23211232,
  1076. 0x23221100,
  1077. 0x23221111,
  1078. 0x23221211,
  1079. 0x23221222,
  1080. 0x23222210,
  1081. 0x23222221,
  1082. 0x23222321,
  1083. 0x23222332,
  1084. 0x23321000,
  1085. 0x23321011,
  1086. 0x23321111,
  1087. 0x23321122,
  1088. 0x23322110,
  1089. 0x23322121,
  1090. 0x23322221,
  1091. 0x23322232,
  1092. 0x23332100,
  1093. 0x23332111,
  1094. 0x23332211,
  1095. 0x23332222,
  1096. 0x23333210,
  1097. 0x23333221,
  1098. 0x23333321,
  1099. 0x23333332
  1100. };
  1101. // This table converts from bits (like in live1, live2) to number
  1102. // of neighbors for each cell in the same row (excluding ourselves)
  1103. //
  1104. int g_tab2[]=
  1105. {
  1106. 0x00000000,
  1107. 0x00000010,
  1108. 0x00000101,
  1109. 0x00000111,
  1110. 0x00001010,
  1111. 0x00001020,
  1112. 0x00001111,
  1113. 0x00001121,
  1114. 0x00010100,
  1115. 0x00010110,
  1116. 0x00010201,
  1117. 0x00010211,
  1118. 0x00011110,
  1119. 0x00011120,
  1120. 0x00011211,
  1121. 0x00011221,
  1122. 0x00101000,
  1123. 0x00101010,
  1124. 0x00101101,
  1125. 0x00101111,
  1126. 0x00102010,
  1127. 0x00102020,
  1128. 0x00102111,
  1129. 0x00102121,
  1130. 0x00111100,
  1131. 0x00111110,
  1132. 0x00111201,
  1133. 0x00111211,
  1134. 0x00112110,
  1135. 0x00112120,
  1136. 0x00112211,
  1137. 0x00112221,
  1138. 0x01010000,
  1139. 0x01010010,
  1140. 0x01010101,
  1141. 0x01010111,
  1142. 0x01011010,
  1143. 0x01011020,
  1144. 0x01011111,
  1145. 0x01011121,
  1146. 0x01020100,
  1147. 0x01020110,
  1148. 0x01020201,
  1149. 0x01020211,
  1150. 0x01021110,
  1151. 0x01021120,
  1152. 0x01021211,
  1153. 0x01021221,
  1154. 0x01111000,
  1155. 0x01111010,
  1156. 0x01111101,
  1157. 0x01111111,
  1158. 0x01112010,
  1159. 0x01112020,
  1160. 0x01112111,
  1161. 0x01112121,
  1162. 0x01121100,
  1163. 0x01121110,
  1164. 0x01121201,
  1165. 0x01121211,
  1166. 0x01122110,
  1167. 0x01122120,
  1168. 0x01122211,
  1169. 0x01122221,
  1170. 0x10100000,
  1171. 0x10100010,
  1172. 0x10100101,
  1173. 0x10100111,
  1174. 0x10101010,
  1175. 0x10101020,
  1176. 0x10101111,
  1177. 0x10101121,
  1178. 0x10110100,
  1179. 0x10110110,
  1180. 0x10110201,
  1181. 0x10110211,
  1182. 0x10111110,
  1183. 0x10111120,
  1184. 0x10111211,
  1185. 0x10111221,
  1186. 0x10201000,
  1187. 0x10201010,
  1188. 0x10201101,
  1189. 0x10201111,
  1190. 0x10202010,
  1191. 0x10202020,
  1192. 0x10202111,
  1193. 0x10202121,
  1194. 0x10211100,
  1195. 0x10211110,
  1196. 0x10211201,
  1197. 0x10211211,
  1198. 0x10212110,
  1199. 0x10212120,
  1200. 0x10212211,
  1201. 0x10212221,
  1202. 0x11110000,
  1203. 0x11110010,
  1204. 0x11110101,
  1205. 0x11110111,
  1206. 0x11111010,
  1207. 0x11111020,
  1208. 0x11111111,
  1209. 0x11111121,
  1210. 0x11120100,
  1211. 0x11120110,
  1212. 0x11120201,
  1213. 0x11120211,
  1214. 0x11121110,
  1215. 0x11121120,
  1216. 0x11121211,
  1217. 0x11121221,
  1218. 0x11211000,
  1219. 0x11211010,
  1220. 0x11211101,
  1221. 0x11211111,
  1222. 0x11212010,
  1223. 0x11212020,
  1224. 0x11212111,
  1225. 0x11212121,
  1226. 0x11221100,
  1227. 0x11221110,
  1228. 0x11221201,
  1229. 0x11221211,
  1230. 0x11222110,
  1231. 0x11222120,
  1232. 0x11222211,
  1233. 0x11222221,
  1234. 0x01000000,
  1235. 0x01000010,
  1236. 0x01000101,
  1237. 0x01000111,
  1238. 0x01001010,
  1239. 0x01001020,
  1240. 0x01001111,
  1241. 0x01001121,
  1242. 0x01010100,
  1243. 0x01010110,
  1244. 0x01010201,
  1245. 0x01010211,
  1246. 0x01011110,
  1247. 0x01011120,
  1248. 0x01011211,
  1249. 0x01011221,
  1250. 0x01101000,
  1251. 0x01101010,
  1252. 0x01101101,
  1253. 0x01101111,
  1254. 0x01102010,
  1255. 0x01102020,
  1256. 0x01102111,
  1257. 0x01102121,
  1258. 0x01111100,
  1259. 0x01111110,
  1260. 0x01111201,
  1261. 0x01111211,
  1262. 0x01112110,
  1263. 0x01112120,
  1264. 0x01112211,
  1265. 0x01112221,
  1266. 0x02010000,
  1267. 0x02010010,
  1268. 0x02010101,
  1269. 0x02010111,
  1270. 0x02011010,
  1271. 0x02011020,
  1272. 0x02011111,
  1273. 0x02011121,
  1274. 0x02020100,
  1275. 0x02020110,
  1276. 0x02020201,
  1277. 0x02020211,
  1278. 0x02021110,
  1279. 0x02021120,
  1280. 0x02021211,
  1281. 0x02021221,
  1282. 0x02111000,
  1283. 0x02111010,
  1284. 0x02111101,
  1285. 0x02111111,
  1286. 0x02112010,
  1287. 0x02112020,
  1288. 0x02112111,
  1289. 0x02112121,
  1290. 0x02121100,
  1291. 0x02121110,
  1292. 0x02121201,
  1293. 0x02121211,
  1294. 0x02122110,
  1295. 0x02122120,
  1296. 0x02122211,
  1297. 0x02122221,
  1298. 0x11100000,
  1299. 0x11100010,
  1300. 0x11100101,
  1301. 0x11100111,
  1302. 0x11101010,
  1303. 0x11101020,
  1304. 0x11101111,
  1305. 0x11101121,
  1306. 0x11110100,
  1307. 0x11110110,
  1308. 0x11110201,
  1309. 0x11110211,
  1310. 0x11111110,
  1311. 0x11111120,
  1312. 0x11111211,
  1313. 0x11111221,
  1314. 0x11201000,
  1315. 0x11201010,
  1316. 0x11201101,
  1317. 0x11201111,
  1318. 0x11202010,
  1319. 0x11202020,
  1320. 0x11202111,
  1321. 0x11202121,
  1322. 0x11211100,
  1323. 0x11211110,
  1324. 0x11211201,
  1325. 0x11211211,
  1326. 0x11212110,
  1327. 0x11212120,
  1328. 0x11212211,
  1329. 0x11212221,
  1330. 0x12110000,
  1331. 0x12110010,
  1332. 0x12110101,
  1333. 0x12110111,
  1334. 0x12111010,
  1335. 0x12111020,
  1336. 0x12111111,
  1337. 0x12111121,
  1338. 0x12120100,
  1339. 0x12120110,
  1340. 0x12120201,
  1341. 0x12120211,
  1342. 0x12121110,
  1343. 0x12121120,
  1344. 0x12121211,
  1345. 0x12121221,
  1346. 0x12211000,
  1347. 0x12211010,
  1348. 0x12211101,
  1349. 0x12211111,
  1350. 0x12212010,
  1351. 0x12212020,
  1352. 0x12212111,
  1353. 0x12212121,
  1354. 0x12221100,
  1355. 0x12221110,
  1356. 0x12221201,
  1357. 0x12221211,
  1358. 0x12222110,
  1359. 0x12222120,
  1360. 0x12222211,
  1361. 0x12222221
  1362. };