class WalkingTask extends React.Component { constructor(props) { super(props); this.state = { rightSide: "instruction", rightSideHeader: "Your instruction at the pulsing ball", imagePathOutcome: '/static/img/coin_questionmark.png', imagePathGuess: '/static/img/coin.png', winningSide: "", payment: [], keyNum: 0, modal: false, } this.testCurrentNode = this.testCurrentNode.bind(this); this.ballInstructions = this.ballInstructions.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.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); this.arrayEquals = this.arrayEquals.bind(this); } componentDidMount() { // Disable ball clicks var balls = document.getElementsByClassName("ball") for(var i=0;i { document.getElementById("confirm_btn").disabled = false; }, 1000) } else if (!this.props.practiceRound){ this.openModal(); // Hide risk info document.getElementById("riskInfo").classList.add("d-none") } else { document.getElementById("confirm_btn").classList.remove("d-none") document.getElementById("remainingRounds").classList.add("d-none") document.getElementById("nextScreen").classList.remove("d-none") document.getElementById("task").classList.add("d-none") if ( ! this.props.continuationDec.slice(0,this.props.roundNumber).includes("Stop")){ // Only stop in last round // Include information about five risks for all Walking Tasks document.getElementById("fiveRisks").classList.remove("d-none") } } } else if (this.props.type == "coin"){ if ((this.props.continuationDec.slice(0,5).includes("Stop"))) { this.setState({ rightSide: "coin", imagePathGuess: this.props.imagePathGuess, imagePathOutcome: '/static/img/coin_questionmark.png', }, () => { document.getElementById("placeholderFooter").classList.add("d-none"); document.getElementById("noFeedback").classList.remove("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 { 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 { document.getElementById("pickWinningSide").classList.remove("d-none")}) } else { this.testCurrentNode() } this.calculateEarnings(); } openModal() { this.setState({ modal: true, keyNum: 4 }) document.getElementById("lineSVG").id="lineSVG_main" } calculateEarnings = () => { 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("moveDown").classList.add("d-none") document.getElementById("noFeedback").classList.add("d-none") document.getElementById("placeholderFooter").classList.remove("d-none") this.setState({ rightSide: "instruction", imagePathOutcome: '/static/img/coin_questionmark.png', imagePathGuess: '/static/img/coin.png', winningSide: "", }, this.testCurrentNode) } arrayEquals(a, b) { return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((val, index) => 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 let radioValue ="" if (stoppingStrategy[currentNode] == 100) { // White Ball radioValue = "Continue" } else if (stoppingStrategy[currentNode] == 0){ // Black Ball radioValue = "Stop" } else if (stoppingStrategy[currentNode] == -100) { // White-black-gradient 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; } } radioValue = pdStop[pathName] } $("input[name=ballDecision][value=" + radioValue + "]").prop('checked', true); } ballInstructions () { // Submit changed choice let decision = document.querySelector('input[name="ballDecision"]:checked').value; if (decision == "Stop") { liveSend({ 'type': "nodeChoice", 'value': "Stop", 'ballContinue': 0, }) } else if (decision == "Continue") { liveSend({ 'type': "nodeChoice", 'value': "Continue", 'ballContinue': 100, }) } this.setState({ rightSide: "coin" }, () => { document.getElementById("pickWinningSide").classList.remove("d-none") }) } 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 { for (let radio of document.querySelectorAll('input[type=radio]')) { radio.disabled = false; } document.getElementById("pickWinningSide").classList.remove("alert-secondary") document.getElementById("pickWinningSide").classList.add("alert-warning") }, 5000) } else { document.getElementById("riskInfo").classList.add("d-none") } document.getElementById("accumulatedEarningsDiv").style.visibility = "hidden" this.setState({ //keyNum: 1, modal:false}) } render() { // Find stop decision let submittedContinuation = this.props.continuationDec.slice(0,this.props.roundNumber + 1) let submittedStop = submittedContinuation.findIndex(element => 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]]) } // Write payment to main page if (! this.props.practiceRound) { document.getElementById("finPay1").innerHTML = payment.toFixed(2) } return( <>
{/* Left column showing stopping strategy */}
Your decoloring
Your current accumulated earnings are £{payment.toFixed(2)}.
{ (! this.state.modal) ? <> : <> }
{/* Footer */}
{ !(this.props.continuationDec.slice(0,5).includes("Stop")) ?
You moved up.
: <>}
{ !(this.props.continuationDec.slice(0,5).includes("Stop")) ?
You moved down.
: <>}
{/* Right column */}
{this.state.rightSide == "instruction" ?
{this.state.rightSideHeader}
At this ball, please
Stop Continue
taking risks.


: (this.state.rightSide == "coin") ? : <> }
) } } class BonusModal extends React.Component { constructor(props) { super(props); this.state = { keyForTriangle: 0, } } componentDidMount() { this.setState({keyForTriangle: 5}) } render() { if(!this.props.show){ return null; } else { $('#staticBackdrop').modal("show") } return ( <> )} }