/// This is the representation of a place on a chess board.
/// It can be empty (None) or contain a piece with a color: Some((piece, color)).
pub
typealias BoardPlace =
Option
[(Piece, Color)]
通过这种定义方式,在代码中任何位置,我们都可以用
BoardPlace
代替对应的
Option
类型,反之亦然。这只是右侧类型定义的简化表达方式。另外,值得注意的是,
Option
数据类型内置于MoonBit语言的标准库中,与Rust和Scala类似。MoonBit还内置了
Result
数据类型,它与Scala中的
Either
类型类似,但更专注于错误处理。
/// This is a struct that represents a row in the board pubstructRow { // Array type definition: priv cols: Array[BoardPlace] // information hiding: private fields } derive(Show, Eq)
再定义整个棋盘(Board)的网格结构以及棋盘当前的状态(BoardState):
/// This is a struct that represents the board grid pubstructBoard { priv grid: Array[Row] }
/// This is a struct that represents the board state pubstructBoardState