1. Home
  2. >
  3. Gambling
2

Gambling
NieR

Every time the player loses, the stake is doubled.

<?php

const MAX_ROUND = 100, MUL = 2,CREDIT_INIT = 200;
$current_balance = CREDIT_INIT;$bet_amount = 1;
$win_count = 0;$lose_count = 0;
$turn_over = 0;$total_bet_win = 0;$total_bet_lose=0;


for($i = 0;$i<MAX_ROUND;$i++)
{
    $result = mt_rand()%2;$turn_over += $bet_amount;
  
  	if($result == 1)
    {
      $current_balance = $current_balance+$bet_amount;$total_bet_win += $bet_amount;
      $win_count++; $bet_amount = 1;     
    }
  	
  	else
    {
      $current_balance = $current_balance-$bet_amount;$total_bet_lose += $bet_amount;
      $lose_count++;$bet_amount = $bet_amount*MUL; 

    }
  
  
  
        $result = $result == 1 ? 'win' : 'lose';
    	echo "round :".(1+$i)." result: ".$result ."(W/L) :"."(".$win_count."/".$lose_count.")";
        echo " ,bet_amount :".$bet_amount." ,balance : ".$current_balance."\n";
}
		echo "\n\n|___________________SUMMARY________________|\n";
		echo "Turnover: "."$turn_over". "\nTotal Win: ".$total_bet_win."\nTotal Lose: ".$total_bet_lose;
		echo "\nProfit: ". ($current_balance - CREDIT_INIT);



# gambling