diff --git a/.all-contributorsrc b/.all-contributorsrc
new file mode 100644
index 00000000..0a5faad0
--- /dev/null
+++ b/.all-contributorsrc
@@ -0,0 +1,115 @@
+{
+ "projectName": "JavaScript-Snake",
+ "projectOwner": "patorjk",
+ "files": ["README.md"],
+ "commitType": "docs",
+ "commitConvention": "angular",
+ "contributorsPerLine": 7,
+ "contributors": [
+ {
+ "login": "patorjk",
+ "name": "patorjk",
+ "avatar_url": "https://avatars.githubusercontent.com/u/521224?v=4",
+ "profile": "http://patorjk.com/",
+ "contributions": ["code", "doc", "design", "bug", "example"]
+ },
+ {
+ "login": "ultra17",
+ "name": "ultra17",
+ "avatar_url": "https://avatars.githubusercontent.com/u/27869698?v=4",
+ "profile": "https://github.com/ultra17",
+ "contributions": ["code", "doc", "design", "bug"]
+ },
+ {
+ "login": "Rb64",
+ "name": "Rb64",
+ "avatar_url": "https://avatars.githubusercontent.com/u/91498309?v=4",
+ "profile": "https://github.com/Rb64",
+ "contributions": ["code", "bug"]
+ },
+ {
+ "login": "legoman8304",
+ "name": "Wyatt Nulton",
+ "avatar_url": "https://avatars.githubusercontent.com/u/43346988?v=4",
+ "profile": "https://github.com/legoman8304",
+ "contributions": ["code", "bug"]
+ },
+ {
+ "login": "ashishsiot",
+ "name": "Ashish Bhoir",
+ "avatar_url": "https://avatars.githubusercontent.com/u/63919950?v=4",
+ "profile": "https://github.com/ashishsiot",
+ "contributions": ["doc"]
+ },
+ {
+ "login": "dginovker",
+ "name": "Dan G",
+ "avatar_url": "https://avatars.githubusercontent.com/u/32943174?v=4",
+ "profile": "http://dginovker.github.io",
+ "contributions": ["code", "bug"]
+ },
+ {
+ "login": "Megas4ever",
+ "name": "Megas4ever",
+ "avatar_url": "https://avatars.githubusercontent.com/u/28103886?v=4",
+ "profile": "https://github.com/Megas4ever",
+ "contributions": ["code", "design"]
+ },
+ {
+ "login": "mamamia5x",
+ "name": "Bugs Bunny",
+ "avatar_url": "https://avatars.githubusercontent.com/u/57536929?v=4",
+ "profile": "https://github.com/mamamia5x",
+ "contributions": ["code", "bug"]
+ },
+ {
+ "login": "Coteh",
+ "name": "James Cote",
+ "avatar_url": "https://avatars.githubusercontent.com/u/3276350?v=4",
+ "profile": "https://www.jamescote.ca",
+ "contributions": ["code", "bug", "doc"]
+ },
+ {
+ "login": "yokesharun",
+ "name": "Arun Yokesh",
+ "avatar_url": "https://avatars.githubusercontent.com/u/12830078?v=4",
+ "profile": "http://yokesharun.github.io/",
+ "contributions": ["code", "design"]
+ },
+ {
+ "login": "GregFrench",
+ "name": "Greg French",
+ "avatar_url": "https://avatars.githubusercontent.com/u/17938510?v=4",
+ "profile": "https://github.com/GregFrench",
+ "contributions": ["code"]
+ },
+ {
+ "login": "KT360",
+ "name": "KT360",
+ "avatar_url": "https://avatars.githubusercontent.com/u/31077743?v=4",
+ "profile": "https://github.com/KT360",
+ "contributions": ["code", "design"]
+ },
+ {
+ "login": "Thusal06",
+ "name": "Thusal Ranawaka",
+ "avatar_url": "https://avatars.githubusercontent.com/u/66709891?v=4",
+ "profile": "https://thusal06.github.io/",
+ "contributions": ["code", "design"]
+ },
+ {
+ "login": "Furtano",
+ "name": "C. S.",
+ "avatar_url": "https://avatars.githubusercontent.com/u/4115133?v=4",
+ "profile": "https://github.com/Furtano",
+ "contributions": ["code", "design"]
+ },
+ {
+ "login": "akhill2606",
+ "name": "Akhil Manohar",
+ "avatar_url": "https://avatars.githubusercontent.com/u/56164681?v=4",
+ "profile": "https://github.com/akhill2606",
+ "contributions": ["code"]
+ }
+ ]
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..f78ec928
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.parcel-cache
diff --git a/.parcelrc b/.parcelrc
new file mode 100644
index 00000000..1f3df894
--- /dev/null
+++ b/.parcelrc
@@ -0,0 +1,4 @@
+{
+ "extends": ["@parcel/config-default"],
+ "reporters": ["...", "parcel-reporter-static-files-copy"]
+}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..7cf19bc5
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,7 @@
+Copyright © Patrick Gillespie, http://patorjk.com
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/README.md b/README.md
index f2181309..0956f864 100755
--- a/README.md
+++ b/README.md
@@ -1,19 +1,121 @@
-JavaScript Snake
-By Patrick Gillespie
-License: MIT
+# JavaScript Snake Game
+
+This is a DOM-based game of Snake that I wrote in JavaScript over a decade ago. It was made to have sort of a nostalgic feel to it.
+
+## Play and Edit the Game Online!
+
+You can now play and edit the game live in codesandbox:
+
+https://codesandbox.io/s/github/patorjk/JavaScript-Snake?file=/index.html
+
+**2025: Looks like CSS inside the sandbox isn't working properly, in the game it works fine though**
+
+On first load sometimes the game frame will not load correctly and you'll need to press the refresh icon above its display panel to get the game to show.
+
+Original game is located here:
+
http://patorjk.com/games/snake
-This is a DOM-based game of Snake that I wrote in JavaScript a few years back.
+## How to use
-Other than the full screen mode demonstrated in the code, it can also be
-initialized in div tags within a page. Example:
+The index.html file should give an idea of how to use this code. However, below you can see how to initialize it into any div within a webpage.
- var mySnakeBoard = new SNAKE.Board( {
+ const mySnakeBoard = new SNAKE.Board( {
boardContainer: "game-area",
fullScreen: false,
width: 580,
height:400
});
-
-The comments are formatted a little strange because at the time I was playing
-around with YUI Doc.
+
+The comments within the source code are formatted a little strange because at the time I was playing around with YUI Doc which generates documentation from code. Kind of sucks that there's so much churn in the JavaScript world. However, I'm glad the rest of the code doesn't use any external libraries, as this game still works the same after over a decade.
+
+## Running
+
+Clone project, then at command line:
+
+```
+npx parcel src/index.html
+```
+
+Runs on http://localhost:1234
+
+## AI Snake
+
+If you want to control the snake via an AI algorithm see the ai-init.js and ai-example files.
+
+Essentially all you have to do is run `params.startAIGame();` when initializing and pass in a `moveSnakeWithAI` method
+which is run before the snake does each move.
+
+```js
+ moveSnakeWithAI: ({
+ grid,
+ snakeHead,
+ currentDirection,
+ isFirstGameMove,
+ setDirection,
+ }) => {
+
+ /*
+ Direction:
+ 0
+ 3 1
+ 2
+ */
+
+ // This is NOT a real hamiltonian cycle. It misses some values, I'm just including this here as an example of
+ // a look-up type table that you could do.
+ const hamiltonianCycleGrid = [
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0],
+ [0, 0, 2, 3, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 0],
+ [0, 0, 2, 0, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0],
+ [0, 0, 2, 0, 2, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0],
+ [0, 0, 3, 0, 3, 3, 3, 3, 0, 3, 0, 3, 0, 3, 0],
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ ];
+
+ const newDirection = hamiltonianCycleGrid[snakeHead.row][snakeHead.col];
+ setDirection(newDirection);
+ },
+ onInit: (params) => {
+ params.startAIGame(); // This start an AI game
+ },
+```
+
+## Contributors
+
+Thanks goes to these people: ([emoji key](https://allcontributors.org/docs/en/emoji-key))
+
+
+
+
+
patorjk 💻 📖 🎨 🐛 💡 |
+ ultra17 💻 📖 🎨 🐛 |
+ Rb64 💻 🐛 |
+ Wyatt Nulton 💻 🐛 |
+ Ashish Bhoir 📖 |
+ Dan G 💻 🐛 |
+ Megas4ever 💻 🎨 |
+
Bugs Bunny 💻 🐛 |
+ James Cote 💻 🐛 📖 |
+ Arun Yokesh 💻 🎨 |
+ Greg French 💻 |
+ KT360 💻 🎨 |
+ Thusal Ranawaka 💻 🎨 |
+ C. S. 💻 🎨 |
+
Akhil Manohar 💻 |
+