class DecoloringBonus extends React.Component { constructor(props) { super(props); this.state = { imagePathOutcome: '/static/img/coin_questionmark.png', imagePathGuess: '/static/img/coin.png', winningSide: "", payment: [], key: 0, modal: false, } this.testCurrentNode = this.testCurrentNode.bind(this); this.submitCoin = this.submitCoin.bind(this); this.nextBall = this.nextBall.bind(this); this.winningSideUpdate = this.winningSideUpdate.bind(this); this.calculateEarnings = this.calculateEarnings.bind(this); this.arrayEquals = this.arrayEquals.bind(this); } componentDidMount() { // Disable clicks in ball var balls = document.getElementsByClassName("ball") for(var i=0;i { if (this.props.imagePathGuess == this.props.imagePathOutcome) { document.getElementById("coinTossWon").classList.remove("d-none"); document.getElementById("moveUp").classList.remove("d-none"); document.getElementById("placeholderFooter").classList.add("d-none"); } else { document.getElementById("coinTossLost").classList.remove("d-none"); document.getElementById("moveDown").classList.remove("d-none"); document.getElementById("placeholderFooter").classList.add("d-none"); } // Grey background for selection section document.getElementById("pickWinningSide").classList.remove("alert-warning"); document.getElementById("pickWinningSide").classList.add("alert-secondary"); var ele = document.getElementsByName("winningSideInput"); for(var i=0;i { const indArray = [ [0], [1, 2], [3, 4, 5], [6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20] ] let upTick = js_vars.upTick let payment = [] let j = 0 for (let i in indArray) { for (let k in indArray[i]) { payment[j] = upTick * i - 2 * k * upTick; j++ } } this.setState({payment}) return payment } // Submit coin toss submitCoin() { liveSend({ 'type': "coin", 'value': this.state.winningSide }) } nextBall() { //document.getElementById("nextCoinBtn").classList.add("d-none") document.getElementById("moveUp").classList.add("d-none") document.getElementById("coinTossWon").classList.add("d-none"); document.getElementById("moveDown").classList.add("d-none") document.getElementById("coinTossLost").classList.add("d-none"); document.getElementById("placeholderFooter").classList.remove("d-none") document.getElementById("pickWinningSide").classList.add("alert-warning"); document.getElementById("pickWinningSide").classList.remove("alert-secondary"); var ele = document.getElementsByName("winningSideInput"); for(var i=0;i val === b[index]); } // Test Current Button testCurrentNode() { const drawn = this.props.drawn || [0] const roundNumber = this.props.roundNumber || [0] const currentNode = drawn[roundNumber] const stoppingStrategy = js_vars.stopStrategy.continuation const pdStop = js_vars.stopStrategy.pdStopDecision const payment = this.state.payment[currentNode] if (stoppingStrategy[currentNode] == 0){ liveSend({ 'type': "payment", 'value': payment }) // Show payment information document.getElementById("continueSection").classList.remove("d-none") document.getElementById("proceedBtnDownCol").classList.add("d-none") document.getElementById("proceedBtnUpCol").classList.add("d-none") } else if (stoppingStrategy[currentNode] == -100){ // Path-dependent const realizedPath = drawn.slice(0,roundNumber+1) const relevantPaths = js_vars.allPaths[currentNode] let pathName = "" for (const [key, value] of Object.entries(relevantPaths)) { if (this.arrayEquals(value[1], realizedPath)) { pathName = value[0] break; } } let stopDecision = pdStop[pathName] if (stopDecision == "Stop") { liveSend({ 'type': "payment", 'value': payment }) // Show payment information document.getElementById("continueSection").classList.remove("d-none") document.getElementById("proceedBtnDownCol").classList.add("d-none") document.getElementById("proceedBtnUpCol").classList.add("d-none") } else { this.nextBall() } } else { this.nextBall() } } winningSideUpdate(chosenSide) { // Disable winning side buttons var ele = document.getElementsByName("winningSideInput"); for(var i=0;i {this.submitCoin()}) } else if (chosenSide == "T") { this.setState({ winningSide: chosenSide, imagePathGuess: '/static/img/coin_t.png' }, () => {this.submitCoin()}) } // Grey background for selection section document.getElementById("pickWinningSide").classList.remove("alert-warning"); document.getElementById("pickWinningSide").classList.add("alert-secondary"); var ele = document.getElementsByName("winningSideInput"); for(var i=0;i element == "Stop") // Calculate accumulated earning to show let payment = 0 if (submittedStop >= 0) { payment = parseFloat(this.state.payment[this.props.drawn[submittedStop]]) } else { payment = parseFloat(this.state.payment[this.props.drawn[this.props.roundNumber]]) } return( <>
{/* Left column showing stopping strategy */}
Your decoloring
Your current accumulated earnings are £{payment.toFixed(2)}.
{/* Footer */}
You moved up.
You moved down.
{/* Right column */}
) } }