|
|
@@ -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) {
|
|
|
|