Code Monkey home page Code Monkey logo

dice10k's Introduction

dice10k

dice, dice, baby

A simple server-side take on the game-logic of dice 10000. These are the rules I use. Fork it and change 'em if you'd like.

Start the Server

Real easy: clone and lein run (default port is 3000) If you want your friends to join in, something like ngrok will work. Or if you want to be fancy about it build an uberjar, and a docker image and host it somewhere.

Start a game

Example bash functions for some game config/playing exist in the /resources directory, but here you go:

Request

curl \
-X POST -H "Content-Type: application/json" \
-d '{"friendly-name": "YOUR NEW GAME"}'\
$DICE_HOST/games

Names are optional; a generated one will be passed to you if you don't provide one. $DICE_HOST would be localhost:3000 or whatever you have tunnelling to your server.

Response

This will return you some JSON:

{
  "game-id": "04d209d5-3b9c-4d22-8559-5a8de14f13ad",
  "players": {},
  "friendly-name": "YOUR NEW GAME",
  "turn": 0,
  "pending-points": 0,
  "pending-dice": 0
}

Adding some players

You need some players to start a game, but players can join an ongoing game as well:

Request

curl \
-X POST -H "Content-Type: application/json" \
-d '{"name": "some name"}' \
$DICE_HOST/games/$GAME_ID/players

Response

{
  "message": "You've been added, some name. Use your player-id for rolling/passing.",
  "player-id": "2b9de4bc-a0e1-49b1-b35c-f625050ee548"
}

The player-id provided in the response is your 'secret token' that allows you to roll/keep/pass, so anyone with this token can play for you. It won't be provided in basic game responses/fetches to other players.

Playing

Start

When you're ready, you must initiate the game with a PUT to /games/$GAME_ID/start.

State

You can check who's turn it is and get other game-state info at any point with a GET from /games/$GAME_ID.

Actions

The actions available for the turn-player (POST /games/$GAME_ID/players/$PLAYER_ID/:action-name):

  • roll - rolls all 6 dice unless steal parameter is passed in json post data, or you've already rolled
  • keep - pick dice to score with and either keep rolling or pass under keepers param in json post body
  • pass - freezes your current score and passes remaining dice to the next player

TODOs

  • The turn ordering is probably messed up, players used to be a vector, and are now a map
  • There is no end-game handling... you just sorta have to stop when someone wins
  • Some of the state stuff is janky and not totally good.
  • Rulesets could be variablized and stored somewhere like domain (num-dice, values of straights/3 of a kind, stealing protocol...)
  • keep.sh resource example needs to take a vector of keepers as third input
  • Doesn't use a real logger, very simple thread with blocking queue implementation.
  • Stats would be cool: Bust count (Anthony Bennett award?) avg scoring hand, steals vs. steal-attempts...
  • Add a route for removing players from games

License

Copyright © 2020 EPL... The game is in no way mine and the code isn't great.

dice10k's People

Contributors

kaliayev avatar

Watchers

James Cloos 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.