Skip to content

cmgchess/facemash-v2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FaceMash V2

Simple, Reusable, Prototypical solution inspired by FaceMash ( As seen in The Social Network (2010) ) that allows users to rate two Pokemons against each other. The game uses Glicko 2 rating system to calculate the relative strength?/popularity? whatever of each Pokemon, and features a leaderboard that is automatically updated at GMT midnight.

Inspiration

FaceMash

Data

The dataset is collected from fanzeyi/pokemon.json

Seed Data for MongoDB

You need 2 MongoDB collections for the application. One for saving Pokemon data and the other for saving Match/Pairing data. Initial seed data for MongoDB can be found here. Initial rating,deviation and sigma are set to 1500, 350 and 0.06 respectively. The initial rank values are set to the same value as the currRank field, and prevRank is also initialized to the same value. Below is an example of what the seed data for a Pokemon in the database would look like:

{
  "id": "1",
  "name": "Bulbasaur",
  "img": "https://raw.githubusercontent.com/fanzeyi/pokemon.json/master/images/001.png",
  "currRank": 1,
  "prevRank": 1,
  "rating": 1500,
  "deviation": 350,
  "sigma": 0.06
}

Seed Data for Algolia

You will have to create an Algolia index for this. You can do that for free. Initial seed data for Algolia can be found here. Below is an example of what the seed data for a Pokemon in Algolia would look like:

{
  "objectID": "1",
  "name": "Bulbasaur",
  "img": "https://raw.githubusercontent.com/fanzeyi/pokemon.json/master/images/001.png",
  "currRank": 1,
  "prevRank": 1,
  "rating": 1500
}

Note that the id field in the database seed data corresponds to the objectID field in the Algolia seed data, and that the deviation and sigma fields are only included in the database seed data. Also make sure to configure the name as a Searchable attribute and to configure the ranking to sort by increasing currRank in Algolia.

Deploying your own

Backend

The backend for this game is a Serverless API that is hosted on Vercel. To deploy the backend, follow these steps:

  1. Fork the repository to your GitHub account.
  2. Open the Vercel dashboard and "Import Project".
  3. Select the serverless directory as the source directory.
  4. Set the Environment Variables according to the given .env.example.

Frontend

The frontend for this game can also be hosted on Vercel. To deploy the frontend, follow these steps:

  1. Fork the repository to your GitHub account.
  2. Open the Vercel dashboard and "Import Project".
  3. Select the frontend directory as the source directory.
  4. Set the Environment Variables according to the given .env.example.

Sync server

The sync server for this game can be hosted on Render or any other platform of your choice. The sync server contains 2 endpoints which can be used to automatically update the ratings in the database and Algolia search index, as well as delete any unfinished matches from the database. To deploy the sync server using Render, follow these steps:

  1. Fork the repository to your GitHub account.
  2. Create a new Render project and connect it to your GitHub repository.
  3. Select the sync directory as the source directory.
  4. Set the Environment Variables according to the given .env.example.

Setting up Cron Jobs

To automatically call the endpoints of the sync server, you can use a third-party service like cron-job.org.
The 2 endpoints will be https://deployedUrl/sync/rating and https://deployedUrl/sync/delete. Set the desired interval for the cron job. By default, the sync server is set to update the ratings every day at midnight GMT. If you need to change the duration, make sure to update the time difference in the sync.js file in the sync/controllers directory of the repository.

Contributing

This project is open-source and contributions are welcome. If you have any suggestions or would like to contribute to the project, please feel free to submit a pull request or open an issue.

License

FaceMash is an open-source project released under the MIT License.