GithubHelp home page GithubHelp logo

minesweeper-backend's Introduction

Minesweeper API

Lives at https://minesweeperbackend.herokuapp.com/

First steps

  • Make sure you have ruby installed (I used 2.7.1)
  • Also make sure you have postgresql installed and running
  • You'll need to create the database (bundle exec rails db:create db:migrate)
  • To start the server run bundle exec rails s

API DOCS

Lives at https://minesweeperbackend.herokuapp.com/api-docs

Model definition

  1. User

    • UUID: uuid (unique)
    • Name: string
  2. Game

    • Start time: datetime
    • End time: datetime
    • Mines amount: integer
    • Rows size: integer
    • Columns size: integer
    • Cells: array of integers
    • Opened cells: array of integers
    • Flagged cells: array of integers
    • Status: [active, lost, won]

Cells stores the board with all the data (mines, indicators and empty spaces). Cells is a one-dimensional array containing the board.

Game#current_cells discloses the board with the opened and flagged cells.

Routes

  • Users with create, update and show.
  • Games with create, update and show. The update action will handle opening and flagging cells.

Services

Board service

  • Handles the board creation, which is actually an one-dimensional array.
  • Randomize the mines creation.
  • Raises errors if amount of mines is greater than amount of cells, and also if the amount of mines is zero.

Game service

  • Handles the update of the game object (I was intending not to touch the database in the service layer, but for simplicity I ended up using active record in here).
  • When the user decides to open a cell, this service will run the flood-fill algorithm (recursively) in the cells array, trying to open all the adjacent cells available.

"Session" management

  • Each user is provided with an UUID.
  • Every request should have the header X-Minesweeper-User-Uuid so that the controller can set the current user.
  • It will raise an error if the current user is not found, except for the create user endpoint.

Miscellaneous

  • Added active model serializer
  • Added rack-cors (anything is whitelisted though)

minesweeper-backend's People

Contributors

lautarob avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.