Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToyingAround #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 74 additions & 11 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,78 @@ chris.skill = [25.0, 25.0/3.0]
darren = {}
darren.skill = [25.0, 25.0/3.0]

function consScore (player) {
return player.skill[0] - (player.skill[1] * 3);
}

// The four players play a game. Alice wins, Bob and Chris tie for
// second, Darren comes in last. The actual numerical values of the
// ranks don't matter, they could be (1, 2, 2, 4) or (1, 2, 2, 3) or
// (23, 45, 45, 67). All that matters is that a smaller rank beats a
// larger one, and equal ranks indicate draws.

alice.rank = 1

alice.rank = 4
bob.rank = 2
chris.rank = 5
darren.rank = 1

// Do the computation to find each player's new skill estimate.

trueskill = require("./trueskill");
trueskill.AdjustPlayers([alice, bob, chris, darren]);

// Print the results.

console.log("alice: [ rank", alice.rank, ']', alice.skill, consScore(alice));
console.log("bob: [ rank", bob.rank, ']', bob.skill, consScore(bob));
console.log("chris: [ rank", chris.rank, ']', chris.skill, consScore(chris));
console.log("darren: [ rank", darren.rank, ']', darren.skill, consScore(darren));
console.log('-----------------------')


alice.rank = 4
bob.rank = 2
chris.rank = 5
darren.rank = 1

// Do the computation to find each player's new skill estimate.

trueskill = require("./trueskill");
trueskill.AdjustPlayers([alice, bob, chris, darren]);

// Print the results.

console.log("alice: [ rank", alice.rank, ']', alice.skill, consScore(alice));
console.log("bob: [ rank", bob.rank, ']', bob.skill, consScore(bob));
console.log("chris: [ rank", chris.rank, ']', chris.skill, consScore(chris));
console.log("darren: [ rank", darren.rank, ']', darren.skill, consScore(darren));
console.log('-----------------------')


alice.rank = 4
bob.rank = 6
chris.rank = 5
darren.rank = 1

// Do the computation to find each player's new skill estimate.

trueskill = require("./trueskill");
trueskill.AdjustPlayers([alice, bob, chris, darren]);

// Print the results.

console.log("alice: [ rank", alice.rank, ']', alice.skill, consScore(alice));
console.log("bob: [ rank", bob.rank, ']', bob.skill, consScore(bob));
console.log("chris: [ rank", chris.rank, ']', chris.skill, consScore(chris));
console.log("darren: [ rank", darren.rank, ']', darren.skill, consScore(darren));
console.log('-----------------------')


alice.rank = 4
bob.rank = 2
chris.rank = 2
darren.rank = 4
chris.rank = 5
darren.rank = 9

// Do the computation to find each player's new skill estimate.

Expand All @@ -46,11 +108,12 @@ trueskill.AdjustPlayers([alice, bob, chris, darren]);

// Print the results.

console.log("alice:");
console.log(alice.skill);
console.log("bob:");
console.log(bob.skill);
console.log("chris:");
console.log(chris.skill);
console.log("darren:");
console.log(darren.skill);
console.log("alice: [ rank", alice.rank, ']', alice.skill, consScore(alice));
console.log("bob: [ rank", bob.rank, ']', bob.skill, consScore(bob));
console.log("chris: [ rank", chris.rank, ']', chris.skill, consScore(chris));
console.log("darren: [ rank", darren.rank, ']', darren.skill, consScore(darren));
console.log('-----------------------')




191 changes: 191 additions & 0 deletions gameObjectExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
// The output of this program should match the output of the TrueSkill
// calculator at:
//
// http://atom.research.microsoft.com/trueskill/rankcalculator.aspx
//
// (Select game mode "custom", create 4 players each on their own team,
// check the second "Draw?" box to indicate a tie for second place,
// then click "Recalculate Skill Level Distribution". The mu and sigma
// values in the "after game" section should match what this program
// prints.

// The objects we pass to AdjustPlayers can be anything with skill and
// rank attributes.

// Create four players. Assign each of them the default skill. The
// player ranking (their "level") is mu-3*sigma, so the default skill
// value corresponds to a level of 0.

