Skip to content

Instantly share code, notes, and snippets.

@evdokimovm
Last active February 15, 2024 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evdokimovm/f529c0f773e02f99abf0c0353fd7d231 to your computer and use it in GitHub Desktop.
Save evdokimovm/f529c0f773e02f99abf0c0353fd7d231 to your computer and use it in GitHub Desktop.
chess puzzles from The Password Game with answers
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Chess Puzzles from The Password Game with Solutions</title>
</head>
<body>
<style>
#container {
display: flex;
flex-direction: column;
width: 90%;
margin: 0 auto;
}
.puzzle {
display: flex;
flex-direction: column;
align-items: center;
}
.solution_wrapper {
display: flex;
flex-direction: row;
gap: 10px;
margin-bottom: 10px;
}
.spoiler {
cursor: pointer;
background-color: black;
}
.reveal {
cursor: auto;
background-color: inherit;
}
h1 {
margin: 0;
}
img {
max-width: 50%;
margin-bottom: 50px;
}
div#container > div.puzzle:last-child > img {
margin-bottom: 0;
}
</style>
<div id="container"></div>
<script>
var solutions = ['Nf6+', 'Qd5+', 'Qb8+', 'Qd8+', 'Qxg6+', 'Qxd7+', 'Qxf8+', 'Qd7+',
'Qg6+', 'Qxh6+', 'Qg4+', 'Qxh6+', 'Qg6+', 'Rg1+', 'Qxh5+', 'Ne7',
'Qc3+', 'Qf5+', 'Bf6+', 'Qc8+', 'Re8+', 'Rc1+', 'Bf4+', 'Ne6+',
'Qf8+', 'Bf5+', 'Qxc6+', 'Qxb8+', 'Qxd6+', 'Rd8+', 'Nd3+', 'Rxb6+',
'Qxf7+', 'Nf6+', 'Qe7+', 'Rg8+', 'Qxf7+', 'Be3+', 'Nh4+', 'Qxe6+',
'Qf8+', 'Qf6+', 'Nb5+', 'Qxh7+', 'Qxb7+', 'Qg1+', 'Bh6+', 'Rxf6+',
'Qxh6+', 'h5+', 'Nxd7+', 'Rxh2+', 'Bb5+', 'Rg8+', 'Qh8+', 'Bh5+',
'Qh7+', 'Qxh7+', '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qd8+',
'Rxh6+', 'Qg7+', 'Be5+', 'Rxh6+', 'Re4+', 'Nf7+', 'Rxh6+', 'Rf1+', 'Rg8+'
]
for (var i = 0; i < 193; i++) {
var puzzle_wrapper = document.createElement("div")
puzzle_wrapper.className = "puzzle"
var caption = document.createElement("h1")
caption.textContent = "Chess Puzzle #" + i
var solution_wrapper = document.createElement("div")
solution_wrapper.className = "solution_wrapper"
var inner_html = `<h1>Solution: </h1><h1 class="spoiler" data-solution="${solutions[i]}">reveal</h1>`
solution_wrapper.innerHTML = inner_html
var puzzle = document.createElement("img")
puzzle.src = "https://neal.fun/password-game/chess/puzzle" + i + ".svg"
puzzle_wrapper.appendChild(caption)
puzzle_wrapper.appendChild(solution_wrapper)
puzzle_wrapper.appendChild(puzzle)
document.getElementById("container").appendChild(puzzle_wrapper)
}
document.querySelectorAll(".spoiler").forEach(element => {
element.addEventListener("click", function(e) {
this.className = "reveal"
this.innerText = this.dataset.solution
})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment