Better weights

This commit is contained in:
eTronic
2018-06-29 23:56:24 -04:00
parent 870a3c2434
commit 15cb020762
3 changed files with 9533 additions and 40 deletions

View File

@@ -209,30 +209,10 @@ request('https://api-quiz.hype.space/shows/now', (error, response, body) => {
if (timeoutTimer) clearTimeout(timeoutTimer);
const inputAnswer = res.answer.trim();
if (!inputAnswer) {
if (PLAY_USING_DISCORD) {
console.log('Playing using Discord current weights...');
let weights = scraper.getWeights();
console.log(`Weights: [${weights}]`);
const normalized = scraper.normalizeWeights(playersInGame.length);
let playerIndex = 0;
normalized.forEach((playersAssignedToAnswer, index) => {
for (let i = 0; i < playersAssignedToAnswer; i++) {
const player = playersInGame[playerIndex];
if (player) {
player.sendAnswer(questionId, answers[index].answerId);
console.log(`Player ${player.username} sent answer ${index + 1}`);
playerIndex++;
}
}
});
} else {
playersInGame.forEach((player, index) => {
console.log(`Player ${player.username} sent answer ${(index % 3) + 1}`);
player.sendAnswer(questionId, answers[index % 3].answerId);
});
}
playersInGame.forEach((player, index) => {
console.log(`Player ${player.username} sent answer ${(index % 3) + 1}`);
player.sendAnswer(questionId, answers[index % 3].answerId);
});
} else {
const input = inputAnswer.split(/,| |;/);
switch (input.length) {

File diff suppressed because it is too large Load Diff

View File

@@ -15,15 +15,27 @@ const servers = [
{
name: 'roles-hq',
id: '454309318330810376',
weightModifier: 0.75,
weightModifier: 10,
},
{
name: 'public-hq',
id: '449575067333033984',
weightModifier: 0.25,
weightModifier: 1,
},
],
},
{
name: 'Hub',
id: '452222497312604170',
channels: [
{
name: 'hq-trivia',
id: '452223090508693515',
weightModifier: 20,
},
],
},
/*
{
name: 'Trivia API',
id: '460797927279951892',
@@ -35,15 +47,17 @@ const servers = [
},
],
},
*/
];
const weights = {
'standard': 3,
'standard': 10,
'apg': 5,
'not': -2,
'w': 0.5,
'?': 0.8,
'not': -10,
'w': 1,
'?': 3,
'apb': 1,
'its': 15,
};
export default class Scraper {
@@ -55,6 +69,8 @@ export default class Scraper {
this.botClient = null;
this.timer = null;
this.players = {};
this.lastWeights = null;
this.ticker = 3;
}
run() {
@@ -102,6 +118,8 @@ export default class Scraper {
this.questionId = questionId;
this.answers = [];
this.weights = [0, 0, 0];
this.lastWeights = null;
this.ticker = 3;
const showUpdate = () => this.updateAnswers(question);
const delayUpdate = () => this.timer = setInterval(showUpdate.bind(this), 1000);
setTimeout(delayUpdate.bind(this), 3000);
@@ -113,10 +131,14 @@ export default class Scraper {
if (this.botClient) {
const channel = this.botClient.channels.get(BOT_DISCORD_CHANNEL);
const normalizedWeights = this.normalizeWeights();
if (channel) {
channel.send(`**Current Weights**\`\`\`[${this.weights[0]}, ${this.weights[1]}, ${this.weights[2]}]\t\t${this.getSuggestion()}\`\`\``);
channel.send(`**Normalized Weights**\`\`\`[${normalizedWeights[0]}%, ${normalizedWeights[1]}%, ${normalizedWeights[2]}%]\t\t${this.getSuggestion()}\`\`\``);
// channel.send(`**Weight Deltas**\`\`\`[${differenceInWeights[0]}, ${differenceInWeights[1]}, ${differenceInWeights[2]}]\`\`\``);
}
}
this.ticker++;
}
getSuggestion() {
@@ -134,11 +156,11 @@ export default class Scraper {
return suggestion;
}
let splitChoices = normalizedWeights.filter(weight => weight >= 33);
let splitChoices = normalizedWeights.filter(weight => weight >= 20);
if (splitChoices.length === 3 || splitChoices.length === 0) return 'Split 1 2 3';
splitChoices = normalizedWeights.map((weight, index) => {
if (weight >= 30) return index;
if (weight >= 20) return index;
return null;
});
@@ -266,11 +288,11 @@ export default class Scraper {
correct = number === correctAnswer.toString();
}
if (!this.players[userId]) this.players[userId] = 1.0;
if (!this.players[userId]) this.players[userId] = 1;
if (correct) {
this.players[userId] = parseFloat(this.players[userId].toString()) + parseFloat('0.2');
this.players[userId] += 1;
} else {
this.players[userId] = parseFloat(this.players[userId].toString()) - parseFloat('1.0');
this.players[userId] -= 5;
}
return {
@@ -294,8 +316,8 @@ export default class Scraper {
const { author, content } = msg;
const { id: userId, username } = author;
const cleanedMessage = content.trim().replace(' ', '').toLowerCase();
const matchedMessage = /((w|not)?([123])(\?|apg|apb)?)/g.exec(cleanedMessage);
const cleanedMessage = content.trim().replace(' ', '').replace('\'', '').toLowerCase();
const matchedMessage = /((w|not|its)?([123])(\?|apg|apb)?)/g.exec(cleanedMessage);
if (!matchedMessage || matchedMessage.length === 0) return;
@@ -308,6 +330,7 @@ export default class Scraper {
let weight = this.weightAnswer(userId, answer);
weight = weight * validChannel.weightModifier;
weight = weight * this.ticker;
this.logAnswer(userId, username, answer, weight);
@@ -325,7 +348,7 @@ export default class Scraper {
const player = this.players[userId];
if (player) {
weight = parseFloat(weight.toString()) + parseFloat(player.toString());
weight += parseInt(player);
}
if (pre) {