import * as React from "react"; import { IPlayer } from "../PersonObjects/IPlayer"; import { StdButton } from "../ui/React/StdButton"; import { Money } from "../ui/React/Money"; import { Game } from "./Game"; import { WHRNG } from "./RNG"; import { trusted } from "./utils"; type IProps = { p: IPlayer; }; type IState = { investment: number; canPlay: boolean; status: string | JSX.Element; n: number; lock: boolean; strategy: Strategy; }; const minPlay = 0; const maxPlay = 1e7; function isRed(n: number): boolean { return [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36].includes(n); } type Strategy = { match: (n: number) => boolean; payout: number; }; const redNumbers: number[] = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36]; const strategies: { Red: Strategy; Black: Strategy; Odd: Strategy; Even: Strategy; High: Strategy; Low: Strategy; Third1: Strategy; Third2: Strategy; Third3: Strategy; } = { Red: { match: (n: number): boolean => { if (n === 0) return false; return redNumbers.includes(n); }, payout: 1, }, Black: { match: (n: number): boolean => { return !redNumbers.includes(n); }, payout: 1, }, Odd: { match: (n: number): boolean => { if (n === 0) return false; return n % 2 === 1; }, payout: 1, }, Even: { match: (n: number): boolean => { if (n === 0) return false; return n % 2 === 0; }, payout: 1, }, High: { match: (n: number): boolean => { if (n === 0) return false; return n > 18; }, payout: 1, }, Low: { match: (n: number): boolean => { if (n === 0) return false; return n < 19; }, payout: 1, }, Third1: { match: (n: number): boolean => { if (n === 0) return false; return n <= 12; }, payout: 2, }, Third2: { match: (n: number): boolean => { if (n === 0) return false; return n >= 13 && n <= 24; }, payout: 2, }, Third3: { match: (n: number): boolean => { if (n === 0) return false; return n >= 25; }, payout: 2, }, }; function Single(s: number): Strategy { return { match: (n: number): boolean => { return s === n; }, payout: 36, }; } export class Roulette extends Game { interval = -1; rng: WHRNG; constructor(props: IProps) { super(props); this.rng = new WHRNG(new Date().getTime()); this.state = { investment: 1000, canPlay: true, status: "waiting", n: 0, lock: true, strategy: { payout: 0, match: (): boolean => { return false; }, }, }; this.step = this.step.bind(this); this.currentNumber = this.currentNumber.bind(this); this.updateInvestment = this.updateInvestment.bind(this); } componentDidMount(): void { this.interval = window.setInterval(this.step, 50); } step(): void { if (!this.state.lock) { this.setState({ n: Math.floor(Math.random() * 37) }); } } componentWillUnmount(): void { clearInterval(this.interval); } updateInvestment(e: React.FormEvent): void { let investment: number = parseInt(e.currentTarget.value); if (isNaN(investment)) { investment = minPlay; } if (investment > maxPlay) { investment = maxPlay; } if (investment < minPlay) { investment = minPlay; } this.setState({ investment: investment }); } currentNumber(): string { if (this.state.n === 0) return "0"; const color = isRed(this.state.n) ? "R" : "B"; return `${this.state.n}${color}`; } play(s: Strategy): void { if (this.reachedLimit(this.props.p)) return; this.setState({ canPlay: false, lock: false, status: "playing", strategy: s, }); setTimeout(() => { let n = Math.floor(this.rng.random() * 37); let status = <>; let gain = 0; let playerWin = this.state.strategy.match(n); // oh yeah, the house straight up cheats. Try finding the seed now! if (playerWin && Math.random() > 0.9) { playerWin = false; while (this.state.strategy.match(n)) { n = (n + 1) % 36; } } if (playerWin) { gain = this.state.investment * this.state.strategy.payout; status = ( <> won ); } else { gain = -this.state.investment; status = ( <> lost ); } this.win(this.props.p, gain); this.setState({ canPlay: true, lock: true, status: status, n: n, }); this.reachedLimit(this.props.p); }, 1600); } render(): React.ReactNode { return ( <>

{this.currentNumber()}

{this.state.status}

this.play(Single(3)))} /> this.play(Single(6)))} /> this.play(Single(9)))} /> this.play(Single(12)))} /> this.play(Single(15)))} /> this.play(Single(18)))} /> this.play(Single(21)))} /> this.play(Single(24)))} /> this.play(Single(27)))} /> this.play(Single(30)))} /> this.play(Single(33)))} /> this.play(Single(36)))} />
this.play(Single(2)))} /> this.play(Single(5)))} /> this.play(Single(8)))} /> this.play(Single(11)))} /> this.play(Single(14)))} /> this.play(Single(17)))} /> this.play(Single(20)))} /> this.play(Single(23)))} /> this.play(Single(26)))} /> this.play(Single(29)))} /> this.play(Single(32)))} /> this.play(Single(35)))} />
this.play(Single(1)))} /> this.play(Single(4)))} /> this.play(Single(7)))} /> this.play(Single(10)))} /> this.play(Single(13)))} /> this.play(Single(16)))} /> this.play(Single(19)))} /> this.play(Single(22)))} /> this.play(Single(25)))} /> this.play(Single(28)))} /> this.play(Single(31)))} /> this.play(Single(34)))} />
this.play(strategies.Third1))} /> this.play(strategies.Third2))} /> this.play(strategies.Third3))} />
this.play(strategies.Red))} /> this.play(strategies.Black))} /> this.play(strategies.Odd))} /> this.play(strategies.Even))} /> this.play(strategies.High))} /> this.play(strategies.Low))} />
this.play(Single(0)))} />
); } }