👀 Reading hidden code
using Chess
👀 Reading hidden code
👀 Reading hidden code
startboard()
Move(a7a6)
Move(b7b6)
Move(c7c6)
Move(d7d6)
Move(e7e6)
Move(f7f6)
Move(g7g6)
Move(h7h6)
Move(a7a5)
Move(b7b5)
Move(c7c5)
Move(d7d5)
Move(e7e5)
Move(f7f5)
Move(g7g5)
Move(h7h5)
Move(b8a6)
Move(b8c6)
Move(g8f6)
Move(g8h6)
👀 Reading hidden code
domove(startboard(), "e4") |> moves
👀 Reading hidden code
using PlutoUI
@bind tick Slider(1:length(xs); show_value=true)
👀 Reading hidden code
b = xs[tick]
👀 Reading hidden code
16pieces(xs[tick], BLACK) |> squarecount
👀 Reading hidden code
16pieces(xs[tick], WHITE) |> squarecount
👀 Reading hidden code
if ischeckmate(b)
md" $(!sidetomove(b)) wins"
elseif isstalemate(b)
"stalemate"
end
👀 Reading hidden code
Base.:(!)(p::PieceColor) = p === BLACK ? WHITE : BLACK
👀 Reading hidden code
Black to move
White to move
Black to move
White to move
Black to move
White to move
Black to move
White to move
Black to move
White to move
xs = try_until_result(random_game)
👀 Reading hidden code
Black to move
x = try_until_result(random_result)
👀 Reading hidden code
trueischeckmate(x)
👀 Reading hidden code
falseisstalemate(x)
👀 Reading hidden code
random_result (generic function with 1 method)function random_result()
board = startboard()
while (next_moves = moves(board); !isempty(next_moves))
choice = rand(next_moves)
board = domove(board, choice)
end
board
end
👀 Reading hidden code
random_game (generic function with 1 method)function random_game()
result = []
board = startboard()
while (next_moves = moves(board); !isempty(next_moves))
choice = rand(next_moves)
board = domove(board, choice)
push!(result, board)
end
result
end
👀 Reading hidden code
try_until_result (generic function with 1 method)function try_until_result(f::Function, args...)
try
f(args...)
catch
try_until_result(f, args...)
end
end
👀 Reading hidden code
Chess move input
👀 Reading hidden code
islegal (generic function with 1 method)islegal(b::Board, m::Move) = m ∈ moves(b)
👀 Reading hidden code
Black to move
your_move_board = try_until_result(random_game)[end-20]
👀 Reading hidden code
Make a move!
👀 Reading hidden code
@bind next_move_raw board_input(your_move_board)
👀 Reading hidden code
missingnext_move_raw
👀 Reading hidden code
squarefromstring (generic function with 1 method)s = squarefromstring
👀 Reading hidden code
MethodError: no method matching getindex(::Missing, ::String)
Here is what happened, the most recent locations are first:
next_move = Move(s(next_move_raw["from"]), s(next_move_raw["to"]))
👀 Reading hidden code
Another cell defining next_move contains errors.
islegal(your_move_board, next_move)
👀 Reading hidden code
Another cell defining next_move contains errors.
Don't panic!
domove(your_move_board, next_move)
👀 Reading hidden code
using HypertextLiteral
👀 Reading hidden code
board_input (generic function with 2 methods)board_input(b=startboard()) = @htl("""
<div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/cm-chessboard@3.10.6/styles/cm-chessboard.css"/>
<script id="this">
const div = currentScript.parentElement
const {INPUT_EVENT_TYPE, COLOR, Chessboard} = await import("https://cdn.jsdelivr.net/npm/cm-chessboard@3.10.6/src/cm-chessboard/Chessboard.js")
function inputHandler(event) {
if (event.type === INPUT_EVENT_TYPE.moveDone) {
const move = {from: event.squareFrom, to: event.squareTo}
div.value = move
div.dispatchEvent(new CustomEvent("input"))
} else {
return true
}
}
const board_div = html`<div id="board" style="max-width: 300px;">
</div>`
const board = new Chessboard(board_div, {
position: $(repr(fen(b))),
sprite: {url: "https://cdn.jsdelivr.net/npm/cm-chessboard@3.10.6/assets/images/chessboard-sprite-staunty.svg"},
orientation: COLOR.white
})
board.enableMoveInput(inputHandler, COLOR.white)
return board_div
</script>
</div>
""")
👀 Reading hidden code
Let's play a game
👀 Reading hidden code
board = Ref(startboard())
👀 Reading hidden code
@initially missing @bind move_raw f(move_raw)
👀 Reading hidden code
f (generic function with 1 method)function f(move_raw)
if move_raw !== missing
move = Move(s(move_raw["from"]), s(move_raw["to"]))
if islegal(board[], move)
# do your move for white
board[] = domove(board[], move)
# do random move for black
board[] = domove(board[], rand(moves(board[])))
end
end
board_input(board[])
end
👀 Reading hidden code
intially_function (generic function with 1 method)👀 Reading hidden code