Skip to content

ashikka/golf-it

Repository files navigation

Issues


Logo

Golf it!

Golf it! is a game designed to let you show off your code-fu by solving problems
in the least number of characters
Explore the docs »

View Demo · Report Bug · Request Feature

🎯 Table of Contents

📖 About The Project

One of our teammates loves to solve codegolf questions. We thought it would be a good idea to implement this as a one on one competition, where two players can compete live to write the shortest snippet of code to solve a question.

Code Golf refers to attempting to solve a problem using the least amount of characters possible i.e. to have the smallest source code. The term is derived from the sport golf where the player’s goal is to hit their ball in the hole using the least number of shots possible. In Code Golf the developer that solves the problem (usually writing a function) using the fewest number characters possible wins.

⚙️ How we built it

The backend was built using NodeJS and Typescript. We used expressJS to implement all the routes required for submitting code. The backend uses an npm library called code-executor which was built in the past by one of our teammates, to execute code against test cases in isolated Docker containers. To implement real-time communication when a head-to-head game started, we used socket.io to connect both the players in the same room. We used firestore as a database.

The frontend was built using React and Bootstrap. We used socket.io-client to interact with the socket server, and axios to interact with the express backend. To display the code editor on the website with multiple themes and syntax support for languages, we used a library called react-ace.

🚀 What's next for Golf-it!

We have many features planned for golf-it in the future:

  • Global leaderboards across the website, for players who regularly win more and more head-to-head games to showcase their skills.
  • User accounts (registering and logging in)
  • The ability for users to submit their own questions, and people to vote for questions they found interesting.
  • Picking avatars for your own profile
  • Having live competitions with even more people, instead of just head-to-head ones.

Built With

Backend Frontend
Typescript Javascript
express axios
firebase React
code-executor react-redux
socket.io socket.io-client
joi react-router-dom
redis react-ace

✈️ Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • yarn
npm install -g yarn

Installation

  1. Clone the repo
git clone https://github.com/ashikka/golf-it.git
  1. Install yarn packages
yarn
  1. Add necessary environment variables to the project using:
{
        echo 'API_KEY='
        echo 'AUTH_DOMAIN='
        echo 'PROJECT_ID='
        echo 'STORAGE_BUCKET='
        echo 'MESSAGING_SENDER_ID='
        echo 'APP_ID='

} >> .env

🔧 Usage

Start the project locally by following these steps.

  1. Run a Redis broker on your system
docker run -p6379:6379 redis
  1. Start the worker which is going to interact with the library code-executor.
cd backend

ts-node worker.ts
  1. Start the backend using:
yarn run dev
  1. Start the frontend using:
cd frontend

yarn start

🚩 Routes

The backend of the project supports the following routes:

1. Code submission

POST /code/submission/:questionName
Parameter Type Description
params string questionName
body string language
body string code
body Date submitTime

2. Create new room

POST /room/create
Parameter Type Description
body string clientId
body number payload

3. Get room

GET /room/:roomId
Parameter Type Description
params string roomId

🗺️ Roadmap

See the open issues for a list of proposed features (and known issues).

🦾 Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'feat: Add some AmazingFeature')
  4. Push to the Branch (git push -u origin feature/AmazingFeature)
  5. Open a Pull Request

You are requested to follow the contribution guidelines specified in CONTRIBUTING.md while contributing to the project 😄.

📄 License

Distributed under the MIT License. See LICENSE for more information.

About

A game designed to let you show off your code-fu by solving problems in the least number of characters ✨

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published