//all
var sPaint = "";
var sSuits = ["Clubs", "Diamonds", "Spades", "Hearts"];
var sURL = "";
var boolDebugReadable = true;
var boolBotProcessing = false;
var vButtonArray = [];
var iRoundReplay = 0;
var iTurnReplay = 0;
//home
var boolListenToKeystrokes = false;
var sDirection = "";
var boolBroken = false;
var sGame = "";
var boolJackDiamondsRule = false;
var iLegalPlaysArray = [];
var iMoonStatus = -1;
var iOriginal13Array = [];
var iPassed3Array = [];
var iReceived3Array = [];
var iRound = 0;
var iStep = 0;
var iTurn = 1;
var sSuitToAdd = "Clubs";
var vCommandArray = [];
var boolMobile = false;
var iUnownedCountTotal = 39;
var vLogicExplainArray = [];
//round
var iRoundCardArray = [[], [], [], []];
var iRoundGoesArray = [[], [], [], []];
var iRoundWinnerArray = [];
var sRoundSuitLedArray = [];
//card
var sCardNumberArray = [];
var iCardOwnerArray = [];
var iCardPlayedByArray = [];
var sCardSuitArray = [];
var sCardWhyNotLegalForThisTurnArray = [];
//team
var iTeamCardsDontHaveArray = [];
var boolTeamSuitOutArray = [[], [], [], []];
var iTeamSuitQtyPlayedArray = [[], [], [], []];
var iTeamPossibleCardsArray = [[], [], [], []];
var iTeamDebugRenegeRoundArray = [[], [], [], []]; //[iTeam][iSuit], (only populate that particular value with round number if it is -1), we only care about the first time
var boolTeamKnowAllArray = [];
var iTeamPointsTakenArray = [];
var iTeamUnknownCountArray = [];
function AddRemoveClass(sTempElementID,sTempClassName,boolAdd) {try {
var eTempElement = document.getElementById(sTempElementID);
if (boolAdd) {
//toggle if it's not there
if (eTempElement.classList.contains(sTempClassName)) {
//it's there, do nothing
} else {
eTempElement.classList.toggle(sTempClassName)
}
} else {
//toggle if it is there
if (eTempElement.classList.contains(sTempClassName)) {
eTempElement.classList.toggle(sTempClassName)
}
}
}catch(err) {DisplayError("AddRemoveClass",err)}}
function AddTo13(iCardNum) {try {
if (iCardNum === 99) return
if (IsThisCardInThisArray(iCardNum,iOriginal13Array)) {
return;
};
vCommandArray.push(["AddTo13",iCardNum])
iOriginal13Array.push(iCardNum)
iOriginal13Array.sort(function(a, b){return a-b});
iCardOwnerArray[iCardNum] = 3;
PaintIt();
}catch(err) {DisplayError("AddTo13",err)}}
function AddToPassing3(iCardNum) {try {
if (iCardOwnerArray[iCardNum] != 3) {
return
}
if (IsThisCardInThisArray(iCardNum, iPassed3Array)) {
return;
};
vCommandArray.push(["AddToPassing3",iCardNum])
iPassed3Array.push(iCardNum)
iPassed3Array.sort(function(a, b){return a-b});
if (sDirection === "left") {
iCardOwnerArray[iCardNum] = 0;
} else if (sDirection === "right") {
iCardOwnerArray[iCardNum] = 2;
} else if (sDirection === "across") {
iCardOwnerArray[iCardNum] = 1;
} else {
return;
}
PaintIt();
}catch(err) {DisplayError("AddToPassing3",err)}}
function AddToReceiving3(iCardNum) {try {
if (iCardOwnerArray[iCardNum] === 3) {
alert("not allowing add to receiving 3 because owner of card " + iCardNum + " is you.")
return
}
if (IsThisCardInThisArray(iCardNum, iReceived3Array)) {
return;
};
vCommandArray.push(["AddToReceiving3",iCardNum])
iReceived3Array.push(iCardNum)
iReceived3Array.sort(function(a, b){return a-b});
iCardOwnerArray[iCardNum] = 3;
PaintIt();
}catch(err) {DisplayError("AddToReceiving3",err)}}
function AfterCardPlayed() {try {
if (iRound > 12) {
FinishGame();
return;
}
var iSmartAgentMadeXChanges = 0;
var iMaxRunTimes = 20;
for (var iRunSmartAgentCount = 1; iRunSmartAgentCount <= iMaxRunTimes; iRunSmartAgentCount++) {
iSmartAgentMadeXChanges = SmartAgent();
if (iRunSmartAgentCount === iMaxRunTimes) {
alert("The function 'AfterCardPlayed' ran 'SmartAgent' max times");
return;
}
if (iSmartAgentMadeXChanges === 0) {
PopulateLegalPlays();
PopulatePossibleCardsAndUnownedCounts()
sSuitToAdd = SmartGetSuit();
return;
}
}
}catch(err) {DisplayError("AfterCardPlayed",err)}}
function AnimateLastCardOfRound(iTempRound) {try {
if (boolBotProcessing) {
PaintIt('')
return;
}
var iWinner = iRoundWinnerArray[iTempRound]
var sElementArray = ["PlayedCard0","PlayedCard1","PlayedCard2","PlayedCard3"];
//put the last card on the screen.
document.getElementById('PlayedCard3').innerHTML = GetCardImageHTML(iRoundCardArray[iTempRound][3],"","")
document.getElementById('PlayedCard3').style.display = 'block'
document.getElementById('Step3LegalCards').style.display = 'none' // hide it so they don't click while animating
AnimateTheseElements(sElementArray,"OC" + iWinner + "18",50,80,10)
}catch(err) {DisplayError("AnimateLastCardOfRound",err)}}
function AnimateTheseElements(sElementNameArray, sFinishName, iPauseSteps, iNumberOfSteps, iMilliseconds) {try {
if (boolBotProcessing) {
return;
}
var iItemLoop = 0;
var iFinishTop = 0;
var iFinishLeft = 0;
var iIterationsDone = 0;
var iTopArray = [];
var iTopAdjArray = [];
var iLeftArray = [];
var iLeftAdjArray = [];
//get finish location
var vPos = document.getElementById(sFinishName).getBoundingClientRect();
iFinishTop = vPos.top;
iFinishLeft = vPos.left;
//populate Arrays
for (iItemLoop = 0; iItemLoop < sElementNameArray.length; iItemLoop++) {
//current position
vPos = document.getElementById(sElementNameArray[iItemLoop]).getBoundingClientRect();
iTopArray[iItemLoop] = vPos.top;
iLeftArray[iItemLoop] = vPos.left;
iTopAdjArray[iItemLoop] = ((iFinishTop - vPos.top) / (iNumberOfSteps - iPauseSteps));
iLeftAdjArray[iItemLoop] = ((iFinishLeft - vPos.left) / (iNumberOfSteps - iPauseSteps));
}
//move 'em
var vInterval = setInterval(MoveALittle, iMilliseconds);
function MoveALittle() {
if (iIterationsDone > iPauseSteps) {
for (iItemLoop = 0; iItemLoop < sElementNameArray.length; iItemLoop++) {
var vElement = document.getElementById(sElementNameArray[iItemLoop]);
iTopArray[iItemLoop] = iTopArray[iItemLoop] + iTopAdjArray[iItemLoop]
iLeftArray[iItemLoop] = iLeftArray[iItemLoop] + iLeftAdjArray[iItemLoop]
vElement.style.position = 'absolute';
vElement.style.top = Math.round(iTopArray[iItemLoop]) + "px";
vElement.style.left = Math.round(iLeftArray[iItemLoop]) + "px";
}
} else {
//do nothing we're skipping the pause steps number of times
}
iIterationsDone++
if (iIterationsDone >= iNumberOfSteps) {
clearInterval(vInterval);
PaintIt('')
}
}
}catch(err) {DisplayError("AnimateTheseElements",err)}}
function AssignDirectionForHearts(sDir) {try {
vCommandArray.push(["AssignDirectionForHearts",sDir])
sDirection = sDir;
PaintIt();
}catch(err) {DisplayError("AssignDirectionForHearts",err)}}
function AssignRoundOrder(iGoesFirst,iRoundNum) {try {
if (iRoundNum > 12) {
return;
}
if (iGoesFirst === 0) {
iRoundGoesArray[iRoundNum][0] = 0
iRoundGoesArray[iRoundNum][1] = 1
iRoundGoesArray[iRoundNum][2] = 2
iRoundGoesArray[iRoundNum][3] = 3
} else if (iGoesFirst === 1) {
iRoundGoesArray[iRoundNum][0] = 1
iRoundGoesArray[iRoundNum][1] = 2
iRoundGoesArray[iRoundNum][2] = 3
iRoundGoesArray[iRoundNum][3] = 0
} else if (iGoesFirst === 2) {
iRoundGoesArray[iRoundNum][0] = 2
iRoundGoesArray[iRoundNum][1] = 3
iRoundGoesArray[iRoundNum][2] = 0
iRoundGoesArray[iRoundNum][3] = 1
} else {
iRoundGoesArray[iRoundNum][0] = 3
iRoundGoesArray[iRoundNum][1] = 0
iRoundGoesArray[iRoundNum][2] = 1
iRoundGoesArray[iRoundNum][3] = 2
}
}catch(err) {DisplayError("AssignRoundOrder",err)}}
function AssignTeamOutOfSuit(iTempTeam,iTempRound,iTempSuit,boolTempRenege,sTempReason) {try {
if (boolTempRenege) {
if (iTeamDebugRenegeRoundArray[iTempTeam][iTempSuit] >= 0) {
//it's already set, don't update it
} else {
iTeamDebugRenegeRoundArray[iTempTeam][iTempSuit] = iTempRound;
}
}
if (boolTeamSuitOutArray[iTempTeam][iTempSuit]) {
//it's already set, don't update it
} else {
boolTeamSuitOutArray[iTempTeam][iTempSuit] = true;
vLogicExplainArray.push([iTempTeam,iTempRound,sTempReason])
}
}catch(err) {DisplayError("AssignTeamOutOfSuit",err)}}
function AssignTeamPointsTaken() {try {
var iThisRoundPoints = 0;
var iWinner = -1;
var iTempRound = 0;
var iTempTurn = 0;
var iTempTeam = 0;
//first reset them
for (iTempTeam = 0; iTempTeam < 4; iTempTeam++) {
iTeamPointsTakenArray[iTempTeam] = 0;
}
for (iTempRound = 0; iTempRound < 13; iTempRound++) {
iThisRoundPoints = 0;
//get who goes first next round so you can easily determine winning team of this round
iWinner = iRoundWinnerArray[iTempRound];
if (iWinner >= 0) {
for (iTempTurn = 0; iTempTurn < 4; iTempTurn++) {
iThisRoundPoints = iThisRoundPoints + HowManyPointsIsThisCard(iRoundCardArray[iTempRound][iTempTurn]);
}
if (sGame === "Spades") {
iThisRoundPoints = 1
}
iTeamPointsTakenArray[iWinner] = iTeamPointsTakenArray[iWinner] + iThisRoundPoints;
}
}
}catch(err) {DisplayError("AssignTeamPointsTaken",err)}}
function AssignWhoOwns2DuringStep0(iTeam) {try {
vCommandArray.push(["AssignWhoOwns2DuringStep0",iTeam])
iCardOwnerArray[0] = iTeam;
if (sDirection === "none") {
AssignRoundOrder(iCardOwnerArray[0],0)
iStep = 3
PlayCardSL(0)
//don't paint it here. you need to paint in playcardsl because that is what undo will call, and it needs to paint after each card play
} else {
iStep = 1
PaintIt();
}
}catch(err) {DisplayError("AssignWhoOwns2DuringStep0",err)}}
function AssignWhoOwns2DuringStep2(iTeam) {try {
vCommandArray.push(["AssignWhoOwns2DuringStep2",iTeam])
iCardOwnerArray[0] = iTeam;
AssignRoundOrder(iCardOwnerArray[0],0)
iStep = 3;
PlayCardSL(0)
//don't paint it here. you need to paint in playcardsl because that is what undo will call, and it needs to paint after each card play
}catch(err) {DisplayError("AssignWhoOwns2DuringStep2",err)}}
function ChangeSuitToAdd(sTempSuit) {try {
var iTempSuit = 0;
sSuitToAdd = sTempSuit
for (iTempSuit = 0; iTempSuit < 4; iTempSuit++) {
document.getElementById("Suit" + sSuits[iTempSuit]).style.opacity = 0.2;
}
document.getElementById("Suit" + sTempSuit).style.opacity = 1.0;
PaintIt(sURL);
}catch(err) {DisplayError("ChangeSuitToAdd",err)}}
function CheckEachSuitForAllPlayed() {try {
//this check is the most logical to the player, so we want it to be the first reason a suit is marked out for teams
//it loops thru all 4 suits and simply marks all teams out of that suit if all have been played
var iTeamLoop = 0;
var iSuitLoop = 0;
var iCardLoop = 0;
var iTempCardsArray = [];
var sTempSuit = "";
var iTempCard = 0;
var iTempOwnerOfThisCard = -1;
var iCountChanges = 0;
var boolAllHaveBeenPlayed = true;
for (iSuitLoop = 0; iSuitLoop < 4; iSuitLoop++) {
boolAllHaveBeenPlayed = true;
sTempSuit = sSuits[iSuitLoop];
iTempCardsArray = GetArrayOfCardsOfThisSuit(sTempSuit)
for (iCardLoop = 0; iCardLoop < iTempCardsArray.length; iCardLoop++) {
iTempCard = iTempCardsArray[iCardLoop]
if (iCardOwnerArray[iTempCard] != 5) {
boolAllHaveBeenPlayed = false;
}
}
if (boolAllHaveBeenPlayed) {
//now you know if they've all been played, if so, mark all teams out
for (iTeamLoop = 0; iTeamLoop < 4; iTeamLoop++) {
if (boolTeamSuitOutArray[iTeamLoop][iSuitLoop]) {
//already
} else {
AssignTeamOutOfSuit(iTeamLoop,ReturnRoundOfPreviousTurn(),iSuitLoop,false,"Out of " + sSuits[iSuitLoop] + " because they have all been played")
iCountChanges++
}
}
}
}
return iCountChanges;
}catch(err) {DisplayError("CheckEachSuitForAllPlayed",err)}}
function CheckForImpossiblePlay() {try {
//for each team (x) compare if iTeamUnknownCountArray[x] > iTeamPossibleCardsArray[x].length
//if so, alert so they can undo their last move(s)
//this is called at the end of paintit()
if (iRoundCardArray[0][0] === -1) {
return false;
}
var iTeamLoop = 0;
for (iTeamLoop = 0; iTeamLoop < 4; iTeamLoop++) {
if (iTeamUnknownCountArray[iTeamLoop] < 0) {
return true;
} else if (iTeamUnknownCountArray[iTeamLoop] > iTeamPossibleCardsArray[iTeamLoop].length) {
return true;
}
}
return false;
}catch(err) {DisplayError("CheckForImpossiblePlay",err)}}
function CheckForKnowAllForEveryTeam() {try {
var iChangeCount = 0;
for (var iTeam = 0; iTeam <= 2; iTeam++) {//notme, it's always true
if (HowManyValuesWeKnowForThisTeam(iTeam) === HowManyCardsForThisTeam(iTeam)) {
if (boolTeamKnowAllArray[iTeam]) {
//already
} else {
boolTeamKnowAllArray[iTeam] = true;
iChangeCount++;
vLogicExplainArray.push([iTeam,ReturnRoundOfPreviousTurn(),"We now know all cards for this hand"])
}
}
}
return iChangeCount;
}catch(err) {DisplayError("CheckForKnowAllForEveryTeam",err)}}
function CheckForOnlyOnePossibleTeamOwner() {try {
var iTempArray = [];
var iChangeCount = 0;
for (var iCard = 0; iCard <= 51; iCard++) {
if (iCardOwnerArray[iCard] != -1) {
//we already know who owns, no need to do anything for this
} else {
iTempArray = [];
for (var iTeam = 0; iTeam <= 2; iTeam++) { //not me
if (boolTeamKnowAllArray[iTeam]) {
//can't be this team, we only act on unknown cards
} else if (boolTeamSuitOutArray[iTeam][GetSuitIndex(sCardSuitArray[iCard])]) {
//can't be this team, they are out of this suit
} else {
//this team can possibly own this card
iTempArray.push(iTeam)
}
}
//if only one team in temparray, set owner of this card to that team (if not already)
if (iTempArray.length === 1) {
iCardOwnerArray[iCard] = iTempArray[0];
iChangeCount++;
vLogicExplainArray.push([iTempArray[0],ReturnRoundOfPreviousTurn(),"Has the " + sCardNumberArray[iCard] + " of " + sCardSuitArray[iCard] + " because the other two hands cannot have it"])
}
}
}
return iChangeCount;
}catch(err) {DisplayError("CheckForOnlyOnePossibleTeamOwner",err)}}
function CheckIfCurrentGameIsSaved() {try {
var sCurrentCookie = GetCookieValue("RebuildGameCommands");
var sCurrentGame = JSON.stringify(vCommandArray);
if (sCurrentCookie === sCurrentGame) {
return true;
}
return false;
}catch(err) {DisplayError("CheckIfCurrentGameIsSaved",err)}}
function CheckIfSuitOutIsSetForThisTeamAtSpecificTime(iThisTeam,sThisSuit,iTempRound,iTempTurn) {try {
//declare variables
var iThisSuitLastPlayedWhen = 0;
var boolOutIRL = false;
var boolEverPlayedThisSuit = false;
var boolLastPlayedThisSuitInTheFuture = false;
boolOutIRL = boolTeamSuitOutArray[iThisTeam][GetSuitIndex(sThisSuit)];
if (boolOutIRL) { //A
iThisSuitLastPlayedWhen = WhenIsTheLastTimeIRLThisTeamPlayedThisSuit(iThisTeam,sThisSuit);
if (iThisSuitLastPlayedWhen === -1) {
boolEverPlayedThisSuit = false;
} else {
boolEverPlayedThisSuit = true;
}
if (boolEverPlayedThisSuit) { //B
if (iThisSuitLastPlayedWhen >= TurnCount(iTempRound,iTempTurn)) {
boolLastPlayedThisSuitInTheFuture = true;//future includes this very next card (current turn)
} else {
boolLastPlayedThisSuitInTheFuture = false;
}
if (boolLastPlayedThisSuitInTheFuture) { //C
//they are out in real life, they have played this suit, and the last time they played it >= now
//which means they are not out now
return false;
} else {
//they are out in real life, they have played this suit, and the last time they played it < now
//which means they are out now
return true;
}
} else {
//they are out in real life, and they never played this suit, so they're out now
return true;
}
} else {
//they are not out in real life, so they are not out now
return false;
}
}catch(err) {DisplayError("CheckIfSuitOutIsSetForThisTeamAtSpecificTime",err)}}
function CheckIfThisCardIsHiLoOrEmptyStringAtThisMomentInTime(iTempCard, iTempTeam, iTempRound, iTempTurn) {try {
//this function should return 'red' if high, 'green' if low, and '' if neither
//calculate the green and red cards for me only
var iLowTemp = 200
var iHighTemp = -1
var iCardLoopTest = 0;
var sTempSuit = sCardSuitArray[iTempCard];
var boolPlayedInPast = false;
for (iCardLoopTest = 0; iCardLoopTest < 52; iCardLoopTest++) {
if (sCardSuitArray[iCardLoopTest] === sTempSuit) {
if (iCardOwnerArray[iCardLoopTest] != iTempTeam) {
if (iCardPlayedByArray[iCardLoopTest] != iTempTeam) {
boolPlayedInPast = WasThisCardPlayedBeforeThisMomentInTime(iCardLoopTest,iTempRound,iTempTurn);
if (boolPlayedInPast) {
//this card was played in the past, don't compare against it
} else {
if (iCardLoopTest < iLowTemp) {
iLowTemp = iCardLoopTest
}
if (iCardLoopTest > iHighTemp) {
iHighTemp = iCardLoopTest
}
}
}
}
}
}
if ((iTempCard >= iHighTemp) || (iHighTemp === -1)) {
return "red";
} else if (iTempCard <= iLowTemp) {
return "green";
} else {
return "";
}
}catch(err) {DisplayError("CheckIfThisCardIsHiLoOrEmptyStringAtThisMomentInTime",err)}}
function CheckTeamsThatKnowAllOutOfSuits() {try {
//for teams that we know all, loop through all 4 suits and if they don't own one, set that suit out
var iTeamLoop = 0;
var iSuitLoop = 0;
var iTempCardsArray = [];
var sTempSuit = "";
var iTempLoop = 0;
var iTempCard = 0;
var iTempOwnerOfThisCard = -1;
var boolOwnsOneOfThisSuit = false;
var iCountChanges = 0;
for (iTeamLoop = 0; iTeamLoop < 4; iTeamLoop++) {
if (boolTeamKnowAllArray[iTeamLoop]) {
//this test is only valid for teams if we know all of their cards
for (iSuitLoop = 0; iSuitLoop < 4; iSuitLoop++) {
sTempSuit = sSuits[iSuitLoop];
boolOwnsOneOfThisSuit = false;
if (boolTeamSuitOutArray[iTeamLoop][iSuitLoop]) {
//they're already marked out, no need to run this test
} else {
iTempCardsArray = GetArrayOfCardsOfThisSuit(sTempSuit)
for (iTempLoop = 0; iTempLoop < iTempCardsArray.length; iTempLoop++) {
iTempCard = iTempCardsArray[iTempLoop];
iTempOwnerOfThisCard = iCardOwnerArray[iTempCard];
if (iTeamLoop === iTempOwnerOfThisCard) {
boolOwnsOneOfThisSuit = true;
}
}
if (boolOwnsOneOfThisSuit) {
//they own one, don't set it out
} else {
AssignTeamOutOfSuit(iTeamLoop,ReturnRoundOfPreviousTurn(),iSuitLoop,false,"Out of " + sSuits[iSuitLoop] + " because we know every card, and none of them are " + sSuits[iSuitLoop])
iCountChanges++
}
}
}
}
}
return iCountChanges;
}catch(err) {DisplayError("CheckTeamsThatKnowAllOutOfSuits",err)}}
function CheckThisCardForDontHaveTheory(iCardToCheck, iThisTeam) {try {
for(var iTemp = 0; iTemp < iTeamCardsDontHaveArray[iThisTeam].length; iTemp++){
if ( iTeamCardsDontHaveArray[iThisTeam][iTemp] === iCardToCheck) {
return true;
}
};
return false;
}catch(err) {DisplayError("CheckThisCardForDontHaveTheory",err)}}
function ClickOrTypeThisCard(iTempCard) {try {
var iCardOwner = iCardOwnerArray[iTempCard]
var iCardPlayedBy = iCardPlayedByArray[iTempCard]
var sTemp = "";
//total of 7 (step 0-3, plus renege, history, and unplayed)
if ((sURL === "") && (iStep === 0)) {
//0 select your cards
if (IsThisCardInThisArray(iTempCard, iOriginal13Array)) {
RemoveFrom13(iTempCard)
} else {
AddTo13(iTempCard)
}
} else if ((sURL === "") && (iStep === 1)) {
//1 pass 3
if (IsThisCardInThisArray(iTempCard, iPassed3Array)) {
RemoveFromPassing3(iTempCard)
} else {
AddToPassing3(iTempCard)
}
} else if ((sURL === "") && (iStep === 2)) {
//1 receive 3
if (IsThisCardInThisArray(iTempCard, iPassed3Array)) {
YouCannotPlayThatCard(iTempCard,"You cannot select that card, because you passed it " + sDirection)
} else if (IsThisCardInThisArray(iTempCard, iOriginal13Array)) {
YouCannotPlayThatCard(iTempCard,"You cannot select that card, because it was in the original 13 cards you were dealt.")
} else if (IsThisCardInThisArray(iTempCard, iReceived3Array)) {
RemoveFromReceiving3(iTempCard)
} else {
AddToReceiving3(iTempCard)
}
} else if ((sURL === "") && (iStep === 3)) {
//game play
//if it's been played, display extra information, including buttons to go to replay
if (iCardOwner === 5) {
ThisCardHasBeenPlayedInfo(iTempCard)
} else if (!IsThisCardInThisArray(iTempCard, iLegalPlaysArray)) {
sTemp = sCardWhyNotLegalForThisTurnArray[iTempCard]
if (sTemp === "") {
sTemp = "Error in logic? Card is not in legal plays array, but it does not have a reason."
}
YouCannotPlayThatCard(iTempCard,sTemp)
} else {
PlayCardSL(iTempCard);
}
} else if ((sURL === "History") || (sURL === "Renege")) {
if (iCardOwner === 5) {
ThisCardHasBeenPlayedInfo(iTempCard)
} else if (IsThisCardInThisArray(iTempCard, iPassed3Array)) {
YouCannotPlayThatCard(iTempCard,"This card was dealt to you and you passed it " + sDirection)
} else if (IsThisCardInThisArray(iTempCard, iReceived3Array)) {
YouCannotPlayThatCard(iTempCard,"You received this card")
} else if (IsThisCardInThisArray(iTempCard, iOriginal13Array)) {
YouCannotPlayThatCard(iTempCard,"You were dealt this card in the original 13 and did not pass it.")
} else {
YouCannotPlayThatCard(iTempCard,"This card is unverified.")
}
} else {
if (iCardOwner === 5) {
ThisCardHasBeenPlayedInfo(iTempCard)
} else if (iCardOwner === -1) {
YouCannotPlayThatCard(iTempCard,"This card hasn't been played and we do not know the owner.")
} else if (iCardOwner === 3) {
YouCannotPlayThatCard(iTempCard,"You own this card and it has not been played.")
} else {
YouCannotPlayThatCard(iTempCard,"This card has not been played, but we know it is owned by " + GetArrowText(iCardOwner))
}
}
}catch(err) {DisplayError("ClickOrTypeThisCard",err)}}
function ComparePossibleCardsToCardsShouldHave() {try {
var iChangesMade = 0;
var iPossible = 0;
var iCard = 0;
for (var iTeam = 0; iTeam <= 2; iTeam++) { //not me
if (boolTeamKnowAllArray[iTeam]) {
//don't change anything for this team, we already know all
} else {
iPossible = 0;
for (iCard = 0; iCard <= 51; iCard++) {
if (boolTeamSuitOutArray[iTeam][GetSuitIndex(sCardSuitArray[iCard])]) {
//out of this suit, not possible
} else if ((iCardOwnerArray[iCard] === -1) || (iCardOwnerArray[iCard] === iTeam)) {
iPossible++
}
}
if (iPossible === HowManyCardsForThisTeam(iTeam)) {
//set all these cards to owned by this team if not already
for (iCard = 0; iCard <= 51; iCard++) {
if (boolTeamSuitOutArray[iTeam][GetSuitIndex(sCardSuitArray[iCard])]) {
//i already know this person is out of this suit
} else if (iCardOwnerArray[iCard] === -1) {
iChangesMade++
iCardOwnerArray[iCard] = iTeam;
vLogicExplainArray.push([iTeam,ReturnRoundOfPreviousTurn(),"Has the " + sCardNumberArray[iCard] + " of " + sCardSuitArray[iCard] + " because it has to be in this hand based on the number of unknown cards remaining"])
}
}
}
}
}
return iChangesMade;
}catch(err) {DisplayError("ComparePossibleCardsToCardsShouldHave",err)}}
function DisplayError(sFunctionName,vError) {
alert("ERROR\nFunction: " + sFunctionName + "\nError Name: " + vError.name + "\nError Message: " + vError.message);
}
function DoAllCardsOfThisSuitHaveAnOwner(sThisSuit) {try {
var iTempCardArray = [];
var iCardLoop = 0;
var iTempCard = 0;
var iTempOwner = 0;
iTempCardArray = GetArrayOfCardsOfThisSuit(sThisSuit);
for (iCardLoop = 0; iCardLoop < iTempCardArray.length; iCardLoop++) {
iTempCard = iTempCardArray[iCardLoop];
iTempOwner = iCardOwnerArray[iTempCard];
if (iTempOwner === -1) {
return false;
}
}
return true;
}catch(err) {DisplayError("DoAllCardsOfThisSuitHaveAnOwner",err)}}
function DoWeKnowForSureThisTeamHasASuit(iThisTeam, sThisSuit) {try {
for (var iTemp = 0; iTemp <= 51; iTemp++) {
if (iCardOwnerArray[iTemp] === iThisTeam) {
if (sCardSuitArray[iTemp] === sThisSuit) {
return true;
}
}
}
return false;
}catch(err) {DisplayError("DoWeKnowForSureThisTeamHasASuit",err)}}
function FinishGame() {try {
for (var iLoopTeam = 0; iLoopTeam < 4; iLoopTeam++) {
for (var iLoopSuit = 0; iLoopSuit < 4; iLoopSuit++) {
AssignTeamOutOfSuit(iLoopTeam,ReturnRoundOfPreviousTurn(),iLoopSuit,false,"Out of " + sSuits[iLoopSuit] + " because the round is over, all cards have been played")
}
}
}catch(err) {DisplayError("FinishGame",err)}}