diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ae5c301 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,20 @@ +## Description +[Provide a brief description of the changes made in this pull request.] + +## Motivation and Context +[Explain the motivation behind these changes and provide any relevant context.] + +## How to Test +[Describe the steps to test the changes made in this pull request.] + +## Related Issues +[If applicable, mention any related issues or pull requests.] + +## Checklist +- [ ] I have tested these changes locally. +- [ ] I have reviewed the code and ensured it follows the project's coding guidelines. +- [ ] I have updated the documentation, if necessary. +- [ ] I have assigned reviewers to this pull request. + +## Screenshots (if applicable) +[If your changes include any visual updates, provide screenshots here.] diff --git a/.github/issue_template.md b/.github/issue_template.md new file mode 100644 index 0000000..b0f2851 --- /dev/null +++ b/.github/issue_template.md @@ -0,0 +1,25 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environment (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b6faba..ab66ddf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,3 @@ - --- # Contributing to Multiplayer UNO Game @@ -21,6 +20,8 @@ Maintainers will approve the issue and add relevant labels to indicate that its ### Fixing Issues +Given that you have already forked the repository and set it up locally: + 1. **Find an Issue to Work On**: - Look for issues labeled `help wanted` or `good first issue` if you are a first-time contributor. @@ -29,22 +30,13 @@ Maintainers will approve the issue and add relevant labels to indicate that its If you are not able to make progress on an issue in 4 days, you will be unassigned from the issue and it will be available for others to work on. -3. **Fork the Repository**: - - Fork the repository to your own GitHub account by clicking the "Fork" button on the top right of the repository page. - -4. **Clone Your Fork**: - - Clone your fork to your local machine: - - ```bash - git clone https://github.com/yourusername/multiplayer-uno.git - cd multiplayer-uno - ``` - 5. **Create a Branch**: - Create a new branch for your fix from the `main` branch. Use a descriptive name for your branch: + It is crucial to fetch from upstream before creating a branch. This ensures that your branch is created from the latest changes in the main branch. ```bash - git checkout -b fix/issue-#123 + git fetch upstream + git checkout -b upstream/main ``` 6. **Implement Your Fix**: @@ -54,7 +46,7 @@ Maintainers will approve the issue and add relevant labels to indicate that its - Thoroughly test your changes to ensure they work as intended and do not introduce any new bugs. 8. **Commit Your Changes**: - - Please refer to the commit message guidelines in [CONVENTIONS.md](CONVENTIONS.md) for writing meaningful commit messages. + - Please refer to the commit message guidelines in [CONVENTIONS.md](CONVENTIONS.md#commit-message-guidelines) for writing meaningful commit messages. 9. **Push Your Changes**: - Push your branch to your forked repository: @@ -64,10 +56,10 @@ Maintainers will approve the issue and add relevant labels to indicate that its ``` 10. **Open a Pull Request**: - - Open a pull request (PR) against the `main` branch of the original repository. Provide a clear description of your changes and reference the issue number you are fixing. Fill the self review checklist. + - Open a pull request (PR) against the `main` branch of the original repository. Provide a clear description of your changes and reference the issue number you are fixing. Fill the self review checklist. You should only solve one issue in one PR. 11. **Address Review Comments**: - - If maintainers suggests changes to your code, make the necessary updates and push the changes to your branch. The fix/changes should not be in a separate commit - rather the original commit must be modified force-pushed to the branch. If merge conflicts arise, use `git rebase` to resolve them. + - If maintainers suggests changes to your code, make the necessary updates and push the changes to your branch. The fix/changes should not be in a separate commit - rather the original commit must be modified force-pushed to the branch. If merge conflicts arise, use `git rebase` to resolve them. See the section on [editing commit history](#editing-commit-history) for more details. @@ -78,6 +70,85 @@ Maintainers will approve the issue and add relevant labels to indicate that its - Addressing reviews on existing PRs is as important as creating new PRs. Please be responsive to the feedback and make the necessary updates. - Create a new branch for each issue you are working on. This will help you keep your changes isolated and make it easier to manage multiple PRs. The branch should be created from upstream/master, and only after fetching the latest changes from the main branch from upstream first. +## Common Git Operations you may need to perform + +During contribution, you will often need to rewrite commit history or sync your branch with the main branch. +Here is how you should do it: + +### Syncing your branch with the main branch +If there have been updates to the upstream/master branch after you created your branch, you should sync your branch with the main branch. This will help you avoid merge conflicts and keep your branch up-to-date. + +```bash +git fetch upstream +git rebase upstream/main +``` +Rebasing your branch on top of the main branch will apply your changes on top of the latest changes in the main branch. +It would be equivalent to merging the main branch into your branch, but it keeps the commit history clean. The commit history will reflect that your changes were made on top of the latest changes in the main branch. + +If any merge conflicts occur, you will need to resolve them manually. Code editors (like VSCode) have built-in tools to help you resolve merge conflicts. After resolving the conflicts, you can continue the rebase process by running `git rebase --continue`. + +Now the local copy of the branch is synced with upstream/main. You need to force push these changes to origin, since the commit history has been rewritten. + +```bash +git push --force +``` + +### Editing commit history +A maintainer might ask you to edit your commit history, for example, change the variable name, add/remove lines, change commit message, drop commits etc. The changes should not be made as a separate commit, rather you should edit the original commit with the changes. You can do this using an interactive rebase. + +Lets take the case where I want to merge 4 commits through a PR. The maintainer has asked me to change some variable names I had made through the 2nd commit. I am also asked to rename the commit message of the 3rd commit. + +```bash +git rebase -i HEAD~4 +``` + +The `-i` represents interactive mode, i.e, after each commit, git will pause and ask you what you want to do with the commit. `HEAD~4` means that I want to rebase the last 4 commits. + +After running the command, you will see a list of commits in your default text editor. It will look something like this: + +```bash + +pick 1a2b3c4d This is the commit message of Commit 1 +pick 5e6f7g8h Added variables in index.js. +pick 9i0j1k2l Updeted README.md +pick 3m4n5o6p Commit msg 4 + +``` +To drop a commit, you can simply delete the line corresponding to that commit. To edit a commit, you can replace `pick` with `edit` in front of the commit you want to edit. + +Since we wish to edit the 2nd and 3rd commit, we will change the file to look like this: + +```bash + +pick 1a2b3c4d This is the commit message of Commit 1 +edit 5e6f7g8h Added variables in index.js. +edit 9i0j1k2l Updeted README.md +pick 3m4n5o6p Commit msg 4 + +``` +Save the changes and exit. + +After saving the changes, git will then apply the 2nd commit and pause. You can now make the necessary changes to the code, and then stage the changes (Using `git add .`). You then incorporate the changes to the 2nd commit using `git commit --amend`. The editor opens, asking for commit meessage. You can change the commit message if needed at this needed. + + +#### "Uncommitting" a commit +When you choose to edit the 2nd commit, git pauses **after** applying the second commit. You might wish to uncommit all the changes made in the 2nd commit. In that case, you run `git reset HEAD~1`. This will uncommit the changes made in the 2nd commit, but keep the changes in the working directory. You can then make the necessary changes and commit them again. The `git reset` command can be used to uncommit any number of commits. For example, `git reset HEAD~2` will uncommit the last 2 commits. Note that after doing this operation, there would be no way to distinguish the changes made in the two commits. This command can be used outside of an interactive rebase as well. + +After making the changes, you can continue the rebase process by running `git rebase --continue`. Git will then apply the 3rd commit and pause again. You can then change the commit message using `git commit --amend`. After making the changes, you can continue the rebase process by running `git rebase --continue`. + +When there are no more commits left, the rebase process will be complete. + +After all the commits have been applied, you can push the changes to your branch using `git push --force`. This will overwrite the commits in the remote branch in your forked repository with the changes you just made locally. + +#### Tip +VSCode provides a helpful UI to perform these operations. You can set the default text editor for Git to VSCode by running the following command: + +```bash +git config --global core.editor "code --wait" +``` +This will open VSCode whenever you run a command that requires a text editor, like `git rebase -i HEAD~4`, `git commit --amend`, etc. + + ## Code Review All contributions go through a code review process to ensure the quality and maintainability of the codebase. During the review, maintainers may provide feedback or request changes to your code. Please be responsive to the feedback and make the necessary updates. There may be multiple rounds of review before your changes are approved. @@ -94,4 +165,6 @@ If you have any questions about the project or how to contribute, feel free to r Do not worry about the points scored during contributing. Feel free to make mistakes, but be open to acknowledge and fix them. The main goal is to learn and grow together. Depending on your enthusiasm, dedication and contribution, you will be judged in the end of CSOC. +The main purpose for this whole activity is to get you acquainted with the open source contribution workflow. We cannot replicate the exact workflow of a real open source project due to the time constraints, but we have tried to cover the most important aspects of it (related to git, code review, etc.). + --- diff --git a/CONVENTIONS.md b/CONVENTIONS.md index cbf80ff..10f6a1d 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -20,6 +20,7 @@ - Use meaningful commit messages that describe the changes made in the commit. - Please do only one thing in a single commit. If you are fixing a bug and refactoring some code, make two separate commits. - If you make tweaks to existing code to fit your implementation, do it in a separate commit. +- Your commits would be more readable if each line is limited to around 72 characters. Break long lines into multiple lines if necessary. - Commit messages should be of the format: ``` : @@ -33,14 +34,15 @@ server: Add endpoint to fetch user data. This commit adds a new endpoint to the server that allows clients to fetch user data. + We fetch the user data from MongoDB and return it as a JSON response, filtering out sensitive information. - Fixes #28686 + Fixes #28626 ``` ``` client: Refactor user profile component. - This commit refactors the user profile component to improve code readability and maintainability. + This commit refactors the user profile component to improve code readability and maintainability. ``` @@ -50,5 +52,6 @@ - Use proper spacing and line breaks to improve code readability. - Avoid unnecessary code duplication and strive for code reusability. - Write clear and concise documentation for public APIs and important functions. Do not over-document trivial functions. +- We decided not to use typescript in the backend to accomodate more contributors, but we do use JSDocs for documentation. Please document your code using JSDocs. Remember to review and adhere to these conventions to maintain a clean and consistent codebase. diff --git a/INSTALLATION.md b/INSTALLATION.md index 0b2d598..f394b52 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -75,14 +75,14 @@ cd multiplayer-uno 4. Start the frontend development server: ```bash - npm start + npm run dev ``` - The frontend application should now be running on `http://localhost:3000`. + The frontend application should now be running on `http://localhost:5173`. ## Running the Application -With both the backend and frontend servers running, open your browser and navigate to `http://localhost:3000` to access the UNO game. You should be able to sign up, log in, create or join game rooms, and start playing. +With both the backend and frontend servers running, open your browser and navigate to `http://localhost:5173` to access the UNO game. You should be able to sign up, log in, create or join game rooms, and start playing. ## Troubleshooting @@ -91,7 +91,7 @@ If you encounter any issues during installation, consider the following steps: - **Check Dependencies**: Ensure that all dependencies are installed correctly by running `npm install` in both the `backend` and `frontend` directories. - **Environment Variables**: Ensure that your `.env` file contains the correct values for your MongoDB connection string and JWT secret. - **Server Logs**: Check the terminal output for any error messages from the backend or frontend servers. -- **Port Conflicts**: Make sure that ports `5000` (backend) and `3000` (frontend) are not being used by other applications. +- **Port Conflicts**: Make sure that ports `5000` (backend) and `5173` (frontend) are not being used by other applications. ## Contact diff --git a/backend/.eslintignore b/backend/.eslintignore deleted file mode 100644 index b4b5654..0000000 --- a/backend/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -/node_modules/* -/dist/* -/tests/* \ No newline at end of file diff --git a/backend/.eslintrc.json b/backend/.eslintrc.json deleted file mode 100644 index 450fb69..0000000 --- a/backend/.eslintrc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "env": { - "browser": true, - "es2021": true, - "node": true - }, - "extends": ["eslint:recommended"], - "parserOptions": { - "ecmaFeatures": { - "jsx": true - }, - "ecmaVersion": 12, - "sourceType": "module" - }, - "rules": { - // Add your custom rules here - } -} diff --git a/backend/controllers/gameControllers.js b/backend/controllers/gameControllers.js index e5d0640..a4d73c4 100644 --- a/backend/controllers/gameControllers.js +++ b/backend/controllers/gameControllers.js @@ -1,2 +1 @@ // Implement the handler for `/events` endpoint. Refer to ARCHITECTURE.md for implementation details. - diff --git a/backend/eslint.config.js b/backend/eslint.config.js new file mode 100644 index 0000000..cdae4e7 --- /dev/null +++ b/backend/eslint.config.js @@ -0,0 +1,14 @@ +import jsdoc from 'eslint-plugin-jsdoc'; + +export default [ + { + files: ['**/*.js'], + plugins: { + jsdoc: jsdoc, + }, + rules: { + 'jsdoc/require-description': 'error', + 'jsdoc/check-values': 'error', + }, + }, +]; diff --git a/backend/gameStore.js b/backend/gameStore.js index 53251fb..62a1f8a 100644 --- a/backend/gameStore.js +++ b/backend/gameStore.js @@ -16,8 +16,14 @@ export function createGame() { } /** +<<<<<<< feat/game-store-create-retrieve * Retrieve a game from the games map * @param {string} id gameId +======= + * Retrieves a game from the store using its id. + * + * @param {string} id Game id +>>>>>>> master * @returns {GameEngine|null} GameEngine instance */ export function retrieveGame(id) { diff --git a/backend/package-lock.json b/backend/package-lock.json index dcc6f0f..939cbcf 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -16,6 +16,7 @@ }, "devDependencies": { "eslint": "^8.57.0", + "eslint-plugin-jsdoc": "^48.2.6", "jest": "^29.7.0", "prettier": "^3.2.5", "supertest": "^7.0.0" @@ -680,6 +681,24 @@ "dev": true, "license": "MIT" }, + "node_modules/@es-joy/jsdoccomment": { + "version": "0.43.0", + "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.43.0.tgz", + "integrity": "sha512-Q1CnsQrytI3TlCB1IVWXWeqUIPGVEKGaE7IbVdt13Nq/3i0JESAkQQERrfiQkmlpijl+++qyqPgaS31Bvc1jRQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/eslint": "^8.56.5", + "@types/estree": "^1.0.5", + "@typescript-eslint/types": "^7.2.0", + "comment-parser": "1.4.1", + "esquery": "^1.5.0", + "jsdoc-type-pratt-parser": "~4.0.0" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -1353,6 +1372,24 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/eslint": { + "version": "8.56.10", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.10.tgz", + "integrity": "sha512-Shavhk87gCtY2fhXDctcfS3e6FdxWkCx1iUZ9eEUbh7rTqlZT0/IzOkCOVt0fCjcFuZ9FPYfuezTBImfHCDBGQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "*", + "@types/json-schema": "*" + } + }, + "node_modules/@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/graceful-fs": { "version": "4.1.9", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.9.tgz", @@ -1390,6 +1427,13 @@ "@types/istanbul-lib-report": "*" } }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/node": { "version": "20.12.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.12.tgz", @@ -1437,6 +1481,20 @@ "dev": true, "license": "MIT" }, + "node_modules/@typescript-eslint/types": { + "version": "7.11.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.11.0.tgz", + "integrity": "sha512-MPEsDRZTyCiXkD4vd3zywDCifi7tatc4K37KqTprCvaXptP7Xlpdw0NR2hRJTetG5TxbWDB79Ys4kLmHliEo/w==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, "node_modules/@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", @@ -1548,6 +1606,16 @@ "node": ">= 8" } }, + "node_modules/are-docs-informative": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/are-docs-informative/-/are-docs-informative-0.0.2.tgz", + "integrity": "sha512-ixiS0nLNNG5jNQzgZJNoUpBKdo9yTYZMGJ+QgT2jmjR7G7+QHRCc4v6LQ3NgE7EBJq+o0ams3waJwkrlBom8Ig==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14" + } + }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -1985,6 +2053,16 @@ "node": ">= 0.8" } }, + "node_modules/comment-parser": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-1.4.1.tgz", + "integrity": "sha512-buhp5kePrmda3vhc5B9t7pUQXAb2Tnd0qgpkIhPhkHXxJpiPJ11H0ZEU0oBpJ2QztSbzG/ZxMj/CHsYJqRHmyg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 12.0.0" + } + }, "node_modules/component-emitter": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", @@ -2383,6 +2461,80 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint-plugin-jsdoc": { + "version": "48.2.6", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-48.2.6.tgz", + "integrity": "sha512-GNk9jtpYmoEVeD/U6yYYmd6T8vSOoPs7CL8ZeX85iD8P3qifDdLQGze6+cw9boobDthmYnnxvIoHrhuSffj09g==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@es-joy/jsdoccomment": "~0.43.0", + "are-docs-informative": "^0.0.2", + "comment-parser": "1.4.1", + "debug": "^4.3.4", + "escape-string-regexp": "^4.0.0", + "esquery": "^1.5.0", + "semver": "^7.6.1", + "spdx-expression-parse": "^4.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0" + } + }, + "node_modules/eslint-plugin-jsdoc/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/eslint-plugin-jsdoc/node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint-plugin-jsdoc/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true, + "license": "MIT" + }, + "node_modules/eslint-plugin-jsdoc/node_modules/semver": { + "version": "7.6.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", + "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/eslint-scope": { "version": "7.2.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", @@ -4071,6 +4223,16 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsdoc-type-pratt-parser": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsdoc-type-pratt-parser/-/jsdoc-type-pratt-parser-4.0.0.tgz", + "integrity": "sha512-YtOli5Cmzy3q4dP26GraSOeAhqecewG04hoO8DY56CH4KJ9Fvv5qKWUCCo3HZob7esJQHCv6/+bnTy72xZZaVQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", @@ -5253,6 +5415,31 @@ "memory-pager": "^1.0.2" } }, + "node_modules/spdx-exceptions": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.5.0.tgz", + "integrity": "sha512-PiU42r+xO4UbUS1buo3LPJkjlO7430Xn5SVAhdpzzsPHsjbYVflnnFdATgabnLude+Cqu25p6N+g2lw/PFsa4w==", + "dev": true, + "license": "CC-BY-3.0" + }, + "node_modules/spdx-expression-parse": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-4.0.0.tgz", + "integrity": "sha512-Clya5JIij/7C6bRR22+tnGXbc4VKlibKSVj2iHvVeX5iMW7s1SIQlqu699JkODJJIhh/pUu8L0/VLh8xflD+LQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "node_modules/spdx-license-ids": { + "version": "3.0.18", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.18.tgz", + "integrity": "sha512-xxRs31BqRYHwiMzudOrpSiHtZ8i/GeionCBDSilhYRj+9gIcI8wCZTlXZKu9vZIVqViP3dcp9qE5G6AlIaD+TQ==", + "dev": true, + "license": "CC0-1.0" + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", diff --git a/backend/package.json b/backend/package.json index 849790f..0bf3581 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,4 +1,5 @@ { +<<<<<<< feat/game-store-create-retrieve "name": "backend", "version": "1.0.0", "main": "index.js", @@ -27,4 +28,34 @@ "prettier": "^3.2.5", "supertest": "^7.0.0" } +======= + "name": "backend", + "version": "1.0.0", + "main": "index.js", + "type": "module", + "scripts": { + "lint": "eslint . --report-unused-disable-directives --max-warnings 0", + "format": "prettier --check .", + "fix-format": "prettier --write .", + "test": "jest", + "start": "node src/index.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^16.4.5", + "express": "^4.19.2", + "mongoose": "^8.4.0" + }, + "devDependencies": { + "eslint": "^8.57.0", + "eslint-plugin-jsdoc": "^48.2.6", + "jest": "^29.7.0", + "prettier": "^3.2.5", + "supertest": "^7.0.0" + } +>>>>>>> master } diff --git a/backend/src/index.js b/backend/src/index.js index aeeb865..0aba0ce 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -13,9 +13,9 @@ app.use(cors()); app.use(json()); connect(process.env.MONGO_URI, { - useNewUrlParser: true, - useUnifiedTopology: true, - }) + useNewUrlParser: true, + useUnifiedTopology: true, +}) .then(() => console.log('MongoDB connected')) .catch((err) => console.error('Could not connect to MongoDB', err)); diff --git a/backend/uno-game-engine/deck.js b/backend/uno-game-engine/deck.js index e094a7d..4d59052 100644 --- a/backend/uno-game-engine/deck.js +++ b/backend/uno-game-engine/deck.js @@ -47,8 +47,8 @@ export default function getShuffledCardDeck() { // deck.push(makeCard('special', 'wild', 'wild')) // deck.push(makeCard('number', 'red', '0')) - shuffle(deck) - return deck + shuffle(deck); + return deck; } /** @@ -66,9 +66,9 @@ function makeCard(type, color, value) { /** * This function shuffles the elements of the given array *in place* . The function behaves in a type-agnostic way. * Time complexity: O(n) - * @param {Array} deck + * @param {Array} deck */ function shuffle(deck) { //todo: Implement a generic shuffling algorithm [deck[0], deck[1]] = [deck[1], deck[0]]; -} \ No newline at end of file +} diff --git a/backend/uno-game-engine/engine.js b/backend/uno-game-engine/engine.js index cb312cd..56a5564 100644 --- a/backend/uno-game-engine/engine.js +++ b/backend/uno-game-engine/engine.js @@ -1,39 +1,41 @@ -import getShuffledCardDeck from "./deck"; +import getShuffledCardDeck from './deck'; const NUM_CARDS_PER_PLAYER = 7; -export class GameEngine{ - constructor(){ +export class GameEngine { + constructor() { this.cardDeck = getShuffledCardDeck(); this.thrownCards = []; - this.players= []; + this.players = []; this.currentPlayerIndex = 0; this.lastThrownCard = null; this.currentColor = 0; this.direction = 1; - this.status = "READY" - + this.status = 'READY'; } - allotCards(){ + allotCards() { //todo: Implement the card allotment logic: Remove `NUM_CARDS_PER_PLAYER` cards from the deck // and add them to the player's hand - Do this for each player // example: this.players[0].cards = this.cardDeck.splice(0, NUM_CARDS_PER_PLAYER); } - addPlayer(player){ + addPlayer(player) { this.players.push(player); } - startGame(){ - if(this.players.length < 2){ - throw new Error("Not enough players to start the game") + startGame() { + if (this.players.length < 2) { + throw new Error('Not enough players to start the game'); } - this.status = "STARTED" + this.status = 'STARTED'; } - nextPlayer(){ - this.currentPlayerIndex = (this.currentPlayerIndex + this.direction) % this.players.length; + nextPlayer() { + this.currentPlayerIndex = + (this.currentPlayerIndex + this.direction) % this.players.length; } drawCardFromDeck(player) { //todo: Handle the case when the deck is empty and we have to move the thrown cards back to the deck - this.players.find(p => p.id === player.id).cards.push(this.cardDeck.pop()); + this.players + .find((p) => p.id === player.id) + .cards.push(this.cardDeck.pop()); } -} \ No newline at end of file +} diff --git a/docs/pull_request_template.md b/docs/pull_request_template.md deleted file mode 100644 index 86007e1..0000000 --- a/docs/pull_request_template.md +++ /dev/null @@ -1,32 +0,0 @@ - - - -Fixes # - -
-Screenshots and screen captures -
- - -
-Self-review checklist - - - - - -- [ ] Self reviewed the changes for clarity and maintainability (variable names, code reuse, readability, etc.). -- [ ] Highlights technical choices and bugs encountered. -- [ ] Calls out remaining decisions and concerns. -- [ ] Automated tests verify logic where appropriate. -- [ ] Each commit is a coherent idea. -- [ ] Commit message(s) explain reasoning and motivation for changes. - -Completed manual review and testing of the following: - -- [ ] Visual appearance of the changes. -- [ ] End-to-end functionality of buttons, interactions and flows. -- [ ] Corner cases, error conditions, and easily imagined bugs. -