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>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<script >
|
||||
<script type="text/javascript" >
|
||||
|
||||
playerSet = [ "Pierre Moreau", "Thomas Gauthier", "Antoine Nicolas", "Axel Blanc",
|
||||
"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"];
|
||||
|
||||
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() {
|
||||
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) ;
|
||||
playerAtTable = document.getElementById("tables").value;
|
||||
|
||||
@@ -37,34 +66,46 @@
|
||||
}
|
||||
played ={};
|
||||
for( const player of players ) {
|
||||
played[player]={};
|
||||
played[player.name]={};
|
||||
}
|
||||
|
||||
while(!finished) {
|
||||
show("<p><b>Session "+session +"<b><br/>");
|
||||
var tables=0;
|
||||
playerPlayInSession=[];
|
||||
for( const game of games ) {
|
||||
possibleplayers =[];
|
||||
for( const player of players ) {
|
||||
if ( typeof played[player][game] === "undefined" && !playerPlayInSession.includes(player) ) {
|
||||
possibleplayers.push(player);
|
||||
}
|
||||
if(possibleplayers.length == playerAtTable) break; //les premiers disponibles n'ayant pas joué
|
||||
}
|
||||
playersAvailableInSession=players.slice();
|
||||
newTable=1;
|
||||
while(playersAvailableInSession.length >= playerAtTable
|
||||
&& tables < maxgameplayed && newTable > 0) {
|
||||
newTable=0;
|
||||
for( const game of games ) {
|
||||
showDebug( "try for "+game+" players disponibles "+playersAvailableInSession.length +" ");
|
||||
possibleplayers= playersAvailableInSession[0].availablePlayers( playersAvailableInSession, game);
|
||||
showDebug ("players dispo " +possibleplayers.length + " <br/>" );
|
||||
|
||||
//youpi , une table faite
|
||||
if(possibleplayers.length == playerAtTable ) {
|
||||
for( const player of possibleplayers ) {
|
||||
played[player][game] = session;
|
||||
playerPlayInSession.push(player);
|
||||
//youpi , une table faite
|
||||
if(possibleplayers.length >= playerAtTable ) {
|
||||
tablePlayer = possibleplayers.slice(0,playerAtTable) ;
|
||||
show( "table "+game+" : ");
|
||||
//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) {
|
||||
break;
|
||||
if(tables == maxgameplayed) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
show("</p>");
|
||||
@@ -95,6 +136,9 @@
|
||||
show ("<span style='color:red' >"+ text +"</span><br/>");
|
||||
}
|
||||
|
||||
function showDebug(text){
|
||||
show ("<span style='color:gray' >"+ text +"</span><br/>");
|
||||
}
|
||||
function show(text) {
|
||||
elem = document.getElementById("results");
|
||||
elem.insertAdjacentHTML( 'beforeend', text);
|
||||
|
||||
Reference in New Issue
Block a user