genius_deck/README.md

1.7 KiB

Genius Deck

Specification

A simple web API that manages an in-memory deck of cards.

On starting the API, or after sorting, the default sort order from top to bottom is:

Suits: Spades > Hearts > Clubs > Diamonds
Face Values: 2 > 10 > Jack > Queen > King > Ace

Two of Spades is on top, Ace of Diamonds is at the bottom.

Source code location where the routes are defined: here

Permitted operations are as follows:

GET /deal

Takes the top card off the deck and returns it as json

GET /cheat

Peaks at the top card of the deck and returns it as json

POST /discard

Discards a card previously dealt Expects data in json in the form

{
  "face_value": "Seven",
  "suite": "Spades"
}

POST /cut

Cuts the deck at the index provided, either as query params (/cut?index=10) or json

{
  "index": 10
}

POST /rebuild

Puts the discard pile back into the deck and sorts the resulting deck

POST /sort

Orders the deck in the default sort order (see Specification)

POST /shuffle

Shuffles the current deck of cards in random order

Running

You can navigate to the releases to download a prebuilt binary for your platform, or you can run it locally yourself with Zig.

You will need to download Zig 0.13.0 from Zig's releases page, or from your package manager. If you use Nix flakes, a working config with direnv is already present in the repository.

Deck Method Tests

The tests can be run with Zig by running the following command in the root of the project:

zig test src/deck.zig