Added chess board specification (number and cahracters), aswell as a detail view for the damen
This commit is contained in:
@@ -45,13 +45,28 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ♟️ Board */
|
/* ♟️ Board */
|
||||||
.board {
|
.board-grid {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(8, 60px);
|
grid-template-columns: 30px repeat(8, 60px);
|
||||||
|
grid-template-rows: 30px repeat(8, 60px);
|
||||||
margin: 20px auto;
|
margin: 20px auto;
|
||||||
width: 480px;
|
width: max-content;
|
||||||
|
border: 6px solid #1e293b;
|
||||||
|
border-radius: 10px;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-weight: bold;
|
||||||
|
background: #aec8eb;
|
||||||
|
color: #1e293b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.cell {
|
.cell {
|
||||||
width: 60px;
|
width: 60px;
|
||||||
height: 60px;
|
height: 60px;
|
||||||
@@ -114,3 +129,15 @@ body {
|
|||||||
.btn.danger:hover {
|
.btn.danger:hover {
|
||||||
background: #dc2626;
|
background: #dc2626;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#queenList {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#queenList li {
|
||||||
|
padding: 5px;
|
||||||
|
background: #f1f5f9;
|
||||||
|
margin: 4px 0;
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
@@ -90,32 +90,59 @@
|
|||||||
|
|
||||||
function drawBoard() {
|
function drawBoard() {
|
||||||
boardDiv.innerHTML = "";
|
boardDiv.innerHTML = "";
|
||||||
const conflicts = getConflicts();
|
boardDiv.className = "board-grid";
|
||||||
|
|
||||||
for (let row = 0; row < 8; row++) {
|
const conflicts = getConflicts();
|
||||||
for (let col = 0; col < 8; col++) {
|
const letters = ["A", "B", "C", "D", "E", "F", "G", "H"];
|
||||||
|
|
||||||
|
for (let row = -1; row < 8; row++) {
|
||||||
|
for (let col = -1; col < 8; col++) {
|
||||||
|
|
||||||
const cell = document.createElement("div");
|
const cell = document.createElement("div");
|
||||||
cell.classList.add("cell");
|
|
||||||
|
|
||||||
if ((row + col) % 2 === 0) {
|
// 🔹 Ecke oben links
|
||||||
cell.classList.add("white");
|
if (row === -1 && col === -1) {
|
||||||
} else {
|
cell.classList.add("label");
|
||||||
cell.classList.add("black");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (board[row] === col) {
|
// 🔹 Buchstaben (oben)
|
||||||
cell.textContent = "♛";
|
else if (row === -1) {
|
||||||
|
cell.textContent = letters[col];
|
||||||
|
cell.classList.add("label");
|
||||||
|
}
|
||||||
|
|
||||||
if (conflicts.some(([r, c]) => r === row && c === col)) {
|
// 🔹 Zahlen (links)
|
||||||
cell.classList.add("invalid");
|
else if (col === -1) {
|
||||||
|
cell.textContent = 8 - row;
|
||||||
|
cell.classList.add("label");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 echtes Spielfeld
|
||||||
|
else {
|
||||||
|
cell.classList.add("cell");
|
||||||
|
|
||||||
|
if ((row + col) % 2 === 0) {
|
||||||
|
cell.classList.add("white");
|
||||||
|
} else {
|
||||||
|
cell.classList.add("black");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (board[row] === col) {
|
||||||
|
cell.textContent = "♛";
|
||||||
|
|
||||||
|
if (conflicts.some(([r, c]) => r === row && c === col)) {
|
||||||
|
cell.classList.add("invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cell.onclick = () => placeQueen(row, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell.onclick = () => placeQueen(row, col);
|
|
||||||
boardDiv.appendChild(cell);
|
boardDiv.appendChild(cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateQueenList();
|
||||||
}
|
}
|
||||||
|
|
||||||
function placeQueen(row, col) {
|
function placeQueen(row, col) {
|
||||||
@@ -125,6 +152,7 @@
|
|||||||
board[row] = col;
|
board[row] = col;
|
||||||
}
|
}
|
||||||
drawBoard();
|
drawBoard();
|
||||||
|
updateQueenList();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function solve() {
|
async function solve() {
|
||||||
@@ -138,11 +166,43 @@
|
|||||||
function resetBoard() {
|
function resetBoard() {
|
||||||
board = Array(8).fill(-1);
|
board = Array(8).fill(-1);
|
||||||
drawBoard();
|
drawBoard();
|
||||||
|
updateQueenList();
|
||||||
}
|
}
|
||||||
|
|
||||||
drawBoard();
|
drawBoard();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>📋 Damen Positionen</h3>
|
||||||
|
<ul id="queenList"></ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function updateQueenList() {
|
||||||
|
const list = document.getElementById("queenList");
|
||||||
|
list.innerHTML = "";
|
||||||
|
|
||||||
|
const letters = ["A", "B", "C", "D", "E", "F", "G", "H"];
|
||||||
|
|
||||||
|
let count = 1;
|
||||||
|
|
||||||
|
for (let row = 0; row < 8; row++) {
|
||||||
|
if (board[row] !== -1) {
|
||||||
|
let col = board[row];
|
||||||
|
|
||||||
|
let pos = letters[col] + (8 - row);
|
||||||
|
|
||||||
|
const li = document.createElement("li");
|
||||||
|
li.textContent = `Dame ${count}: ${pos}`;
|
||||||
|
|
||||||
|
list.appendChild(li);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user