DEV Community

Cover image for Everyday is an API day with BlackJack
kevinmaru2020
kevinmaru2020

Posted on

Everyday is an API day with BlackJack

Although they say 'What Happens in Vegas, Stays in Vegas.', but there is one thing that you definitely want to get back home to re-live your memories and that would be the Casino games. Even though you might not be able to Visit Vegas at this point in time due to the present Pandemic situation, we have got you covered. We present to you the online version of Black Jack that you can enjoy playing in your leisure time.

Alt Text

This project has been implemented using React JS & MuleSoft. The APIs used in the project have been created using MuleSoft & deployed on CloudHub. CloudHub is an integration platform as a service (iPaaS) where you can deploy sophisticated cross-cloud integration applications in the cloud, create new APIs on top of existing data sources, integrate on-premises applications with cloud services, and much more.

This project also makes use of Object Store, to store the player's data. Object Store lets CloudHub applications store data and states across batch processes, Mule components, and applications, from within an application or by using the Object Store REST API.

MuleSoft APIs description:

  • /initialize -
    This is the first API to be invoked when the player enters the name. The client sends this name as a query parameter named 'uid'. This query param is mandatory in all other APIs as well. MuleSoft creates an object in Object Store & sets initial coins which is configurable through the config.properties.

  • /bet -
    At the start of each turn, the player needs to bet a certain amount that is less than or equal to its coin balance. This value is sent from Client to MuleSoft through 'betAmount' query parameter. This API generates 2 cards for the dealer (One of them hidden) as well as the player and returns it to the source. At the same time, card data along with updated balance is set in object-store.

  • /hit -
    Whenever the player hits, this API is invoked which draws a new card from the deck. It re-calculates the player's hand & returns it to the caller along with the state of the game (Win/Continue/Bust) & the updated coin balance. Based on the state returned, the client allows the user to continue playing or declare win or bust.

  • /stand -
    When the player fears getting busted and doesn't want to draw any new card, the dealer's hidden card is revealed and his hand value is calculated. Until the dealer's hand value crosses 17, a new card is pulled out of the deck. Based on Player's and Dealer's Hand value, the winner is declared.

  • /delete -
    This resets the game by deleting the player's data from Object Store.

Alt Text

How to play -

Rules:

  • The goal of blackjack is to beat the dealer's hand without going over 21.
  • Face cards are worth 10. Aces are worth 1 or 11, whichever makes a better hand.
  • Player and Dealer starts with two cards, one of the dealer's cards is hidden until the player stands
  • To 'Hit' is to ask for another card. To 'Stand' is to hold your total and end your turn.
  • If you go over 21 you bust, and the dealer wins regardless of the dealer's hand.
  • If you are dealt 21 from the start (Ace and 10), you got a blackjack.
  • You win when your hand totals higher than the dealer's hand or the dealer busts.

Configuration:

As this application is hosted on github.io which is HTTPS and it invokes the MuleSoft application hosted on CloudHub, you might see the mixed content error. To fix this please follow the below steps -

Step 1. Click on the lock icon near the URL and then click on the site settings.

Alt Text

Step 2. Select Allow from the dropdown for Insecure content.

Alt Text

Step 3. You are all set! Click here to launch the game and have fun.

Project URLs -

Team -

Challenges & Future Scope -

We could understand the true potential of MuleSoft as we could leverage most of the capabilities provided by MuleSoft ranging from Design Center for designing APIs and testing RAMLs to Anypoint Studio for building actual APIs to using Object Store all the way till application deployment on MuleSoft's very own CloudHub. We also learned transforming messages into dataweave by exploring its vast set of capabilities.

While we were facing the issue with the Mixed Content error due to HTTPS in github.io & HTTP at the API end, we will be working towards configuring TLS and exposing our BlackJack APIs over HTTPS.

This application would further be enhanced by adding multi-player capabilities over the internet. We also plan to publish a connector for this application.

References -
  1. https://docs.mulesoft.com/runtime-manager/cloudhub
  2. https://docs.mulesoft.com/object-store/

Top comments (3)

Collapse
 
mark1654 profile image
Mark

Looking for an interesting way to unwind, I accidentally found royalreelsonlinecasino.com/ and decided to give it a try. It turned out, not in vain! The site offers not only a wide selection of games, but also excellent conditions for beginners, which is very important. The first games really drew me in, and taking into account the bonuses, it became even more interesting to play. Winnings are withdrawn quickly, there were no difficulties. Now this is one of those places where I return again and again. If you are looking for new gambling experiences, I recommend you to take a look!

Collapse
 
emmacole profile image
Emma Cole

What really stands out for me is how competitive the game can get. Itโ€™s thrilling to play against real players, and the app does a great job of keeping it balanced. You can choose from different stakes depending on your mood, so itโ€™s perfect for casual players and high-rollers alike join now

Collapse
 
jordanschuetz profile image
Jordan Schuetz

Great work! Thanks for submitting