Skip to content

Commit

Permalink
ノーテンの出現確率を50%に
Browse files Browse the repository at this point in the history
  • Loading branch information
ef81sp committed Jan 20, 2024
1 parent 99772cb commit 7b4652d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
25 changes: 17 additions & 8 deletions src/composables/nanikiruGenerateHand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { 手牌, } from 'pairi'
import { ref } from 'vue'
import * as option from './nanikiruOption'
import { generateRandomMountain } from '../utils/generateHandUtils'
import { generateRandomMountain, randomlyNotenOrTempai } from '../utils/generateHandUtils'

const initialHand = new 手牌([
new ('1s'),
Expand All @@ -28,6 +28,7 @@ export const generateHand = (
range: '1-9' | '2-8' | '3-7' = option.range.value,
waitNum: number = option.waitNum.value,
) => {
const _ramdomlyNotenOrTempai = randomlyNotenOrTempai()
do {
const mountain = generateRandomMountain(suit, range)
const handStr = mountain.slice(0, length)
Expand All @@ -40,22 +41,30 @@ export const generateHand = (
const tehai = new 手牌(handPaiList)
tehai.doツモ(new (mountain[Number(length)]))

if (waitNum === 0) {
// ノーテン以上なのでなんでも返して良い
hand.value = tehai
return hand.value
}

const _analysisResult = tehai.getAnalysisResult14()
if (_analysisResult === null) {
throw new Error('手牌がおかしい')
}

const analysisResult = Array.from(_analysisResult.values())

const minimumShanten = Math.min(
...analysisResult.map(({ analysisResult }) => analysisResult.シャンテン数),
)

if (waitNum === 0) {
// _randomlyNotenOrTempai === 'noten' のときは、シャンテン数が1以上の手牌を返すためやり直し
if (_ramdomlyNotenOrTempai === 'noten' && minimumShanten === 0) {
continue
}
// _randomlyNotenOrTempai === 'tempai' のときは、シャンテン数が0の手牌を返すためやり直し
if (_ramdomlyNotenOrTempai === 'tempai' && minimumShanten !== 0) {
continue
}
hand.value = tehai
return hand.value
}


if (minimumShanten === 0) {
const onlyMinimumShanten = analysisResult.filter(
({ analysisResult }) => analysisResult.シャンテン数 === minimumShanten,
Expand Down
22 changes: 16 additions & 6 deletions src/composables/nanimachiGenerateHand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { 手牌, } from 'pairi'
import { ref } from 'vue'
import * as option from './nanimachiOption'
import { generateRandomMountain } from '../utils/generateHandUtils'
import { generateRandomMountain, randomlyNotenOrTempai } from '../utils/generateHandUtils'

export const handNanimachi = ref<手牌>(
new 手牌([
Expand All @@ -26,6 +26,8 @@ export const generateHandNanimachi = (
range: '1-9' | '2-8' | '3-7' = option.range.value,
waitNum: number = option.waitNum.value,
) => {
const _ramdomlyNotenOrTempai = randomlyNotenOrTempai()

do {
const mountain = generateRandomMountain(suit, range)
const handStr = mountain.slice(0, length)
Expand All @@ -36,16 +38,24 @@ export const generateHandNanimachi = (
: [, , , , , , , , , , , , ]

const tehai = new 手牌(handPaiList)
const analysisResult = tehai.getAnalysisResult13()
if (analysisResult === null) {
throw new Error('手牌がおかしい')
}

if (waitNum === 0) {
// ノーテン以上なのでなんでも返して良い
// _randomlyNotenOrTempai === 'noten' のときは、シャンテン数が1以上の手牌を返すためやり直し
if (_ramdomlyNotenOrTempai === 'noten' && analysisResult.シャンテン数 === 0) {
continue
}
// _randomlyNotenOrTempai === 'tempai' のときは、シャンテン数が0の手牌を返すためやり直し
if (_ramdomlyNotenOrTempai === 'tempai' && analysisResult.シャンテン数 !== 0) {
continue
}
handNanimachi.value = tehai
return handNanimachi.value
}

const analysisResult = tehai.getAnalysisResult13()
if (analysisResult === null) {
throw new Error('手牌がおかしい')
}
if (analysisResult.シャンテン数 === 0) {
if (analysisResult.有効牌.length >= waitNum) {
handNanimachi.value = tehai
Expand Down
9 changes: 9 additions & 0 deletions src/utils/generateHandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ export const filterRange = <T extends Manzu[] | Pinzu[] | Sozu[]>(
) as T
}
}

export const randomlyNotenOrTempai = (): "noten" | "tempai" => {
const random = Math.random()
if (random < 0.5) {
return 'noten'
} else {
return 'tempai'
}
}

0 comments on commit 7b4652d

Please sign in to comment.