JSFiddle - React, Tailwind, and code Playground
HTML
<p>Очки — среднее число пустых ячеек за 1000 запусков, меньше — лучше.</p>
<table id="scoretable">
<thead>
<tr>
<td></td>
<td>Участник</td>
<td>Очки(min/max)</td>
<td>Ошибки</td>
<td>Время</td>
</tr>
</thead>
</table>
CSS
#scoretable {
font-size: 16px;
line-height: 1.4;
border-collapse: collapse;
}
#scoretable thead td {
font-weight: 700;
border-bottom: 1px solid #ccc;
}
#scoretable td {
padding: 5px 30px 5px 5px;
}
#scoretable tr:nth-child(even) {
background: #f5f5f5;
}
JavaScript
var contenders = {
'bay73': function(w, h, cols) {
if(w==1) {
if(cols[5] < cols[4]) return 6;
if(cols[8] < cols[9]) return 9
else if(cols[9] <= 16) return 10;
else if(cols[4] <= 16) return 5;
else if(cols[3] < cols[2]) return 4;
else if(cols[2] < cols[1]) return 3;
else if(cols[1] < cols[0]) return 2;
else return 1;
}
if(w==2) {
if(cols[2] < cols[0]) return 3;
else if(cols[4] < cols[0]) return 5;
else if(cols[0] < cols[2]) return 1;
else if(cols[6] <= 18) return 7;
else if(cols[4] < 12) return 5;
else if(cols[4] < 18 && cols[9] < 16) return 5;
else if(cols[0] <= 17) return 1;
else if(cols[4] <= 18) return 5;
else return 9;
}
if(w==4) {
if(cols[0]<20) return 1;
else if(cols[1]<20) return 2;
else return 3;
}
},
'tigerforce': function(w, h, cols) {
function calculateScore(col) {
if (cols[col] + h > 20 || col + w > 10) {
return 999;
}
var score = 0;
for (var i = col; i < col + w; i++) {
if (cols[i] > cols[col]) {
return 999;
}
score += cols[col] - cols[i];
}
return score;
}
var bestMatch = {
col: 0,
score: cols[0]
},
colScore = 0;
for (var i = 0; i <= cols.length - w; i++) {
colScore = calculateScore(i);
if (colScore < bestMatch.score || (colScore == bestMatch.score && cols[i] < cols[bestMatch.col])) {
bestMatch.col = i;
bestMatch.score = colScore;
}
}
return...