Fixed last hand rendering

This commit is contained in:
2021-06-23 21:02:33 +02:00
parent 17fb1253b3
commit c9ffa273a4
+10 -17
View File
@@ -44,6 +44,7 @@ function idToCard(cardId) {
}
function cardToElement(card, forDeck = false, drawn = false) {
if (card) {
var element = document.createElement("okey-card");
element.innerHTML = card.number.toString();
@@ -81,6 +82,9 @@ function cardToElement(card, forDeck = false, drawn = false) {
return element.outerHTML;
}
return "";
}
function isHandFull(thisHand = null) {
if (thisHand == null) {
thisHand = hand;
@@ -139,7 +143,7 @@ function discard(cardId, thisHand = null, update = true) {
}
}
function cashOut(thisHand = null) {
function cashOut(thisHand = null, forceRefresh = true) {
if (recommendations.length > 0) {
let handGiven = true;
if (thisHand == null) {
@@ -147,11 +151,7 @@ function cashOut(thisHand = null) {
handGiven = false;
}
// console.log("Recommendation: ");
// console.log(recommendations[0]);
if (recommendations[0].burnedCard) {
// console.log("Discarding: " + recommendations[0].burnedCard);
discard(recommendations[0].burnedCard, thisHand, false);
}
else if (recommendations[0].pattern && recommendations[0].cards) {
@@ -163,22 +163,17 @@ function cashOut(thisHand = null) {
recommendations = [];
for (let cardId of localCards) {
// console.log("Redeeming: " + cardId);
discard(cardId, thisHand, false);
}
globalPoints += localPoints;
// console.log("Cashed out: " + (localPoints * pointsMultiplier) + " points");
}
}
if (!handGiven) {
if (forceRefresh) {
updateUI();
}
}
else {
// console.log("Nothing to do.");
}
}
function drawCard(cardId, thisHand = null, thisDeck = null) {
let handGiven = true;
@@ -239,9 +234,11 @@ function getPatterns(thisHand = null) {
// fill them with the current hand's cards
for (let cardId of thisHand) {
let card = idToCard(cardId);
if (card) {
cardColorsByNumbers[card.number - 1].push(card.color);
cardsByNumbers[card.number - 1].push(card);
}
}
// check if there are "color" amount of any
for (let i = 0; i < maxNumber; i++) {
@@ -458,10 +455,6 @@ function recommendThrowaway(depth = 0, thisHand = null, thisDeck = null, chance
}
return place;
});
// let fewer = recommendations.filter(choice => choice.chance >= 0.01);
// if (fewer.length > 0) {
// recommendations = fewer;
// }
}
}
@@ -486,7 +479,7 @@ function updateUI(skipAuto = false) {
recommend();
}
else {
// recommendations = [];
recommendations = [];
}
}
recommendationArray = [];