dnovikoff/tempai-core

Can it correctly calculate the shanten for less than 13 tiles case?

luooooob opened this issue · 3 comments

thank you for this go package. I have two problems with it.

  1. how can I get the right shanten value for less than 13 tiles case? the same case in tempai.net is right, "11223m55p1z" best drop is 1z, shanten value is 0, but use these package, it got 5, all less than 13 tiles case will get the wrong answer.
  2. I found that when tenhon and tempai.net calculate the effective, If there is 3n+1 tiles in hand, it will be completed to 3n+2, but effective.Calculate() won't do that, it will get a wrong answer with 3n+1 tiles. Does anyone need the effective with 3n+1 tiles? if I want to completed the 3n+2nd tile, what rule should I use ?

Hi! Thanks for the interest to the package

  1. For calculating shanten for less than 13 tiles, use calc.Opened option. You should tell the calculator the number of melds opened. Find the example at TestCalculatorShanten test. For example for calculating shanten for 10 tiles you should use calc.Opened(1), for 7 tiles use calc.Opened(2), etc...
  2. For filling the missing tiles, you should add some code, because the calculator is not responsible for adding random tiles.
    Here is some code from temapi.net
        missing := 14 - l
	need := missing
	if missing != 14 {
		this.opened = missing / 3
		need = missing % 3
	}
	if need > 0 {
		free := summary.CopyFree(compact.AllTiles)
		if free.CountBits() < need {
			return common.NewBadRequestError("Not enought tiles")
		}
		rnd := getRand()
		wall := free.Instances()
		rnd.Shuffle(len(wall), func(i, j int) {
			wall[i], wall[j] = wall[j], wall[i]
		})
		hand := tile.Instances(wall[:need]).Tiles()
		sort.Sort(hand)
		this.Hand = this.Hand.Append(hand)
	}

thank you, it works!
I did not notice that the calculate function can accept the option parameter when I look at the source code, I think it should be reminded on the README.

Thanks for the note. I will probably add some notes on that and add comments to the code