const players = {
// the below players are now added automatically with each game in the game object.
/* alice: {
skill: [25.0, 25.0/3.0],
gamesplayed: []
},
bob: {
skill: [25.0, 25.0/3.0],
gamesplayed: []
},
chris: {
skill: [25.0, 25.0/3.0],
gamesplayed: []
},
darren: {
skill: [25.0, 25.0/3.0],
gamesplayed: []
},
franky: {
skill: [25.0, 25.0/3.0],
gamesplayed: []
},
freddy: {
skill: [25.0, 25.0/3.0],
gamesplayed: []
},
jacklee: {
skill: [25.0, 25.0/3.0],
gamesplayed: []
},*/
makePlayer (name) {
this[name] = {
skill: [25.0, 25.0/3.0],
gamesplayed: []
}
}

};

const games = {
game1:{
gameId: 'game1',
name: 'Magical Piobaireachd Championship',
kind: 'piob',
results: [
{name: 'alice', pos: 1},
{name: 'bob', pos: 2},
{name: 'chris', pos: 3},
{name: 'darren', pos: 4},
] ,


judges: ['jacktaylor','jacklee','jackheins']
},
game2:{
gameId: 'game2',
name: 'Magical MSR Championship',
kind: 'MSR',
results: [
{name: 'franky', pos: 1},
{name: 'chris', pos: 2},
{name: 'alice', pos: 3},
{name: 'bob', pos: 4},
{name: 'darren', pos: 5},
],
judges: ['jacktaylor','jacklee','jackheins']
} ,
game3:{
gameId: 'game3',
name: 'Magical HJ Championship',
kind: 'HJ',
results: [
{name: 'alice', pos: 1},
{name: 'franky', pos: 2},
{name: 'chris', pos: 3},
{name: 'bob', pos: 4},
{name: 'darren', pos: 5},

] ,
judges: ['jacktaylor','jacklee','jackheins']
},
game4:{
gameId: 'game4',
name: 'Game 4',
kind: 'HJ',
results: [
{name: 'jacklee', pos: 1},
{name: 'franky', pos: 2},
{name: 'freddy', pos: 3},
{name: 'bob', pos: 4},
{name: 'darren', pos: 5},

] ,
judges: ['jacktaylor','jacklee','jackheins']
},
game5:{
gameId: 'game5',
name: 'Game 5',
kind: 'HJ',
results: [
{name: 'jacklee', pos: 1},
{name: 'franky', pos: 2},
{name: 'chris', pos: 3},
{name: 'bob', pos: 4},
{name: 'darren', pos: 5},
{name: 'alice', pos: 6},
{name: 'freddy', pos: 7},
{name: 'billybob', pos: 7}

] ,
judges: ['jacktaylor','jacklee','jackheins']
}
};


function consScore (player) {
return player.skill[0] - (player.skill[1] * 3);
}

function playGame(gameName) {

let adjustArr = []; // initialize an array we can use for the "Adjust Players later. "

//For each player in the game, log their result (individually)
gameName.results.forEach(result => {
let playerName = result.name;
let playerRank = result.pos;

//if the player doesn't exist yet, make one, with default '0' true score.
if (typeof players[playerName] === 'undefined') {
players.makePlayer(playerName);
}

players[playerName].rank = playerRank; // sets rank to player for this game.
adjustArr.push(players[playerName]); // push to the Adjustment Array
players[playerName].gamesplayed.push(gameName.gameId); //log this game to player object
});

//Now, "Adjust" all of the players that participated in this game.
trueskill = require("./trueskill"); //hooks in the magic trueskill algos
trueskill.AdjustPlayers(adjustArr); // does the adjustment on the completed array.


//update the player object with new "consScores" (conservative estimates of skill)
gameName.results.forEach(result => {
let playerName = result.name;
players[playerName].consscore = consScore(players[playerName]); // sets a conScore for the player based on the result of this game.
});


//This logs the result of this game on the player ratings to the console
console.log(gameName.name);
console.log('------------------------------------');
gameName.results.forEach(result => {
let playerName = result.name;
let playerRank = result.pos;
console.log(playerName, ": [ rank", players[playerName].rank, ']', players[playerName].skill, consScore(players[playerName]), '---> Total games = ', players[playerName].gamesplayed.length);
})
console.log('------------------------------------');
console.log(' ');

} ;

//Now play all the games in the game object.
for (const game in games) {
if (game.includes('game') && games[game].kind === 'HJ') {
playGame(games[game]);
}
}

console.log(players);


1 change: 1 addition & 0 deletions node_modules/.bin/cake

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/.bin/coffee

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions node_modules/coffee-script/.npmignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/coffee-script/CNAME

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions node_modules/coffee-script/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading