Skip to content

Instantly share code, notes, and snippets.

@hogashi
Last active June 8, 2020 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hogashi/e19701da1ff5c2934bab915d695978a7 to your computer and use it in GitHub Desktop.
Save hogashi/e19701da1ff5c2934bab915d695978a7 to your computer and use it in GitHub Desktop.
ランダム麻雀
const allHais = [
'一萬', '二萬', '三萬', '四萬', '五萬', '六萬', '七萬', '八萬', '九萬',
'一筒', '二筒', '三筒', '四筒', '五筒', '六筒', '七筒', '八筒', '九筒',
'一索', '二索', '三索', '四索', '五索', '六索', '七索', '八索', '九索',
'東 ', '南 ', '西 ', '北 ', '白 ', '発 ', '中 ',
] as const;
type HaiName = typeof allHais[number];
type HaiNameArray = HaiName[];
type HaiNameSetForShow = {
upper: string[];
lower: string[];
};
const show = (hais: HaiNameArray): void => {
const { upper, lower }: HaiNameSetForShow = hais.reduce(
(set: HaiNameSetForShow, hai: HaiName) => ({
upper: [...set.upper, hai[0]],
lower: [...set.lower, hai[1]],
}),
{ upper: [], lower: [] }
);
console.log(`${upper.join('')}\n${lower.join('')}`);
};
const [dragon, hiddenDragon, ...tehai] = [...allHais, ...allHais, ...allHais, ...allHais].sort(() => Math.random() - 0.5).slice(0, 16);
show([dragon, hiddenDragon]);
show(tehai.sort((a, b) => allHais.findIndex((v) => v === a) - allHais.findIndex((v) => v === b)));
$ deno run https://gist.githubusercontent.com/hogashi/e19701da1ff5c2934bab915d695978a7/raw/ecb5acc41ce74c1d72486af4a9e4edc88673f302/random-mahjong.ts
七六
萬索
四六八一二三五一三八南白白発
萬萬萬筒筒筒筒索索索
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment