xxxxxxxxxx
210
// ****** TODO: This is OUTDATED!!!!!! Look in "WeakActive.js" instead. Have to restructure that to be strong vs from CPU
// ======================================= SET VARIABLES =======================================
// Takes all of the same values but for the whole hand
// RM:
let handArray = $gameVariables.value(140); // This is the current player's hand
let card1 = [$gameActors.actor($gameVariables.value(140)[0]).currentClass().name, $gameActors.actor($gameVariables.value(140)[0]).equips()[2].name, $gameActors.actor($gameVariables.value(140)[0]).skills()[1].name, $gameActors.actor($gameVariables.value(140)[0]).skills()[2].name, $gameActors.actor($gameVariables.value(140)[0]).name(), $gameActors.actor($gameVariables.value(140)[0])];
let card2 = [$gameActors.actor($gameVariables.value(140)[1]).currentClass().name, $gameActors.actor($gameVariables.value(140)[1]).equips()[2].name, $gameActors.actor($gameVariables.value(140)[1]).skills()[1].name, $gameActors.actor($gameVariables.value(140)[1]).skills()[2].name, $gameActors.actor($gameVariables.value(140)[1]).name(), $gameActors.actor($gameVariables.value(140)[1])];
let card3 = [$gameActors.actor($gameVariables.value(140)[2]).currentClass().name, $gameActors.actor($gameVariables.value(140)[2]).equips()[2].name, $gameActors.actor($gameVariables.value(140)[2]).skills()[1].name, $gameActors.actor($gameVariables.value(140)[2]).skills()[2].name, $gameActors.actor($gameVariables.value(140)[2]).name(), $gameActors.actor($gameVariables.value(140)[2])];
let card4 = [$gameActors.actor($gameVariables.value(140)[3]).currentClass().name, $gameActors.actor($gameVariables.value(140)[3]).equips()[2].name, $gameActors.actor($gameVariables.value(140)[3]).skills()[1].name, $gameActors.actor($gameVariables.value(140)[3]).skills()[2].name, $gameActors.actor($gameVariables.value(140)[3]).name(), $gameActors.actor($gameVariables.value(140)[3])];
let card5 = [$gameActors.actor($gameVariables.value(140)[4]).currentClass().name, $gameActors.actor($gameVariables.value(140)[4]).equips()[2].name, $gameActors.actor($gameVariables.value(140)[4]).skills()[1].name, $gameActors.actor($gameVariables.value(140)[4]).skills()[2].name, $gameActors.actor($gameVariables.value(140)[4]).name(), $gameActors.actor($gameVariables.value(140)[4])];
let card6 = [$gameActors.actor($gameVariables.value(140)[5]).currentClass().name, $gameActors.actor($gameVariables.value(140)[5]).equips()[2].name, $gameActors.actor($gameVariables.value(140)[5]).skills()[1].name, $gameActors.actor($gameVariables.value(140)[5]).skills()[2].name, $gameActors.actor($gameVariables.value(140)[5]).name(), $gameActors.actor($gameVariables.value(140)[5])];
let types = [card1[0], card2[0], card3[0], card4[0], card5[0], card6[0]];
let birthdays = [card1[1], card2[1], card3[1], card4[1], card5[1], card6[1]];
let traits = [card1[2], card2[2], card3[2], card4[2], card5[2], card6[2], card1[3], card2[3], card3[3], card4[3], card5[3], card6[3]];
// ======================================= FUNCTIONS =======================================
// This is taken mostly from the AI for Mode 1:
// ----- FREQUENCY OF STRING -----
// Determines which value is most frequently used (i.e., Compass World for world because there are 2/3)
function mostFrequent(array){
var freq; // stores the most frequent item
var counts = {}; // counts occurence of item
var compare = 0; // compares using stored value
for(var i = 0, len = array.length; i < len; i++){ // len variable stores the length, so it runs as long as the length is less than number of items in the array
var word = array[i]; // save the first item of the array in the word variable
if (word !== "0") {
if (counts[word] === undefined){ // if the counts[word] doesn't exist
counts[word] = 1; // sets count[word] to 1
} else { // if it does exist
counts[word] = counts[word] + 1; // increment existing value
}
if (counts[word] > compare) { // counts[word] > 0 (first time); the first time, this is false
compare = counts[word]; // set compare to counts[word]
freq = array[i]; // sets most frequently used value
}
}
else {
//console.log("Value was " + word)
}
}
return freq;
}
// Sets the arrays to search specifically for the array elements
// String (array) of the most frequently occurring from all listed cards
let printMost = [0, mostFrequent(types), mostFrequent(birthdays), mostFrequent(traits)];
//console.log(" :TEST: printMost: " + printMost);
// ----- COUNT OF INTEGER -----
// Counts how many times the specified value is used (i.e., Compass World in the world array)
function countValues(array,value){
var n = 0;
for(i = 0; i < array.length; i++){
if(array[i] == value){n++}
}
return n;
}
// Integers added together to show the total of how many times the most frequent value is used
let totalCount = [0, countValues(types, printMost[1]), countValues(birthdays, printMost[2]), countValues(traits, printMost[3])];
//console.log(" :TEST: totalCount: " + totalCount);
// Finds the highest value in the array (so for this example, it's 3 for both Fall and Compass World, but 4 for M Nay)
function maxVal(array){
let indexOfMax = 0;
for (let i = 0; i < array.length; i++){
if (array[i] > array[indexOfMax]){
indexOfMax = i;
}
}
return array[indexOfMax];
}
let countMost = maxVal(totalCount); // this is 4 if all 4 match
// Set this at the start, it'll track which array is actively being pulled out of that loop when getting the name/count; this is basically the position it's pulling
let activeArray;
// This finds the highest number from the totalCount, then it finds the name and position from the printMost to return that string
// If totalCount[i] = countMost, then print the name
// in this case: if array numbers([4] or [6]) is equal to 3, then printMost[4] or printMost[6]
function findHighest(count, name) {
for (let i = 0; i < 7; i++) {
if (countMost <= count[i]) { // once it gets to array[5], value of 3 it breaks out
//console.log(" :TEST: " + "Highest Return Count: " + count[i])
//console.log(" :TEST: " + "Highest Return Name: " + name[i])
// When the name and count are pulled,this sets the active array:
activeArray = i; // This example is position 4
return name[i];
}
}
}
let biggestName = findHighest(totalCount, printMost);
// ======================================= CHOOSE DISCARD =======================================
// Checks if the most frequent string is not found in any of the cards, and it chooses the first one to discard
let selected;
if (!card1.includes(biggestName)) {
selected = 0;
} else if (!card2.includes(biggestName)) {
selected = 1;
} else if (!card3.includes(biggestName)) {
selected = 2;
} else if (!card4.includes(biggestName)) {
selected = 3;
} else if (!card5.includes(biggestName)) {
selected = 4;
} else if (!card6.includes(biggestName)) {
selected = 5;
} else {
selected = 6;
}
//console.log(selected);
// NEW:
let handPlayerArray = $gameVariables.value(140); // This is the selected player's hand
// Type[0], Birthday[1], Birthday[2], Trait 2[3], Trait 3[4], Name[5], ID[6]
let cardP1 = [$gameActors.actor($gameVariables.value(137)[0]).currentClass().name, $gameActors.actor($gameVariables.value(137)[0]).equips()[2].name, $gameActors.actor($gameVariables.value(137)[0]).skills()[1].name, $gameActors.actor($gameVariables.value(137)[0]).skills()[2].name, $gameActors.actor($gameVariables.value(137)[0]).name(), $gameActors.actor($gameVariables.value(137)[0])];
let cardP2 = [$gameActors.actor($gameVariables.value(137)[1]).currentClass().name, $gameActors.actor($gameVariables.value(137)[1]).equips()[2].name, $gameActors.actor($gameVariables.value(137)[1]).skills()[1].name, $gameActors.actor($gameVariables.value(137)[1]).skills()[2].name, $gameActors.actor($gameVariables.value(137)[1]).name(), $gameActors.actor($gameVariables.value(137)[1])];
let cardP3 = [$gameActors.actor($gameVariables.value(137)[2]).currentClass().name, $gameActors.actor($gameVariables.value(137)[2]).equips()[2].name, $gameActors.actor($gameVariables.value(137)[2]).skills()[1].name, $gameActors.actor($gameVariables.value(137)[2]).skills()[2].name, $gameActors.actor($gameVariables.value(137)[2]).name(), $gameActors.actor($gameVariables.value(137)[2])];
let cardP4 = [$gameActors.actor($gameVariables.value(137)[3]).currentClass().name, $gameActors.actor($gameVariables.value(137)[3]).equips()[2].name, $gameActors.actor($gameVariables.value(137)[3]).skills()[1].name, $gameActors.actor($gameVariables.value(137)[3]).skills()[2].name, $gameActors.actor($gameVariables.value(137)[3]).name(), $gameActors.actor($gameVariables.value(137)[3])];
let cardP5 = [$gameActors.actor($gameVariables.value(137)[4]).currentClass().name, $gameActors.actor($gameVariables.value(137)[4]).equips()[2].name, $gameActors.actor($gameVariables.value(137)[4]).skills()[1].name, $gameActors.actor($gameVariables.value(137)[4]).skills()[2].name, $gameActors.actor($gameVariables.value(137)[4]).name(), $gameActors.actor($gameVariables.value(137)[4])];
let cardP6 = [$gameActors.actor($gameVariables.value(137)[5]).currentClass().name, $gameActors.actor($gameVariables.value(137)[5]).equips()[2].name, $gameActors.actor($gameVariables.value(137)[5]).skills()[1].name, $gameActors.actor($gameVariables.value(137)[5]).skills()[2].name, $gameActors.actor($gameVariables.value(137)[5]).name(), $gameActors.actor($gameVariables.value(137)[5])];
let playerHand = [cardP1, cardP2, cardP3, cardP4, cardP5, cardP6];
// Determines which card has the biggestName included in it (if none, then it'll be random)
let picked; // slot
if (cardP1.includes(biggestName)) {
picked = 0;
} else if (cardP2.includes(biggestName)) {
picked = 1;
} else if (cardP3.includes(biggestName)) {
picked = 2;
} else if (cardP4.includes(biggestName)) {
picked = 3;
} else if (cardP5.includes(biggestName)) {
picked = 4;
} else if (cardP6.includes(biggestName)) {
picked = 5;
} else {
picked = 6;
}
// Picked Variables
if (picked == 6) {
picked = Math.floor(Math.random() * 6); // Picks random number between 0-5
}
let activeCard = playerHand[picked]; // This will be cardP1, cardP2, etc.
let pickedName = activeCard[5]; // The player's name from the cardP1 arrays; var 110
let pickedID = activeCard[6];
//$gameVariables.value(137)[picked]; // var 89
// Selected Variables
if (selected == 6) {
picked = Math.floor(Math.random() * 6); // Picks random number between 0-5
}
let selectCard = selectHand[selected]; // This will be card1, card2, etc.
let selectedName = selectCard[5]; // The player's name from the card1 arrays; var 111
let selectedID = selectCard[6]; // var 135
// ======================================= RETURN VARIABLES =======================================
// RM:
$gameVariables.setValue(88, selected); // slot
$gameVariables.setValue(135, selectedID); // ID
$gameVariables.setValue(111, selectedName); // name
$gameVariables.setValue(138, biggestName);
$gameVariables.setValue(136, picked); // slot
$gameVariables.setValue(89, pickedID); // ID
$gameVariables.setValue(110, pickedName); // name
// Once above is done, trigger the next part
$gameSwitches.setValue(9, true);