Compare commits

...

10 Commits

Author SHA1 Message Date
thayol 7b47977598 Removed unused compression 2021-07-19 02:25:20 +02:00
thayol 1c22d47840 Factored out greedy check 2021-07-08 21:30:30 +02:00
thayol fa6e0806f1 Fixed wrong shorthands 2021-06-30 05:00:31 +02:00
thayol 8934c35cc2 Include initial state of auto-draw. 2021-06-29 22:40:49 +02:00
thayol 1265205ded Fixed double-declaration 2021-06-28 00:24:31 +02:00
thayol 6f323c46e2 Removed the unnecessary double-loading 2021-06-28 00:21:42 +02:00
thayol 7181753689 Adjusted defaults 2021-06-25 21:14:14 +02:00
thayol aa0a23e702 Optimized defaults 2021-06-24 01:26:57 +02:00
thayol 1ef838ff88 Changed to sensible defaults 2021-06-24 00:57:34 +02:00
thayol 80ad22cbb6 Fix minimum points application 2021-06-24 00:38:37 +02:00
2 changed files with 28 additions and 37 deletions
+25 -34
View File
@@ -12,8 +12,9 @@ var sameNumberFixed = false; // if this is true, "sameNumberExtra" will be const
var seriesExtra = 0; // extra points given for series var seriesExtra = 0; // extra points given for series
var seriesFixed = false; // if this is true, "seriesExtra" will be constant instead of additive var seriesFixed = false; // if this is true, "seriesExtra" will be constant instead of additive
var sameColorExtra = 4; // extra points given for sets of the same color if they are in a series // set the "sameColor" to non-fixed and the extra to 4 to reflect the official wiki (for some reason the live game does not work like that)
var sameColorFixed = false; // if this is true, "sameColorExtra" will be constant instead of additive var sameColorExtra = 10; // extra points given for sets of the same color if they are in a series
var sameColorFixed = true; // if this is true, "sameColorExtra" will be constant instead of additive
var autoDraw = false; // whether the script should automatically draw on start and on discard var autoDraw = false; // whether the script should automatically draw on start and on discard
var autoRecommend = true; // whether the script should automatically recommend on change var autoRecommend = true; // whether the script should automatically recommend on change
@@ -22,14 +23,10 @@ var allowRedraw = true; // if redrawing a card by hand is allowed (sometimes the
var defaultDepth = 2; // the default depth of search (0 means single-level, 1 means one extra level, 2 means two extra levels) var defaultDepth = 2; // the default depth of search (0 means single-level, 1 means one extra level, 2 means two extra levels)
var minimumRecommendations = 3; // the minimum amount of recommended next steps the script should strive for var minimumRecommendations = -1; // the minimum amount of recommended next steps the script should strive for
var minimumPoints = 4; // the minimum points the script should consider cashing out var minimumPoints = 2; // the minimum points the script should consider cashing out
var preferCashOut = true; // whether the default option should be cashing out even if there is a chance of getting a better opportunity var preferCashOut = true; // whether the default option should be cashing out even if there is a chance of getting a better opportunity
var greedyAlgorithm = false; // whether the greedy algorithm should be used (never cash out, always discard for better)
// fixups (feel free to delete if not needed)
sameColorFixed = true; // for some reason the live game does not work like the wiki says
sameColorExtra = 10; // it gives 100 for 1-2-3* too
/* END OF CONFIG */ /* END OF CONFIG */
@@ -45,8 +42,10 @@ var deckElement = document.getElementById('deck');
var handElement = document.getElementById('hand'); var handElement = document.getElementById('hand');
var recommendElement = document.getElementById('result'); var recommendElement = document.getElementById('result');
var pointsElement = document.getElementById('points'); var pointsElement = document.getElementById('points');
var autoDrawElement = document.getElementById('autoDrawToggle');
reset(); reset();
toggleAutoDraw(autoDrawElement);
function toggleAutoDraw(element) { function toggleAutoDraw(element) {
if (element.checked) { if (element.checked) {
@@ -245,7 +244,6 @@ function drawCard(cardId, thisHand = null, thisDeck = null) {
} }
function recommend() { function recommend() {
var cardCount = Object.keys(allCards).length
recommendOfDepth(defaultDepth); recommendOfDepth(defaultDepth);
updateUI(true); updateUI(true);
} }
@@ -373,7 +371,7 @@ function getPatterns(thisHand = null, thisMinimumPoints = null) {
let points = Object.values(patterns).map(pattern => pattern.points); let points = Object.values(patterns).map(pattern => pattern.points);
let maxPoints = Math.max(...points); let maxPoints = Math.max(...points);
if (maxPoints < minimumPoints) { if (maxPoints < thisMinimumPoints) {
return []; return [];
} }
@@ -401,7 +399,6 @@ function recommendOfDepth(depth = 0) {
let current = getHandPoints(); let current = getHandPoints();
if (current.points > 0) { if (current.points > 0) {
let choice = { let choice = {
points: current,
chance: 1, chance: 1,
points: current.points, points: current.points,
pattern: current.pattern, pattern: current.pattern,
@@ -477,9 +474,17 @@ function recommendThrowaway(depth = 0, thisHand = null, thisDeck = null, chance
for (let choice of choices) { for (let choice of choices) {
let result = getHandPoints(hands[choice.index]); let result = getHandPoints(hands[choice.index]);
if (!greedyAlgorithm) {
result.points = cashOut(hands[choice.index], result, false);
if (hands[choice.index].length < handSize) {
// create new hands and push all possible permutations
// might need a separate loop
}
}
if (result.points > 0) { if (result.points > 0) {
// choice.points = result.points; choice.points = result.points;
choice.points = cashOut(hands[choice.index], result, false);
choice.pattern = result.pattern; choice.pattern = result.pattern;
choice.cards = result.cards; choice.cards = result.cards;
@@ -488,27 +493,13 @@ function recommendThrowaway(depth = 0, thisHand = null, thisDeck = null, chance
thisChance = chance * (1 / thisDeck.length); thisChance = chance * (1 / thisDeck.length);
} }
choice.chance = thisChance choice.chance = thisChance;
choice.cardSignature = choice.cards.join(" ");
recommendations.push(choice); recommendations.push(choice);
} }
} }
// compress recommendations
if (choices.length > 0) {
// recommendations = [...new Set(recommendations)];
// only allow one recommendation per pattern
let newRecs = [];
for (let rec of recommendations) {
if (!newRecs.map(newRec => newRec.pattern).includes(rec.pattern)) {
newRecs.push(rec);
}
}
recommendations = newRecs;
}
for (let choice of choices) { for (let choice of choices) {
if (!choice.points) { if (!choice.points) {
choice.points = 0; choice.points = 0;
@@ -518,7 +509,7 @@ function recommendThrowaway(depth = 0, thisHand = null, thisDeck = null, chance
// recursive // recursive
for (let choice of choices) { for (let choice of choices) {
if (depth > 0 && recommendations.length < minimumRecommendations) { if (depth > 0 && (minimumRecommendations < 0 || recommendations.length < minimumRecommendations)) {
recommendThrowaway(depth - 1, hands[choice.index], decks[choice.index], choice.chance, choice.burnedCard, choice.points); recommendThrowaway(depth - 1, hands[choice.index], decks[choice.index], choice.chance, choice.burnedCard, choice.points);
} }
} }
@@ -563,9 +554,9 @@ function updateUI(skipAuto = false) {
if (hand.length >= handSize) { if (hand.length >= handSize) {
recommend(); recommend();
} }
else { // else {
recommendations = []; // recommendations = [];
} // }
} }
recommendationArray = []; recommendationArray = [];
for (let recommendation of recommendations) { for (let recommendation of recommendations) {
+2 -2
View File
@@ -65,7 +65,7 @@ main-container {
main-panel { main-panel {
display: block; display: block;
max-width: 550px; max-width: 550px;
margin: 10px auto 0 auto; margin: 10px auto 0;
padding: 20px; padding: 20px;
background-color: var(--surface); background-color: var(--surface);
border-radius: 5px; border-radius: 5px;
@@ -73,7 +73,7 @@ main-panel {
panel-title { panel-title {
display: block; display: block;
margin: 0 0 0.67em 0; margin: 0 0 0.67em;
font-size: 2em; font-size: 2em;
font-weight: bold; font-weight: bold;
} }