Last active
August 27, 2024 08:43
-
-
Save redpeacock78/30ccf9969a20c29e16e16791aec787c7 to your computer and use it in GitHub Desktop.
麻雀の得点計算(満貫打ち切り)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 切り上げ用関数 | |
| const roundUp = (val: number, base: number): number => | |
| Math.ceil(val / base) * base; | |
| // 翻数と符数 | |
| const hanArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]; | |
| const fuArray = [20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 110]; | |
| const matrix: number[][] = hanArray.flatMap((han: number): number[][] => | |
| fuArray.map((fu: number): number[] => [han, fu]) | |
| ); | |
| // 基本点の算出 | |
| const basicCalc = (conb: number[]): number => 2 ** (conb[0] + 2) * conb[1]; | |
| const basicResult: { [key: string]: { [key: string]: number } } = {}; | |
| matrix.forEach((comb: number[]): void => { | |
| const han = `${comb[0]}翻`; | |
| const fu = `${comb[1]}符`; | |
| if (!basicResult[han]) basicResult[han] = {}; | |
| switch (comb[0]) { | |
| // 3翻70符以上は満貫扱い | |
| case 3: | |
| comb[1] >= 70 | |
| ? (basicResult[han][fu] = 2000) | |
| : (basicResult[han][fu] = basicCalc(comb)); | |
| break; | |
| // 4翻40符以上は満貫扱い | |
| case 4: | |
| comb[1] >= 40 | |
| ? (basicResult[han][fu] = 2000) | |
| : (basicResult[han][fu] = basicCalc(comb)); | |
| break; | |
| // 5翻は満貫 | |
| case 5: | |
| basicResult[han][fu] = 2000; | |
| break; | |
| // 6翻、7翻は跳満 | |
| case 6: | |
| case 7: | |
| basicResult[han][fu] = 3000; | |
| break; | |
| // 8翻、9翻、10翻は倍満 | |
| case 8: | |
| case 9: | |
| case 10: | |
| basicResult[han][fu] = 4000; | |
| break; | |
| // 11翻、12翻は三倍満 | |
| case 11: | |
| case 12: | |
| basicResult[han][fu] = 6000; | |
| break; | |
| // 13翻は役満 | |
| case 13: | |
| basicResult[han][fu] = 8000; | |
| break; | |
| default: | |
| basicResult[han][fu] = basicCalc(comb); | |
| } | |
| }); | |
| // 親の点の算出 | |
| const parentResult: { [key: string]: { [key: string]: string } } = {}; | |
| Object.keys(basicResult).forEach((key: string): void => { | |
| parentResult[key] = Object.fromEntries( | |
| Object.entries(basicResult[key]).map( | |
| ([key, val]: [string, number]): [string, string] => { | |
| const result: number = roundUp(val * 2, 100); | |
| return [key, `${result * 3}(${result}All)`]; | |
| } | |
| ) | |
| ); | |
| }); | |
| // 子の点の算出 | |
| const childResult: { [key: string]: { [key: string]: string } } = {}; | |
| Object.keys(basicResult).forEach((key: string): void => { | |
| childResult[key] = Object.fromEntries( | |
| Object.entries(basicResult[key]).map( | |
| ([key, val]: [string, number]): [string, string] => { | |
| const child: number = roundUp(val, 100); | |
| const parent: number = roundUp(val * 2, 100); | |
| const result: number = child * 2 + parent; | |
| return [key, `${result}(${child}/${parent})`]; | |
| } | |
| ) | |
| ); | |
| }); | |
| const totalResult = { | |
| 親: parentResult, | |
| 子: childResult, | |
| }; | |
| console.log(totalResult); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Command
Result
{ "親": { "0翻": { "20符": "600(200All)", "25符": "600(200All)", "30符": "900(300All)", "40符": "1200(400All)", "50符": "1200(400All)", "60符": "1500(500All)", "70符": "1800(600All)", "80符": "2100(700All)", "90符": "2400(800All)", "100符": "2400(800All)", "110符": "2700(900All)" }, "1翻": { "20符": "1200(400All)", "25符": "1200(400All)", "30符": "1500(500All)", "40符": "2100(700All)", "50符": "2400(800All)", "60符": "3000(1000All)", "70符": "3600(1200All)", "80符": "3900(1300All)", "90符": "4500(1500All)", "100符": "4800(1600All)", "110符": "5400(1800All)" }, "2翻": { "20符": "2100(700All)", "25符": "2400(800All)", "30符": "3000(1000All)", "40符": "3900(1300All)", "50符": "4800(1600All)", "60符": "6000(2000All)", "70符": "6900(2300All)", "80符": "7800(2600All)", "90符": "8700(2900All)", "100符": "9600(3200All)", "110符": "10800(3600All)" }, "3翻": { "20符": "3900(1300All)", "25符": "4800(1600All)", "30符": "6000(2000All)", "40符": "7800(2600All)", "50符": "9600(3200All)", "60符": "11700(3900All)", "70符": "12000(4000All)", "80符": "12000(4000All)", "90符": "12000(4000All)", "100符": "12000(4000All)", "110符": "12000(4000All)" }, "4翻": { "20符": "7800(2600All)", "25符": "9600(3200All)", "30符": "11700(3900All)", "40符": "12000(4000All)", "50符": "12000(4000All)", "60符": "12000(4000All)", "70符": "12000(4000All)", "80符": "12000(4000All)", "90符": "12000(4000All)", "100符": "12000(4000All)", "110符": "12000(4000All)" }, "5翻": { "20符": "12000(4000All)", "25符": "12000(4000All)", "30符": "12000(4000All)", "40符": "12000(4000All)", "50符": "12000(4000All)", "60符": "12000(4000All)", "70符": "12000(4000All)", "80符": "12000(4000All)", "90符": "12000(4000All)", "100符": "12000(4000All)", "110符": "12000(4000All)" }, "6翻": { "20符": "18000(6000All)", "25符": "18000(6000All)", "30符": "18000(6000All)", "40符": "18000(6000All)", "50符": "18000(6000All)", "60符": "18000(6000All)", "70符": "18000(6000All)", "80符": "18000(6000All)", "90符": "18000(6000All)", "100符": "18000(6000All)", "110符": "18000(6000All)" }, "7翻": { "20符": "18000(6000All)", "25符": "18000(6000All)", "30符": "18000(6000All)", "40符": "18000(6000All)", "50符": "18000(6000All)", "60符": "18000(6000All)", "70符": "18000(6000All)", "80符": "18000(6000All)", "90符": "18000(6000All)", "100符": "18000(6000All)", "110符": "18000(6000All)" }, "8翻": { "20符": "24000(8000All)", "25符": "24000(8000All)", "30符": "24000(8000All)", "40符": "24000(8000All)", "50符": "24000(8000All)", "60符": "24000(8000All)", "70符": "24000(8000All)", "80符": "24000(8000All)", "90符": "24000(8000All)", "100符": "24000(8000All)", "110符": "24000(8000All)" }, "9翻": { "20符": "24000(8000All)", "25符": "24000(8000All)", "30符": "24000(8000All)", "40符": "24000(8000All)", "50符": "24000(8000All)", "60符": "24000(8000All)", "70符": "24000(8000All)", "80符": "24000(8000All)", "90符": "24000(8000All)", "100符": "24000(8000All)", "110符": "24000(8000All)" }, "10翻": { "20符": "24000(8000All)", "25符": "24000(8000All)", "30符": "24000(8000All)", "40符": "24000(8000All)", "50符": "24000(8000All)", "60符": "24000(8000All)", "70符": "24000(8000All)", "80符": "24000(8000All)", "90符": "24000(8000All)", "100符": "24000(8000All)", "110符": "24000(8000All)" }, "11翻": { "20符": "36000(12000All)", "25符": "36000(12000All)", "30符": "36000(12000All)", "40符": "36000(12000All)", "50符": "36000(12000All)", "60符": "36000(12000All)", "70符": "36000(12000All)", "80符": "36000(12000All)", "90符": "36000(12000All)", "100符": "36000(12000All)", "110符": "36000(12000All)" }, "12翻": { "20符": "36000(12000All)", "25符": "36000(12000All)", "30符": "36000(12000All)", "40符": "36000(12000All)", "50符": "36000(12000All)", "60符": "36000(12000All)", "70符": "36000(12000All)", "80符": "36000(12000All)", "90符": "36000(12000All)", "100符": "36000(12000All)", "110符": "36000(12000All)" }, "13翻": { "20符": "48000(16000All)", "25符": "48000(16000All)", "30符": "48000(16000All)", "40符": "48000(16000All)", "50符": "48000(16000All)", "60符": "48000(16000All)", "70符": "48000(16000All)", "80符": "48000(16000All)", "90符": "48000(16000All)", "100符": "48000(16000All)", "110符": "48000(16000All)" } }, "子": { "0翻": { "20符": "400(100/200)", "25符": "400(100/200)", "30符": "700(200/300)", "40符": "800(200/400)", "50符": "800(200/400)", "60符": "1100(300/500)", "70符": "1200(300/600)", "80符": "1500(400/700)", "90符": "1600(400/800)", "100符": "1600(400/800)", "110符": "1900(500/900)" }, "1翻": { "20符": "800(200/400)", "25符": "800(200/400)", "30符": "1100(300/500)", "40符": "1500(400/700)", "50符": "1600(400/800)", "60符": "2000(500/1000)", "70符": "2400(600/1200)", "80符": "2700(700/1300)", "90符": "3100(800/1500)", "100符": "3200(800/1600)", "110符": "3600(900/1800)" }, "2翻": { "20符": "1500(400/700)", "25符": "1600(400/800)", "30符": "2000(500/1000)", "40符": "2700(700/1300)", "50符": "3200(800/1600)", "60符": "4000(1000/2000)", "70符": "4700(1200/2300)", "80符": "5200(1300/2600)", "90符": "5900(1500/2900)", "100符": "6400(1600/3200)", "110符": "7200(1800/3600)" }, "3翻": { "20符": "2700(700/1300)", "25符": "3200(800/1600)", "30符": "4000(1000/2000)", "40符": "5200(1300/2600)", "50符": "6400(1600/3200)", "60符": "7900(2000/3900)", "70符": "8000(2000/4000)", "80符": "8000(2000/4000)", "90符": "8000(2000/4000)", "100符": "8000(2000/4000)", "110符": "8000(2000/4000)" }, "4翻": { "20符": "5200(1300/2600)", "25符": "6400(1600/3200)", "30符": "7900(2000/3900)", "40符": "8000(2000/4000)", "50符": "8000(2000/4000)", "60符": "8000(2000/4000)", "70符": "8000(2000/4000)", "80符": "8000(2000/4000)", "90符": "8000(2000/4000)", "100符": "8000(2000/4000)", "110符": "8000(2000/4000)" }, "5翻": { "20符": "8000(2000/4000)", "25符": "8000(2000/4000)", "30符": "8000(2000/4000)", "40符": "8000(2000/4000)", "50符": "8000(2000/4000)", "60符": "8000(2000/4000)", "70符": "8000(2000/4000)", "80符": "8000(2000/4000)", "90符": "8000(2000/4000)", "100符": "8000(2000/4000)", "110符": "8000(2000/4000)" }, "6翻": { "20符": "12000(3000/6000)", "25符": "12000(3000/6000)", "30符": "12000(3000/6000)", "40符": "12000(3000/6000)", "50符": "12000(3000/6000)", "60符": "12000(3000/6000)", "70符": "12000(3000/6000)", "80符": "12000(3000/6000)", "90符": "12000(3000/6000)", "100符": "12000(3000/6000)", "110符": "12000(3000/6000)" }, "7翻": { "20符": "12000(3000/6000)", "25符": "12000(3000/6000)", "30符": "12000(3000/6000)", "40符": "12000(3000/6000)", "50符": "12000(3000/6000)", "60符": "12000(3000/6000)", "70符": "12000(3000/6000)", "80符": "12000(3000/6000)", "90符": "12000(3000/6000)", "100符": "12000(3000/6000)", "110符": "12000(3000/6000)" }, "8翻": { "20符": "16000(4000/8000)", "25符": "16000(4000/8000)", "30符": "16000(4000/8000)", "40符": "16000(4000/8000)", "50符": "16000(4000/8000)", "60符": "16000(4000/8000)", "70符": "16000(4000/8000)", "80符": "16000(4000/8000)", "90符": "16000(4000/8000)", "100符": "16000(4000/8000)", "110符": "16000(4000/8000)" }, "9翻": { "20符": "16000(4000/8000)", "25符": "16000(4000/8000)", "30符": "16000(4000/8000)", "40符": "16000(4000/8000)", "50符": "16000(4000/8000)", "60符": "16000(4000/8000)", "70符": "16000(4000/8000)", "80符": "16000(4000/8000)", "90符": "16000(4000/8000)", "100符": "16000(4000/8000)", "110符": "16000(4000/8000)" }, "10翻": { "20符": "16000(4000/8000)", "25符": "16000(4000/8000)", "30符": "16000(4000/8000)", "40符": "16000(4000/8000)", "50符": "16000(4000/8000)", "60符": "16000(4000/8000)", "70符": "16000(4000/8000)", "80符": "16000(4000/8000)", "90符": "16000(4000/8000)", "100符": "16000(4000/8000)", "110符": "16000(4000/8000)" }, "11翻": { "20符": "24000(6000/12000)", "25符": "24000(6000/12000)", "30符": "24000(6000/12000)", "40符": "24000(6000/12000)", "50符": "24000(6000/12000)", "60符": "24000(6000/12000)", "70符": "24000(6000/12000)", "80符": "24000(6000/12000)", "90符": "24000(6000/12000)", "100符": "24000(6000/12000)", "110符": "24000(6000/12000)" }, "12翻": { "20符": "24000(6000/12000)", "25符": "24000(6000/12000)", "30符": "24000(6000/12000)", "40符": "24000(6000/12000)", "50符": "24000(6000/12000)", "60符": "24000(6000/12000)", "70符": "24000(6000/12000)", "80符": "24000(6000/12000)", "90符": "24000(6000/12000)", "100符": "24000(6000/12000)", "110符": "24000(6000/12000)" }, "13翻": { "20符": "32000(8000/16000)", "25符": "32000(8000/16000)", "30符": "32000(8000/16000)", "40符": "32000(8000/16000)", "50符": "32000(8000/16000)", "60符": "32000(8000/16000)", "70符": "32000(8000/16000)", "80符": "32000(8000/16000)", "90符": "32000(8000/16000)", "100符": "32000(8000/16000)", "110符": "32000(8000/16000)" } } }