Skip to content

Commit

Permalink
minimize score option
Browse files Browse the repository at this point in the history
  • Loading branch information
EFHIII committed Mar 14, 2024
1 parent 62baf3a commit 176a3dc
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
6 changes: 5 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
<div id="cardsInHand"></div>
<span class='limitText'><span id='handLimit'>0</span>/8</span><br>
<div class="toggleArea" style="margin-bottom: 1em">
<div id="togglePlasma" class="handLevel">
<div id="toggleMinimize" class="handLevel">
<span id="toggleMinimizeBtn" class="lvlBtn" onclick="toggleMinimize()">&nbsp;</span>
<span class="handName">Minimize Score</span>
</div>
<div id="toggleTheFlint" class="handLevel">
<span id="toggleTheFintBtn" class="lvlBtn" onclick="toggleTheFlint()">&nbsp;</span>
<span class="handName">The Flint</span>
</div>
Expand Down
51 changes: 43 additions & 8 deletions manageWorkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let optimizeJokers = true;
let optimizeCards = true;
const toggleJokerDiv = document.getElementById('toggleJokerBtn');
const toggleCardDiv = document.getElementById('toggleCardBtn');
const minimizeDiv = document.getElementById('toggleMinimizeBtn');
const toggleTheFlintDiv = document.getElementById('toggleTheFintBtn');
const togglePlasmaDiv = document.getElementById('togglePlasmaBtn');
const toggleObservatoryDiv = document.getElementById('toggleObservatoryBtn');
Expand All @@ -30,6 +31,18 @@ let observatory = false;
let minimize = false;
let optimizeMode = 0;

function toggleMinimize() {
minimize = !minimize;
redrawPlayfield();

if(minimize) {
minimizeDiv.innerText = 'X';
}
else {
minimizeDiv.innerHTML = '&nbsp;';
}
}

function toggleJoker() {
optimizeJokers = !optimizeJokers;
if(optimizeJokers) {
Expand Down Expand Up @@ -225,14 +238,36 @@ function workerMessage(msg) {
tmpBestLowHand = msg.data[6];
tmpTypeOfHand = msg.data[7];
}
if(msg.data[1][1] > bestScore[1] || (msg.data[1][1] === bestScore[1] && msg.data[1][0] > bestScore[0])) {
bestScore = msg.data[1];
tmpBestJokers = msg.data[2];
tmpBestCards = msg.data[3];
tmpBestCardsInHand = msg.data[4];
tmpBestHighHand = msg.data[5];
tmpBestLowHand = msg.data[6];
tmpTypeOfHand = msg.data[7];
if(minimize) {
if(msg.data[1][1] > bestScore[1] || (msg.data[1][1] === bestScore[1] && msg.data[1][0] > bestScore[0])) {
bestScore = msg.data[1];
tmpBestJokers = msg.data[2];
tmpBestCards = msg.data[3];
tmpBestCardsInHand = msg.data[4];
tmpBestHighHand = msg.data[5];
tmpBestLowHand = msg.data[6];
tmpTypeOfHand = msg.data[7];
}
else if(tmpBestCards.length === 0 && msg.data[3].length > 0) {
bestScore = msg.data[1];
tmpBestJokers = msg.data[2];
tmpBestCards = msg.data[3];
tmpBestCardsInHand = msg.data[4];
tmpBestHighHand = msg.data[5];
tmpBestLowHand = msg.data[6];
tmpTypeOfHand = msg.data[7];
}
}
else {
if(msg.data[1][1] > bestScore[1] || (msg.data[1][1] === bestScore[1] && msg.data[1][0] > bestScore[0])) {
bestScore = msg.data[1];
tmpBestJokers = msg.data[2];
tmpBestCards = msg.data[3];
tmpBestCardsInHand = msg.data[4];
tmpBestHighHand = msg.data[5];
tmpBestLowHand = msg.data[6];
tmpTypeOfHand = msg.data[7];
}
}
if(tasks === 0) {
bestJokers = tmpBestJokers.map(a => {
Expand Down
14 changes: 10 additions & 4 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function run(jokers = [[]]) {
switch (optimizeMode) {
default:
if(minimize) {
thisScore = thisHand.simulateWorstHand();
thisScore = thisHand.simulateBestHand();
if(!bestScore) {
bestScore = thisScore;
bestCards = thisHand.cards;
Expand All @@ -168,10 +168,16 @@ function run(jokers = [[]]) {
bestJokers = jokers[j];
bestCardsInHand = thisHand.cardsInHand;
}
else if(bestCards.length === 0 && thisHand.cards.length > 0) {
bestScore = thisScore;
bestCards = thisHand.cards;
bestJokers = jokers[j];
bestCardsInHand = thisHand.cardsInHand;
}

}
else {
thisScore = thisHand.simulateBestHand();
thisScore = thisHand.simulateWorstHand();

if(!bestScore) {
bestScore = thisScore;
Expand All @@ -198,7 +204,7 @@ function run(jokers = [[]]) {
switch (optimizeMode) {
default:
if(minimize) {
thisScore = thisHand.simulateWorstHand();
thisScore = thisHand.simulateBestHand();
if(!bestScore) {
bestScore = thisScore;
bestJokers = jokers[j];
Expand All @@ -209,7 +215,7 @@ function run(jokers = [[]]) {
}
}
else {
thisScore = thisHand.simulateBestHand();
thisScore = thisHand.simulateWorstHand();

if(!bestScore) {
bestScore = thisScore;
Expand Down

0 comments on commit 176a3dc

Please sign in to comment.