Created
April 9, 2020 10:45
-
-
Save amih/d6b52bea6fd98b455c20866a61f038de to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/sagigac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<script src="https://unpkg.com/[email protected]/lib/gaussian.js"></script> | |
<script src="https://bossanova.uk/jexcel/v3/jexcel.js"></script> | |
<script src="https://bossanova.uk/jsuites/v2/jsuites.js"></script> | |
<link rel="stylesheet" href="https://bossanova.uk/jexcel/v3/jexcel.css" type="text/css" /> | |
<link rel="stylesheet" href="https://bossanova.uk/jsuites/v2/jsuites.css" type="text/css" /> | |
<style id="jsbin-css"> | |
#summary, #details { | |
height: 400px; | |
border: 1px solid blue; | |
overflow-y : auto; | |
} | |
</style> | |
</head> | |
<body> | |
<div>Summary</div> | |
<div id="summary"></div> | |
<div>Details</div> | |
<div id="details"></div> | |
<script id="jsbin-javascript"> | |
//jshint esnext:true | |
// noprotect | |
const gaussian = window.gaussian; // require('gaussian'); | |
const N45 = (mean, sd=45) => gaussian(mean, sd*sd).ppf(Math.random()); | |
const U = (min, max) => Math.floor(Math.random()*(max - min + 1) + min) | |
const removeSmallest = (arr) => { | |
arr.sort((a, b) => Math.sign(a.bet - b.bet)); | |
const numOfLosers = arr.reduce((acc, cur) => (cur.bet == arr[0].bet) ? acc+1 : acc, 0); | |
arr.splice(U(1, numOfLosers), 1); // remove one of the losers | |
return arr; | |
} | |
// const log = (where, ...params) => { | |
// for(p of params){ document.getElementById(where).innerHTML += p + ' '; } | |
// document.getElementById(where).innerHTML += '<br>'; | |
// } | |
// for(let i=0; i<10; i++) log('summary', N45(45, 3)); | |
// for(let i=0; i<10; i++) log('details', U(0, 150)); | |
var data1 = [ [ 2, 10, 1.10, '=B1*C1'] ]; | |
var table1 = jexcel(document.getElementById('details'), { | |
data:data1, | |
columns: [ | |
{ title: 'Round', type: 'text', width:'50px', }, | |
{ title: 'inner', type: 'text', width:'50px', }, | |
{ title: 'X1', type: 'number', width:'30px', }, | |
{ title: 'X2', type: 'number', width:'30px', }, | |
{ title: 'Player-Strategy', type: 'number', width:'200px', align: 'left'}, | |
{ title: '?', type: 'number', width:'30px', }, | |
{ title: 'Bet', type: 'number', width:'30px', }, | |
], | |
rowResize: true, | |
}); | |
var dataS = [ [ 2, 10 ] ]; | |
var tableS = jexcel(document.getElementById('summary'), { | |
data:dataS, | |
columns: [ | |
{ title: 'Round', type: 'text', width:'50px', }, | |
{ title: 'Player-Strategy', type: 'number', width:'200px', align: 'left'}, | |
], | |
rowResize: true, | |
}); | |
const getPlayers = () => { | |
return [ | |
{ | |
strategy: 'simple,max(x1,x2)', | |
func: (X1, X2, T) => { | |
if(X1>X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)1', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)2', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)3', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)4', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)5', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)6', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe1', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe2', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe3', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe4', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe5', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysRisk', | |
func: (X1, X2, T) => { | |
return 'R'; | |
} | |
}, | |
]; | |
} | |
for(let roundNum = 0; roundNum<4; roundNum++){ | |
let player = getPlayers(); | |
while(player.length>1){ | |
let X1 = U(0,150); | |
let X2 = U(0,150); | |
for(i=0; i<player.length; i++){ | |
let decision = player[i].func(X1, X2, player.length); | |
if(decision == 'S'){ | |
player[i].bet = X1; | |
}else{ | |
player[i].bet = Math.round(N45(X2)); | |
} | |
if(roundNum<3){ | |
table1.insertRow([(roundNum+1).toString(), (i+1).toString(), X1, X2, player[i].strategy, decision, player[i].bet]); | |
} | |
} | |
player = removeSmallest(player); // find loser and remove him | |
if(player.length==1){ | |
tableS.insertRow([(roundNum+1).toString(), player[0].strategy]); | |
} | |
} | |
} | |
table1.deleteRow(0,1); | |
tableS.deleteRow(0,1); | |
</script> | |
<script id="jsbin-source-css" type="text/css">#summary, #details { | |
height: 400px; | |
border: 1px solid blue; | |
overflow-y : auto; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">//jshint esnext:true | |
// noprotect | |
const gaussian = window.gaussian; // require('gaussian'); | |
const N45 = (mean, sd=45) => gaussian(mean, sd*sd).ppf(Math.random()); | |
const U = (min, max) => Math.floor(Math.random()*(max - min + 1) + min) | |
const removeSmallest = (arr) => { | |
arr.sort((a, b) => Math.sign(a.bet - b.bet)); | |
const numOfLosers = arr.reduce((acc, cur) => (cur.bet == arr[0].bet) ? acc+1 : acc, 0); | |
arr.splice(U(1, numOfLosers), 1); // remove one of the losers | |
return arr; | |
} | |
// const log = (where, ...params) => { | |
// for(p of params){ document.getElementById(where).innerHTML += p + ' '; } | |
// document.getElementById(where).innerHTML += '<br>'; | |
// } | |
// for(let i=0; i<10; i++) log('summary', N45(45, 3)); | |
// for(let i=0; i<10; i++) log('details', U(0, 150)); | |
var data1 = [ [ 2, 10, 1.10, '=B1*C1'] ]; | |
var table1 = jexcel(document.getElementById('details'), { | |
data:data1, | |
columns: [ | |
{ title: 'Round', type: 'text', width:'50px', }, | |
{ title: 'inner', type: 'text', width:'50px', }, | |
{ title: 'X1', type: 'number', width:'30px', }, | |
{ title: 'X2', type: 'number', width:'30px', }, | |
{ title: 'Player-Strategy', type: 'number', width:'200px', align: 'left'}, | |
{ title: '?', type: 'number', width:'30px', }, | |
{ title: 'Bet', type: 'number', width:'30px', }, | |
], | |
rowResize: true, | |
}); | |
var dataS = [ [ 2, 10 ] ]; | |
var tableS = jexcel(document.getElementById('summary'), { | |
data:dataS, | |
columns: [ | |
{ title: 'Round', type: 'text', width:'50px', }, | |
{ title: 'Player-Strategy', type: 'number', width:'200px', align: 'left'}, | |
], | |
rowResize: true, | |
}); | |
const getPlayers = () => { | |
return [ | |
{ | |
strategy: 'simple,max(x1,x2)', | |
func: (X1, X2, T) => { | |
if(X1>X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)1', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)2', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)3', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)4', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)5', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)6', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe1', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe2', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe3', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe4', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe5', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysRisk', | |
func: (X1, X2, T) => { | |
return 'R'; | |
} | |
}, | |
]; | |
} | |
for(let roundNum = 0; roundNum<4; roundNum++){ | |
let player = getPlayers(); | |
while(player.length>1){ | |
let X1 = U(0,150); | |
let X2 = U(0,150); | |
for(i=0; i<player.length; i++){ | |
let decision = player[i].func(X1, X2, player.length); | |
if(decision == 'S'){ | |
player[i].bet = X1; | |
}else{ | |
player[i].bet = Math.round(N45(X2)); | |
} | |
if(roundNum<3){ | |
table1.insertRow([(roundNum+1).toString(), (i+1).toString(), X1, X2, player[i].strategy, decision, player[i].bet]); | |
} | |
} | |
player = removeSmallest(player); // find loser and remove him | |
if(player.length==1){ | |
tableS.insertRow([(roundNum+1).toString(), player[0].strategy]); | |
} | |
} | |
} | |
table1.deleteRow(0,1); | |
tableS.deleteRow(0,1);</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#summary, #details { | |
height: 400px; | |
border: 1px solid blue; | |
overflow-y : auto; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//jshint esnext:true | |
// noprotect | |
const gaussian = window.gaussian; // require('gaussian'); | |
const N45 = (mean, sd=45) => gaussian(mean, sd*sd).ppf(Math.random()); | |
const U = (min, max) => Math.floor(Math.random()*(max - min + 1) + min) | |
const removeSmallest = (arr) => { | |
arr.sort((a, b) => Math.sign(a.bet - b.bet)); | |
const numOfLosers = arr.reduce((acc, cur) => (cur.bet == arr[0].bet) ? acc+1 : acc, 0); | |
arr.splice(U(1, numOfLosers), 1); // remove one of the losers | |
return arr; | |
} | |
// const log = (where, ...params) => { | |
// for(p of params){ document.getElementById(where).innerHTML += p + ' '; } | |
// document.getElementById(where).innerHTML += '<br>'; | |
// } | |
// for(let i=0; i<10; i++) log('summary', N45(45, 3)); | |
// for(let i=0; i<10; i++) log('details', U(0, 150)); | |
var data1 = [ [ 2, 10, 1.10, '=B1*C1'] ]; | |
var table1 = jexcel(document.getElementById('details'), { | |
data:data1, | |
columns: [ | |
{ title: 'Round', type: 'text', width:'50px', }, | |
{ title: 'inner', type: 'text', width:'50px', }, | |
{ title: 'X1', type: 'number', width:'30px', }, | |
{ title: 'X2', type: 'number', width:'30px', }, | |
{ title: 'Player-Strategy', type: 'number', width:'200px', align: 'left'}, | |
{ title: '?', type: 'number', width:'30px', }, | |
{ title: 'Bet', type: 'number', width:'30px', }, | |
], | |
rowResize: true, | |
}); | |
var dataS = [ [ 2, 10 ] ]; | |
var tableS = jexcel(document.getElementById('summary'), { | |
data:dataS, | |
columns: [ | |
{ title: 'Round', type: 'text', width:'50px', }, | |
{ title: 'Player-Strategy', type: 'number', width:'200px', align: 'left'}, | |
], | |
rowResize: true, | |
}); | |
const getPlayers = () => { | |
return [ | |
{ | |
strategy: 'simple,max(x1,x2)', | |
func: (X1, X2, T) => { | |
if(X1>X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)1', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)2', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)3', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)4', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)5', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'crazy,min(x1,x2)6', | |
func: (X1, X2, T) => { | |
if(X1<X2){ | |
return 'S'; | |
} else { | |
return 'R'; | |
} | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe1', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe2', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe3', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe4', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysSafe5', | |
func: (X1, X2, T) => { | |
return 'S'; | |
} | |
}, | |
{ | |
strategy: 'alwaysRisk', | |
func: (X1, X2, T) => { | |
return 'R'; | |
} | |
}, | |
]; | |
} | |
for(let roundNum = 0; roundNum<4; roundNum++){ | |
let player = getPlayers(); | |
while(player.length>1){ | |
let X1 = U(0,150); | |
let X2 = U(0,150); | |
for(i=0; i<player.length; i++){ | |
let decision = player[i].func(X1, X2, player.length); | |
if(decision == 'S'){ | |
player[i].bet = X1; | |
}else{ | |
player[i].bet = Math.round(N45(X2)); | |
} | |
if(roundNum<3){ | |
table1.insertRow([(roundNum+1).toString(), (i+1).toString(), X1, X2, player[i].strategy, decision, player[i].bet]); | |
} | |
} | |
player = removeSmallest(player); // find loser and remove him | |
if(player.length==1){ | |
tableS.insertRow([(roundNum+1).toString(), player[0].strategy]); | |
} | |
} | |
} | |
table1.deleteRow(0,1); | |
tableS.deleteRow(0,1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment