/gosuji

Rails app for playing the strategy game Go in realtime against fellow humans

Primary LanguageJavaScript

GoSuji - Rails app for playing Go

Check out the live app!

Go is a timeless board game originating in China more than two millenia ago. It has relatively simple rules, and yet the strategy is very deep and rich. It is one of the few classic board games where the best humans still have an edge against computers. Read more about Go on wikipedia.

GoSuji is a straightforward implemenation of the game. It has real-time moves, automatically saved game progress, a nifty behind-the-scenes board analyzer that makes scoring the game very simple, and in-game chat. Users can find their active and finished games on the profile page. Open games to join can be found on the home page of the site, which also has the link for creating new games.

The Stack

GoSuji was built using modern web development tools:

  • Ruby on Rails
    • The large majority of all application logic. Everything except for websockets is handled by Rails
    • POROs are utilized to process moves and scoring actions (/lib directory). This helps maintain separation of concerns and keeps the models skinnier.
  • Node.js & websockets
    • A separate Node.js app is used to handle the realtime aspects of the site
    • Receives data from Rails (via Redis) and sends this data to the necessary clients via websockets
    • Uses the SockJS websocket library, and a wrapper I created that adds socket.io style named events and rooms on top of SockJS.
  • Redis
    • Provides pub-sub messaging layer that allows Rails to send data to the Node.js app
    • Serves as a quick access data-store that holds temporary data during the game scoring phase
  • Many of the other usual suspects
    • jQuery, vanilla javascript, CSS, HTML
    • Rspec, Capybara + Poltergeist for testing

Coming soon...

The basic set of features is fully implemented and working beautifully (see first section for a brief description). However, I have many exciting ideas to make GoSuji even more awesome. In the works:

  • User-created custom rooms where people can hang out, chat, and create games to play against others
  • Timed games, with a wide range of settings (from blitz to leisurely turn based games)
  • Game review, where one can navigate the moves of a finished game and try alternate sequences
  • Exporting of games to SGF (smart game format)
  • Self-balancing ranking system that aligns with the widely used kyu and dan ranks
  • API for allowing user-created bots to play on the site
  • Custom board shapes! This is the feature I am most excited about. There are a lot of possibilities with this idea. I will probably start with some simpler pre-set custom shapes, and then later build an interface that lets users create and share their own custom boards

Setting up and running GoSuji locally

  1. Install the dependencies (older versions may work for some of these)

  2. Ruby 1.9.3 or higher

  3. Rails 4.0.0 or higher

  4. Node.js 0.10.0 or higher

  5. npm 1.2.0 or higher

  6. Redis 2.4 or higher

  7. PostgreSQL or SQLite

  8. Setup the Rails app

  9. Clone the repository: git clone https://github.com/dwaltrip/gosuji.git

  10. Install gems: bundle install

  11. Setup environment variables. The figaro gem is used to manage these. 1. Change the name of config/application-(example).yml to config/application.yml. 1. If you aren't using the default port for Redis or if you modify the port used by the Node.js app, you will need to edit the development: section of application.yml to reflect this.

  12. Change the name of config/database-(example).yml to config/database.yml. To use PostgreSQL instead of SQLite, see this Railscast.

  13. Run the database migrations: bundle exec rake db:migrate.

  14. Setup the Node app

  15. Clone the repository: git clone https://github.com/dwaltrip/gosuji-node-server.git

  16. Install packages: npm install

  17. Change the name of development-config-(example).js to development-config.js. Edit this file if you are not using the default port for redis.

  18. Run the tests and verify that they pass (Optional)

  19. The gameplay integration tests use Poltergiest, which depends on PhantomJS. Follow these instructions to install it. Alternatively, you can skip the integrations tests.

  20. Migrate the test database: bundle exec rake db:migrate RAILS_ENV=test

  21. If including the integration tests, start up Node and Redis (see section 5)

  22. Run the tests: bundle exec rspec. To skip the integration tests, add this option to the rspec command: --tag ~integration.

  23. Run GoSuji!

  24. Start the Redis server: redis-server (my dev machine starts a background Redis process on start up, so I skip this step)

  25. Start the Rails server: rails server

  26. Start the Node.js server: node server.js

  27. Open your browser and visit localhost:3000. Go is a two player game, so you will have to open a second browser to play against yourself :)