summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Paul <n@nc0.fr>2024-03-07 11:25:16 +0100
committerNicolas Paul <n@nc0.fr>2024-03-08 23:12:55 +0100
commit7c4e400fe9991af8f395dec12a047a450558178e (patch)
treed8595cf03453e13a4e6236eb1460ef99b5305d70
parent34995af183d013443fe4a7153774cb452b5cc334 (diff)
game: Define the Cell type
A cell is the smallest unit in the Life2 simulation game. It carries information about its aliveness (whether or not it is filled), and the team it is part of (TEAM_A or TEAM_B). The cell type is currently implemented as an enumeration of integers, merging the two states in one value. I believe integers are the fastest type JavaScript runtimes can manipulate, especially at this small scale (unsigned 8-bit integers). Given these properties, I believe using integers will avoid huge performance and memory consumption in the browser when dealing with boards of larger sizes (or even pseudo infinite sizes...). Signed-off-by: Nicolas Paul <n@nc0.fr>
-rw-r--r--life2/game/cell.js39
-rw-r--r--life2/game/index.js24
2 files changed, 63 insertions, 0 deletions
diff --git a/life2/game/cell.js b/life2/game/cell.js
new file mode 100644
index 0000000..e232366
--- /dev/null
+++ b/life2/game/cell.js
@@ -0,0 +1,39 @@
+/**
+ * Copyright 2024 The Life2 Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * @license
+ */
+
+/**
+ * @fileoverview Implementation of a cell in the Life2 game.
+ * Cells are the smallest unit of the game, they carry information about their
+ * aliveness and their team, but everything else is computed by the board
+ * (interactions, changes, ...).
+ *
+ * @package life2
+ */
+
+/**
+ * An enumeration of the possible states of a cell.
+ * @enum {number}
+ * @const
+ */
+export const Cell = {
+ /** The cell is empty. */
+ EMPTY: 0,
+ /** The cell is filled with the color of the first team. */
+ TEAM_A: 1,
+ /** The cell is filled with the color of the second team. */
+ TEAM_B: 2,
+};
diff --git a/life2/game/index.js b/life2/game/index.js
new file mode 100644
index 0000000..f60d7ec
--- /dev/null
+++ b/life2/game/index.js
@@ -0,0 +1,24 @@
+/**
+ * Copyright 2024 The Life2 Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * @license
+ */
+
+/**
+ * @fileoverview The public API of the Life2 game package.
+ *
+ * @package life2
+ */
+
+export {Cell} from './cell';