ajout de la contrainte de ne pas rejouer contre les memes (essai raté)
This commit is contained in:
88
table.html
88
table.html
@@ -1,8 +1,9 @@
|
|||||||
|
<!doctype html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script >
|
<script type="text/javascript" >
|
||||||
|
|
||||||
playerSet = [ "Pierre Moreau", "Thomas Gauthier", "Antoine Nicolas", "Axel Blanc",
|
playerSet = [ "Pierre Moreau", "Thomas Gauthier", "Antoine Nicolas", "Axel Blanc",
|
||||||
"Clément Garcia", "Maël Mercier", "Alexis Chevalier", "Paul Rousseau", "Théo Leroy", "Victor Robert",
|
"Clément Garcia", "Maël Mercier", "Alexis Chevalier", "Paul Rousseau", "Théo Leroy", "Victor Robert",
|
||||||
@@ -17,10 +18,38 @@
|
|||||||
|
|
||||||
gameSet= [ "Splendor", "Azul", "King Domino", "7 wonders architect", "akkroplis"];
|
gameSet= [ "Splendor", "Azul", "King Domino", "7 wonders architect", "akkroplis"];
|
||||||
|
|
||||||
|
function Player(name) {
|
||||||
|
this.name = name;
|
||||||
|
this.opponents = [];
|
||||||
|
this.gamesPlayed = [];
|
||||||
|
}
|
||||||
|
Player.prototype.availablePlayers = function (players, game) {
|
||||||
|
result = [];
|
||||||
|
for (var player of players ) {
|
||||||
|
if (!this.opponents.includes(player.name) &&
|
||||||
|
!player.gamesPlayed.includes(game) ) //TODO en fonction du mode
|
||||||
|
result.push(player);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Player.prototype.addOpponents = function (players) {
|
||||||
|
for (var player of players ) {
|
||||||
|
if (player.name === this.name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//showDebug(this.name + " ajoute oposant "+ player.name);
|
||||||
|
this.opponents.push(player.name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function compute() {
|
function compute() {
|
||||||
document.getElementById("results").innerHTML="";
|
document.getElementById("results").innerHTML="";
|
||||||
players = playerSet.slice(0,document.getElementById("players").value) ;
|
players = [];
|
||||||
|
for (name of playerSet.slice(0,document.getElementById("players").value) ) {
|
||||||
|
players.push(new Player(name) );
|
||||||
|
};
|
||||||
games = gameSet.slice(0,document.getElementById("games").value) ;
|
games = gameSet.slice(0,document.getElementById("games").value) ;
|
||||||
playerAtTable = document.getElementById("tables").value;
|
playerAtTable = document.getElementById("tables").value;
|
||||||
|
|
||||||
@@ -37,34 +66,46 @@
|
|||||||
}
|
}
|
||||||
played ={};
|
played ={};
|
||||||
for( const player of players ) {
|
for( const player of players ) {
|
||||||
played[player]={};
|
played[player.name]={};
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!finished) {
|
while(!finished) {
|
||||||
show("<p><b>Session "+session +"<b><br/>");
|
show("<p><b>Session "+session +"<b><br/>");
|
||||||
var tables=0;
|
var tables=0;
|
||||||
playerPlayInSession=[];
|
playersAvailableInSession=players.slice();
|
||||||
for( const game of games ) {
|
newTable=1;
|
||||||
possibleplayers =[];
|
while(playersAvailableInSession.length >= playerAtTable
|
||||||
for( const player of players ) {
|
&& tables < maxgameplayed && newTable > 0) {
|
||||||
if ( typeof played[player][game] === "undefined" && !playerPlayInSession.includes(player) ) {
|
newTable=0;
|
||||||
possibleplayers.push(player);
|
for( const game of games ) {
|
||||||
}
|
showDebug( "try for "+game+" players disponibles "+playersAvailableInSession.length +" ");
|
||||||
if(possibleplayers.length == playerAtTable) break; //les premiers disponibles n'ayant pas joué
|
possibleplayers= playersAvailableInSession[0].availablePlayers( playersAvailableInSession, game);
|
||||||
}
|
showDebug ("players dispo " +possibleplayers.length + " <br/>" );
|
||||||
|
|
||||||
//youpi , une table faite
|
//youpi , une table faite
|
||||||
if(possibleplayers.length == playerAtTable ) {
|
if(possibleplayers.length >= playerAtTable ) {
|
||||||
for( const player of possibleplayers ) {
|
tablePlayer = possibleplayers.slice(0,playerAtTable) ;
|
||||||
played[player][game] = session;
|
show( "table "+game+" : ");
|
||||||
playerPlayInSession.push(player);
|
//showDebug ("tablePlayer : " +JSON.stringify(tablePlayer) ) ;
|
||||||
|
for( const player of tablePlayer ) {
|
||||||
|
played[player.name][game] = session;
|
||||||
|
player.gamesPlayed.push(game);
|
||||||
|
player.addOpponents(tablePlayer);
|
||||||
|
show( player.name +", ");
|
||||||
|
const index = playersAvailableInSession.indexOf(player);
|
||||||
|
if (index > -1) {
|
||||||
|
//showDebug("remove "+ player.name + " du pool de session <br/>");
|
||||||
|
playersAvailableInSession.splice(index, 1); // 2nd parameter means remove one item only
|
||||||
|
}
|
||||||
|
}
|
||||||
|
show( "<br/>");
|
||||||
|
tables++;
|
||||||
|
newTable++;
|
||||||
}
|
}
|
||||||
show( "table "+game+" : " + possibleplayers.join(" , ") +"<br/>");
|
|
||||||
tables++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tables == maxgameplayed) {
|
if(tables == maxgameplayed) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
show("</p>");
|
show("</p>");
|
||||||
@@ -95,6 +136,9 @@
|
|||||||
show ("<span style='color:red' >"+ text +"</span><br/>");
|
show ("<span style='color:red' >"+ text +"</span><br/>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function showDebug(text){
|
||||||
|
show ("<span style='color:gray' >"+ text +"</span><br/>");
|
||||||
|
}
|
||||||
function show(text) {
|
function show(text) {
|
||||||
elem = document.getElementById("results");
|
elem = document.getElementById("results");
|
||||||
elem.insertAdjacentHTML( 'beforeend', text);
|
elem.insertAdjacentHTML( 'beforeend', text);
|
||||||
|
|||||||
Reference in New Issue
Block a user