Skip to content

iannguyen/gospot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[GOSpot][site]

[Live][site] [site]: http://thegospot.herokuapp.com/

screenshot

GOSpot is a web application inspired by csgolounge, where users can bet their virtual in-game items on professional CS:GO matches.

Features

  • Single-page web application with a Rails RESTful API serving an Ember.js client-side server via the active_model_serializers gem
  • Secure user authentication with ember-simple-auth and devise gem
  • Parimutuel Betting system determines payout odds based on the total pool of each team as opposed to fixed-odds betting
  • Bin-Packing/Coin-Change algorithm efficiently and quickly distributes winning payouts to users after the site takes a 5% rake (see code spotlight below)
  • Users can deposit and withdraw their items instantly through their profile page
  • Users can bet on matches of their choice, anytime between midnight and before the match starts
  • View match score updates live when the match begins
  • Custom scheduled rake tasks start matches, deposit winnings in the users profile, and re-seed random bets and items everyday.

Code Spotlight

The Bin-Packing/Coin-Change Algorithm

winner_returns distribute

  • When a match is over, it starts by first creating Payout models for all the winners, initialized by returning the initial bets and items each winner made
  • Along with the Payout models, profits are calculated and sorted in descending order, ensuring that users with the highest bets are prioritized
  • All the items betted on the losing team are collected and placed into the PayoutTable model, along with Payout and profits of each user, and the site rake amount.

initialize

  • When the PayoutTable model initializes, it generates the @skins_hash (a frequency hash), and the @bp_table.

bp_table

Here is a preview of the @bp_table calculation.

  • The @bp_table takes the @max profit and iterates from 1..@max, and iterates through the keys from the @skins_hash as the available distributable items
  • Through dynamic programming, it generates values for two arrays, the item_count, and last_item array, where the indices of the arrays represent the $ amount, and the value of the item_count and last_item arrays represent the optimal number of items, and the last item used to make change for that amount respectively
  • In the case that the price of the current item is between the current amt and amt + 10%, an overpay is allowed to allow other items to be distributed, and the winner to receive one item of high value
  • By sacrificing space for time, the average is an O(n*k) time complexity solution. Where n represents the max profit amount, and k represents the unique number of items.

cashout

  • For each of the winning profits, cashout is called. Cashout finds the optimal collection of items for the amount by reading the values generated in the @bp_tableand deducts the respective item from the @skins_hash
  • While iterating through the optimal payout, if the @skins_hash doesn't have the necessary item, the @bp_table is recalculated, but not with the original @max profit. Every time an item is deducted from the current payout, the @max gets updated to the maximum of the current remaining amount, or the next profit, insuring that the the @bp_table doesn't compute values that have already been computed.

ToDo

  • Add projected payout amounts at the time of placing a bet
  • Have the payout odds persist after the match is over
  • Add match history

About

Bet your virtual in-game items on CS:GO matches. Inspired by csgolounge.com

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors