Public
Edited
Dec 11, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gameloop = {
if(currentLevel < 4 && correctGuess === true) mutable currentLevel++
if(currentLevel === 4) {
mutable displayBoard = completion
finishGame()
}
yield true;
}
Insert cell
finishGame = () => {
mutable displayBoard = completion
const totalSeconds = ((new Date() - startTime) / 1000).toFixed(2)
const oneWrong = incorrectGuessCount === 1 ? '' : 'es'
const message = `You solved 3 Big Words puzzle #${puzzleIndexReal} in ${totalSeconds} seconds, with ${incorrectGuessCount} incorrect guess${oneWrong}`
mutable finalMessage = message
}
Insert cell
startGame = () => {
mutable startTime = new Date()
mutable puzzleIndexReal = puzzleIndex
mutable currentLevel = 1
mutable finalMessage = ''
mutable incorrectGuessCount = -3
}
Insert cell
completion = ({
n: -1,
game_level: -1,
game_index: -1,
word: 'COMPLETE',
boardstring: 'W_L__E_LD_N__O_E'
})
Insert cell
mutable displayBoard = currentBoard
Insert cell
drawBoard = (board, width) => {
return Plot.plot({
width: width,
height: width,
marks: [
Plot.cell(board, {
// cells
x: "x",
y: "y",
stroke: "black",
strokeWidth: 3,
}),
Plot.cell(board, {
// blanks
x: "x",
y: "y",
filter: (d) => d.letter === "_",
stroke: "black",
fill: "black"
}),
Plot.text(board, {
x: "x",
y: "y",
text: "letter",
fill: "black",
fontSize: width / 10
})
],
x: { type: "band", axis: false, padding: 0 },
y: { type: "band", axis: false, padding: 0 },
})
}
Insert cell
mutable guess = ''
Insert cell
boardFromString = boardstring => boardstring
.split("")
.map((l,i) => ({
x: i % 4,
y: Math.floor(i/4.0) * 4,
letter: l
}))
Insert cell
picks[0]
Insert cell
boardFromString(currentBoard.boardstring)
Insert cell
updateGuess = (str) => mutable guess = str.toUpperCase()
Insert cell
updateGuessCount = (i) => mutable incorrectGuessCount++
Insert cell
correctGuess = guess === currentBoard.word
Insert cell
currentBoard = picks
.filter(x => x.game_index === puzzleIndexReal)
.filter(x => x.game_level === Math.min(currentLevel,3))[0]
Insert cell
mutable startTime = new Date()
Insert cell
mutable puzzleIndexReal = 1
Insert cell
mutable currentLevel = 1
Insert cell
mutable incorrectGuessCount = -3
Insert cell
<style>
.guess {
font-family: 'Courier New', Courier, monospace;
background-color: #D3D3D3;
color: #686868;
padding: 15px 32px;
text-decoration: none;
display: inline-block;
font-size: 36px;
font-weight: bold;
min-width: 600px;
margin: 2px 1px;
cursor: pointer;
text-transform: uppercase;
}
</style>
Insert cell
picks = FileAttachment("picks_data.csv").csv({typed: true})
Insert cell
puzzleIndexMax = Math.max(...picks.map(x=> x.game_index)) - 1
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more