berry choices

berry choices

by yairamon

HTML

<center>
  <h2>How many perfect encounters do raid winners get?</h2>

  <table border="1" width="55%">
    <tr>
      <th>How many raiders?</th>
      <td>
        <input type="text" id="trainersSimulated" value="10000" />
      </td>
    </tr>
    <tr>
      <th>How many raids each?</th>
      <td>
        <input type="text" id="trialsPerTrainer" value="435" />
      </td>
    </tr>
  </table>


  <input type="button" id="button" value="Simulate!" />


</center>


<div id="histo" class="histo"></div>

<div id="console"> </div>




<script src="https://d3js.org/d3.v2.min.js?2.10.0">

CSS

input {
  text-align: right;
}

.debug {
  color: black;
}

.error {
  color: red;
}

.info {
  color: gray;
}

.histo {
  font: 12px sans-serif;
}

body {
  font: 15px courier;
}

.bar rect {
  fill: steelblue;
  shape-rendering: crispEdges;
}

p {
  line-height: 40%;
}

.bar text {
  fill: #fff;
}

JavaScript

$('#button').click(function() {
  runSimulations();
});


function runSimulations() {
  simulate($('#trialsPerTrainer').val(),
    $('#trainersSimulated').val(),
  );
}


var console = function() {
  var log = function(message, type) {
    switch (type) {
      case 0:
        strMessage = "<p class=\"debug\">" + message + "</p>";
        break;
      case 1:
        strMessage = "<p class=\"error\">" + message + "</p>";
        break;
      case 2:
        strMessage = "<p class=\"info\">" + message + "</p>";
        break;
      default:
        strMessage = "<p class=\"debug\">" + message + "</p>";
    }

    $("#console").append(strMessage);
  };

  return {
    log: log
  };
}();


function simulate(trialsPerTrainer, trainersSimulated) {

 $("#console").empty();
  $("#histo").empty();

  var baseCaptureRate = 0.02;
  var cpmFactor = 0.59740001;

  var raidBallMultiplier = 1.0;
  var curveMultiplier = 1.7;
  var medalMultiplier = 1.3;
  var pinapMultiplier = 1.0;
  var goldenMultiplier = 2.5;
	
	var numRaidBalls = 14;
  var throwMultiplier = 1;
  var numToPinap = 12;

  var totalCatchOdds = 0;
  var totalCandyExpected = 0;
  var totalGoldenUsedExpected = 0;

	for (var i = 0; i < numRaidBalls; i++) {
  
  	var useGolden = (i >= numToPinap);
    
  	var berryMultiplier = useGolden ? goldenMultiplier : pinapMultiplier;
    
  	var totalMultiplier = raidBallMultiplier * curveMultiplier * medalMultiplier * berryMultiplier * throwMultiplier;
    
    var catchProbability = 1 - Math.pow(1 - (baseCaptureRate) /  (2 * cpmFactor), totalMultiplier);
    
    var incrementalProbability = (1 - totalCatchOdds) * catchProbability;
    
    var candy = useGolden ? 4 : 7;
    
  	console.log(i + " " + incrementalProbability.toFixed(2), 2);

    totalGoldenUsedExpected += useGolden ? (1 - totalCatchOdds) : 0.0;
    
    totalCatchOdds += incrementalProbability;
    totalCandyExpected += incrementalProbability * candy;
    
  }

  console.log("=> Catch %" + 
  	(totalCatchOdds...