Skip to content

Commit 4eec358

Browse files
Script tweak and tc tree command added.
1 parent fc4aa06 commit 4eec358

2 files changed

Lines changed: 65 additions & 7 deletions

File tree

precalctc.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,12 @@
7373

7474
usort($precalc[$playermod], fn ($a, $b) => $b[1] <=> $a[1]);
7575

76-
if (isset($data['runs'])) {
77-
$stats["$tc_name [$dropmodifier]"] = [
78-
'total' => $data['runs'],
79-
'elapsed' => $elapsed,
80-
];
76+
$stats["$tc_name [$dropmodifier]"] = [
77+
'total' => $data['runs'],
78+
'elapsed' => $elapsed,
79+
];
8180

82-
print($data['runs'] . " in " . number_format($elapsed, 3) . " seconds" . PHP_EOL);
83-
}
81+
print($data['runs'] . " in " . number_format($elapsed, 3) . " seconds" . PHP_EOL);
8482
}
8583

8684
file_put_contents($statsfile, json_encode((object) $stats, JSON_PRETTY_PRINT));

tctree.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @file
7+
* Display a TC tree (only TC names and heirarchy).
8+
*/
9+
10+
chdir(realpath(__DIR__));
11+
12+
define('TREASURECLASSEX', json_decode(file_get_contents('json/treasureclassex.json'), TRUE));
13+
14+
if ($argc < 2) {
15+
echo "Usage: php tctree.php [TC name]\n";
16+
exit(1);
17+
}
18+
19+
function print_tc_tree($tc_name, $indent = 0) {
20+
if (!isset(TREASURECLASSEX[$tc_name])) {
21+
return;
22+
}
23+
24+
$tc = TREASURECLASSEX[$tc_name];
25+
26+
if ($tc['Picks'] > 0) {
27+
for ($c = 0; $c < 10; $c++) {
28+
$name = $tc['Item' . $c] ?? '';
29+
$prob = $tc['Prob' . $c] ?? 0;
30+
31+
if ($name && $prob > 0) {
32+
echo str_repeat("\t", $indent) . "$name @ $prob\n";
33+
print_tc_tree($name, $indent + 1);
34+
}
35+
}
36+
}
37+
elseif ($tc['Picks'] < 0) {
38+
$picks = -$tc['Picks'];
39+
40+
for ($c = 0; $c < 10; $c++) {
41+
$name = $tc['Item' . $c] ?? '';
42+
$prob = $tc['Prob' . $c] ?? 0;
43+
44+
if ($name && $prob > 0) {
45+
$sub = min($picks, $prob);
46+
47+
if ($sub < 0) {
48+
break;
49+
}
50+
51+
echo str_repeat("\t", $indent) . "$name @ $prob\n";
52+
print_tc_tree($name, $indent + 1);
53+
$picks -= $sub;
54+
}
55+
}
56+
}
57+
}
58+
59+
print($argv[1]);
60+
print_tc_tree($argv[1], 1);

0 commit comments

Comments
 (0)