Last active
June 24, 2019 11:37
-
-
Save kloetzl/ccabcf5ec97faef74e859f6673a7e777 to your computer and use it in GitHub Desktop.
This file contains 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> | |
<script src=https://code.jquery.com/jquery-3.4.1.min.js></script> | |
<style type="text/css"> | |
tr > td:first-child { | |
border-right: solid 2px gray; | |
} | |
table > tr:last-child * { | |
border-top: solid 2px gray; | |
} | |
td.ohne-max > span.ohne { | |
font-weight: bold; | |
color: gray; | |
} | |
td.finte-max > span.finte { | |
font-weight: bold; | |
color: darkred; | |
} | |
td.wuchtschlag-max > span.wuchtschlag { | |
font-weight: bold; | |
color: darkblue; | |
} | |
</style> | |
</head> | |
<body> | |
<table id=tab></table> | |
<script> | |
var tr = $('<tr>'); | |
for (var i = 0; i <= 20; i++) { | |
tr.append('<td>' + i + '</td>'); | |
} | |
for (i = 0; i <= 20; i++) { | |
tr.clone().appendTo('#tab'); | |
} | |
// Keule: 1W6 + 3 | |
// Streitaxt: 1W6 + 4 | |
// Kriegshammer: 2W6 + 3 | |
var durchschnl_schaden = 3.5 + 3; | |
var AT, PA; | |
function ohne(wa, wv) { | |
if (wa == 20 || wv == 1) return 0; // Grenzwerte | |
if (wa == 1) { | |
if (wv <= Math.ceil(PA / 2)) return 0; // trotzdem pariert | |
var p = AT / 20; | |
var kritischer_schaden = p * (durchschnl_schaden * 2); | |
var glücklicher_schaden = (1 - p) * durchschnl_schaden; | |
return kritischer_schaden + glücklicher_schaden; | |
} | |
if (wa <= AT) { | |
if (wv <= PA) return 0; // pariert | |
return durchschnl_schaden; // Schaden | |
} | |
return 0; // nicht getroffen | |
} | |
function finte(wa, wv) { | |
if (wa == 20 || wv == 1) return 0; // Grenzwerte | |
if (AT <= 1) return 0; | |
if (wa == 1) { | |
// krit | |
if (PA > 2 ? wv <= Math.ceil((PA - 2) / 2) : false) return 0; // trotzdem pariert | |
var p = (AT - 1) / 20; | |
var kritischer_schaden = p * (durchschnl_schaden * 2); | |
var glücklicher_schaden = (1 - p) * durchschnl_schaden; | |
return kritischer_schaden + glücklicher_schaden; | |
} | |
if (wa <= AT - 1) { | |
if (PA > 2 ? wv <= PA - 2 : false) return 0; // pariert | |
return durchschnl_schaden; // Schaden | |
} | |
return 0; // nicht getroffen | |
} | |
function wuchtschlag(wa, wv) { | |
if (wa == 20 || wv == 1) return 0; // Grenzwerte | |
if (AT <= 2) return 0; | |
if (wa == 1) { | |
// krit | |
if (wv <= Math.ceil(PA / 2)) return 0; // trotzdem pariert | |
var p = (AT - 2) / 20; | |
var kritischer_schaden = p * ((durchschnl_schaden + 2) * 2); | |
var glücklicher_schaden = (1 - p) * (durchschnl_schaden + 2); | |
return kritischer_schaden + glücklicher_schaden; | |
} | |
if (wa <= AT - 2) { | |
if (wv <= PA) return 0; // pariert | |
return durchschnl_schaden + 2; // Schaden | |
} | |
return 0; // nicht getroffen | |
} | |
function schaden_ohne() { | |
var summe = 0; | |
for (let wa = 1; wa <= 20; wa++) { | |
for (let wv = 1; wv <= 20; wv++) { | |
summe += ohne(wa, wv); | |
} | |
} | |
return summe / 400; | |
} | |
function schaden_finte() { | |
var summe = 0; | |
for (let wa = 1; wa <= 20; wa++) { | |
for (let wv = 1; wv <= 20; wv++) { | |
summe += finte(wa, wv); | |
} | |
} | |
return summe / 400; | |
} | |
function schaden_wuchtschlag() { | |
var summe = 0; | |
for (let wa = 1; wa <= 20; wa++) { | |
for (let wv = 1; wv <= 20; wv++) { | |
summe += wuchtschlag(wa, wv); | |
} | |
} | |
return summe / 400; | |
} | |
function cell(AT, PA) { | |
return $('#tab').children().eq(20 - AT).children().eq(PA); | |
} | |
for (AT = 1; AT <= 20; AT++) { | |
cell(AT, 0).text(AT); | |
for (PA = 1; PA <= 20; PA++) { | |
var s_ohne = schaden_ohne().toPrecision(3); | |
var s_finte = schaden_finte().toPrecision(3); | |
var s_wuchtschlag = schaden_wuchtschlag().toPrecision(3); | |
cell(AT, PA).empty().append( | |
'<span class=ohne>' + s_ohne + '</span> <br>' + | |
'<span class=finte>' + s_finte + '</span> <br>' + | |
'<span class=wuchtschlag>' + s_wuchtschlag + '</span>' | |
); | |
if (s_ohne >= s_finte && s_ohne >= s_wuchtschlag) { | |
cell(AT, PA).addClass('ohne-max'); | |
} | |
if (s_finte >= s_ohne && s_finte >= s_wuchtschlag) { | |
cell(AT, PA).addClass('finte-max'); | |
} | |
if (s_wuchtschlag >= s_finte && s_wuchtschlag >= s_ohne) { | |
cell(AT, PA).addClass('wuchtschlag-max'); | |
} | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Voller Fehler… /edit: fixed.