Mahjong, against Hazel

Hazel activities › Hazel AI opponents · source on GitHub · hazeljs on npm

Hong Kong rules: you against three Hazel players, who sit in turn order to your right, across and to your left. Make a winning hand of four sets and a pair: a set is a chow (three in a row of one suit), a pung (three alike) or a kong (four alike). On your turn you draw (the page does it) and discard: tap a tile, then tap it again. When another player discards, you may claim the tile, to win or to make a pung or a kong, or a chow if you are next. A win counts its faan, and the faan make the points. The deal, the turns, the claims and which comes first, the winning hands, the faan and the points, and what each Hazel player discards and claims, are a Hazel program, shown beside the table.

⏳ Loading Hazel (hazeljs from jsDelivr), whose rules deal, play and score.

    This app needs JavaScript, and a page served over http (python3 -m http.server, then localhost).

    The vocabulary the module sees (mahjong/rules/preamble.hz): a tile is a number from 0 to 33. The listings are text, highlighted, until Edit in Hazel opens each in Hazel's own editor; an edit changes the next step of the game.

    loading preamble.hz…
    Mahjong the deal (the tiles shuffled by the page's random numbers), a turn, the claims on a discard and which comes first, the ways a hand makes a pair and sets, the faan and the points, and the Hazel players: each keeps the tiles that help its hand most, and claims a pung of an honour or of a pair with few neighbours, or the next seat's chow that breaks no pair. The page calls (start, step, options, next_hand).
    loading Mahjong.hz…

    hazeljs-examples · versions · Apache 2.0 (code), CC BY 4.0 (words, the icon) · by Matthew Hammer · an example for hazeljs