Sunday, July 7, 2013

Creating a Webgame - How We Made a Stock Market Simulator Out of the Nothing and php and part 1


The development of a web-based game as a Stock simulator starts a good idea. Not just 'I need to make a Stock Market sim' these idea 'I intent to make a different and new Stock Market sim, one that is better and so on unique than anything today out there'

Then comes research - seeing what other market sims are already already in the market and functional and seeing their work from an end-user's look at. There are Stock Market sims who run using java and server-based engines eg the Hollywood Stock Exchange, sims who run using SSI and ASP modules, and open-source Stock sims eg the Futures Exchange. We looked at these and determined where the opening lay concerning the market and where demand is going to be.

We determined a large void was sitting as to prediction markets and dispenses exchanges for Stock Market Games and simulators so that you may television. There were plenty of websites where you can vote for your show's popularity, and other sites where you can even vote for nick shows and try towards your luck at predicting who was next to go. But no site was there that treated TV due to Stock Market. so we decided that's our niche game.

Television is a growth industry - Each year they sell more TV sets than the previous year. TV studios work tirelessly to build new and different shows helping put over the airwaves and cable networks to entertain hundreds of millions of people in The united states alone. All of those viewers include an opinion about what they like , nor like - that is a market unlike any a few other.

We sat down and requirements crabbed out a checklist of the items a TV Stock Market may do...



  • Buy and sell Stocks in TV demonstrates, TV channels, Studios, and it stars


  • Short sell and over the same Stocks (Short selling and covering goes against a buy or also provide, if you short a extremely Stock, you hope the price drops and try to gain money on the fall. )


  • Rate or vote for popular TV shows


  • offer easy to use registration that is seamless


  • design the end users system for extreme modularity so we can add in functions as we develop them without interrupting the market itself.


That was our original group of features. At the end of the article series - I'll show an index of the current features and has how the market system has grown in complexity but still retains every one of the basic modularity we developed into it.

The most important thing above all was to build an effective way to buy and sell stocks and shares, to track the actual buy and sell process, and to empower the market itself to adjust pricings as product is exchanged.

We decided to try mysql for databasing, also to implement a cron job to run the background calculations many market balancing.

By by using an php language, we could more in a natural way implement mysql access today allow for more flexibility in the goal of keeping the Stocks Match as modular as possible.

MySql and php have been completely modified during their lifecycles to end up being close to seamlessly together attainable, so it made sense you can use the two components to generatte our Stock system like it would enable easier retention and future development.

Beginning by having a basic math code of

</p><br/><p><br/>Decide to buy price = Stock sloppy farrade x (Number of provides + commission)</p><br/><p><br/>

We developed a simple change process that would permit the player to buy shares or place them. with the system easily calculating commission and adding with regard to this the transaction.

We realised that we for you to limit the shares capable of being bought by a single lb . player, so set you must ceiling of 25, 000 tells you per Stock. This makes sure of no one player could build a monopoly on shares. and also limited the result of a single bulk buy maybe a sell.

What started as a useful formula and tracking system rapidly ballooned into a complex math function locomotive that now looked this way:


Number of shares available
= (max shares available - quantity of shares held by player)
IF
player shares are what follows max allowed
THEN
process buy transaction
Buy
current price * various kinds of shares available + fees (1. 5%)
Transaction complete : do market calculations
Stock quickness adjust by (+0. 01 by 5, 000 shares otherwise known as fraction thereof)
cron runs, providing transaction and adjusting 0. 01 in every 10, 000 shares moved
cron also checks a slightly more than 50, 000 tells you have moved
then Stock varies slowed to. 01 per cron cycle to confirm a run-on Stock does not occur.

To ensure this happened properly i was forced to add in multiple mysql table entries with cron and the path to track the Stock transactions so not simply could we gain previous transactions and Stock variations, but also the internal organs could cross-check itself to maintain balance when you are data corruption or a horrible Stock transaction.

The sell transaction was pretty much the same process but with negatives clear of positives.

We also implemented a normal voting system whereby players could opt for their favorite TV tv series - thereby adjusting the significance of that show Stock up or down dependent upon their vote. If your shape liked the show, vote yes, if you not want it, vote no. We create random generator to tug 10 show names by reviewing the database every time these products vote page was full so no show can offer more weight than any kind of show. thus ensuring a even number of votes. The vote system also rewarded the gamer by adding game cash of these account for each vote clicked. If you voted for a lot of 10 options, you accomplished $10k. Thereby, greed is a factor - get more $ to tackle by voting.

Building the player portfolio page was just a matter of setting up an if/then loop to be able to every Stock held one after another and displaying them of page with their decide to purchase price, current price, deals difference, and so on.

Nest article will explain how we built the Stock ticker and other features, and the future directions the Stock Playing field will go in.

.

No comments:

Post a Comment