<?php
/**
/
"" ruletka.4t.com
spomoni.habrahabr.ru/blog/9732
ruletka.4t.com biznesland.narod.ru
1) ( 3 )
2) 1)
3) - , 1)
,
*/
mt_srand(make_seed());
$r = new Ruletka;
while ( true ) {
$r->game();
}
//------------------
class Ruletka {
var $budget = 10000; //
var $min_bid = 1; //
var $last_bid = 1; //
var $wait_rolls = 6; //
var $max_budget = 10000000; // ,
var $min_budget = 0; // ,
var $roll ; //
var $is_make_bet = false ; // (true) (false)
var $last_odd_count = 0; //
function game() {
if (!$ this ->is_make_bet) {
$ this ->roll();
if ($ this ->is_odd()) {
$ this ->last_odd_count++;
if ($ this ->last_odd_count >= $ this ->wait_rolls) {
$ this ->is_make_bet = true ;
$ this ->last_bid = $ this ->min_bid;
}
} else {
$ this ->last_odd_count = 0;
}
} else {
$ this ->bid();
$ this ->roll();
if ($ this ->is_odd()) {
$ this ->win();
} else {
$ this ->fail();
}
$ this ->check_game();
}
}
/**
*
*/
function roll() {
$ this ->roll = mt_rand(0,36);
}
//
function is_odd() {
if ($ this ->roll == 0) return false ;
return $ this ->roll % 2 == 0;
}
//
function is_even() {
if ($ this ->roll == 0) return false ;
return $ this ->roll % 2 == 1;
}
function bid() {
$ this ->budget -= $ this ->last_bid;
}
function win() {
$ this ->budget += 2*$ this ->last_bid;
$ this ->is_make_bet = false ;
$ this ->last_bid = $ this ->min_bid;
}
function fail() {
$ this ->last_bid *= 2;
}
function check_game() {
echo "budget = $this->budget\n" ;
if ($ this ->budget <= $ this ->min_budget) {
echo "You fail!!!!" ;
exit;
}
if ($ this ->budget >= $ this ->max_budget) {
echo "You win!!!!" ;
exit;
}
}
}
function make_seed()
{
list($usec, $sec) = explode( ' ' , microtime());
return ( float ) $sec + (( float ) $usec * 100000);
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/101760/
All Articles