O'Reilly logo

Programming WebAssembly with Rust by Kevin Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Testing Wasm Checkers

Before you can start testing or playing checkers, you need just one more function. You’ve written functions to maintain the game board state, to move player pieces, and even to notify the host when important events occur. What’s missing is the initial set up—placing all of the players’ pieces on the board.

$initBoard is a simple, brute-force function that just calls $setPiece over and over to place the white and black pieces, finally setting the current turn to black:

  ;; Manually place each piece on the board to initialize the game
 (func $initBoard
  ;; Place the white pieces at the top of the board
  (call $setPiece (i32.const 1) (i32.const 0) (i32.const 2))
  (call $setPiece (i32.const 3) (i32.const 0) (i32.const ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required