public int DetermineAllPairsShanten(out HandInfo allPairsHand) { allPairsHand = new HandInfo(remainingTiles); int numberOfPairs = 0; List <Tile> pairTiles = new List <Tile>(); for (int tile = 0; tile < remainingTiles.Count; tile++) { if (tile == remainingTiles.Count - 1 && !pairTiles.Contains(remainingTiles[tile])) { allPairsHand.isolatedTiles.Add(remainingTiles[tile]); break; } else if (tile == remainingTiles.Count - 1 && pairTiles.Contains(remainingTiles[tile])) { break; } if (remainingTiles[tile] == remainingTiles[tile + 1] && !pairTiles.Contains(remainingTiles[tile])) { tile++; numberOfPairs++; pairTiles.Add(remainingTiles[tile]); } else if (!pairTiles.Contains(remainingTiles[tile])) { allPairsHand.isolatedTiles.Add(remainingTiles[tile]); } } allPairsHand.allPairs = true; allPairsHand.shanten = 6 - numberOfPairs; return(6 - numberOfPairs); }
public BestHandsCalculator(List <Tile> tiles) { _startingHand = new HandInfo(tiles); _bestHands = new List <HandInfo>(); _bestShanten = 99; DetermineBestHands(); }
public void CheckIsolatedTile(Tile tile, out HandInfo newPossibleHand) { List <Tile> newTiles = new List <Tile>(remainingTiles); newTiles.Remove(tile); List <Tile> newIsolatedTiles = new List <Tile>(isolatedTiles); newIsolatedTiles.Add(tile); newPossibleHand = new HandInfo(newTiles, numberOfMelds, unfinishedMelds, newIsolatedTiles, hasPair, shanten, maxShanten, impossibleTilesToDraw); }
public void CheckChi(Tile tile, out HandInfo newPossibleHand) { if (remainingTiles.Contains(tile.Next()) && remainingTiles.Contains(tile.Next().Next())) { List <Tile> newTiles = new List <Tile>(remainingTiles); newTiles.Remove(tile); newTiles.Remove(tile.Next()); newTiles.Remove(tile.Next().Next()); newPossibleHand = new HandInfo(newTiles, numberOfMelds + 1, unfinishedMelds, isolatedTiles, hasPair, shanten, maxShanten, impossibleTilesToDraw); } else { newPossibleHand = null; } }
public void CheckUnfinishedChiOne(Tile tile, out HandInfo newPossibleHand) { if (remainingTiles.Contains(tile.Next()) && !impossibleTilesToDraw.Contains(tile)) { List <Tile> newTiles = new List <Tile>(remainingTiles); List <Tile[]> newUnfinishedMelds = new List <Tile[]>(unfinishedMelds); newUnfinishedMelds.Add(new Tile[] { tile, tile.Next() }); newTiles.Remove(tile); newTiles.Remove(tile.Next()); newPossibleHand = new HandInfo(newTiles, numberOfMelds, newUnfinishedMelds, isolatedTiles, hasPair, shanten, maxShanten, impossibleTilesToDraw); } else { newPossibleHand = null; } }
public void CheckPair(Tile tile, out HandInfo newPossibleHand) { if (remainingTiles.IndexOf(tile) != remainingTiles.LastIndexOf(tile)) { int indexOne = remainingTiles.IndexOf(tile); int indexTwo = remainingTiles.LastIndexOf(tile); List <Tile> newTiles = new List <Tile>(remainingTiles); newTiles.RemoveAt(indexTwo); newTiles.RemoveAt(indexOne); newPossibleHand = new HandInfo(newTiles, numberOfMelds, unfinishedMelds, isolatedTiles, true, shanten, maxShanten, impossibleTilesToDraw); } else { newPossibleHand = null; } }
public void CheckUnfinishedPon(Tile tile, out HandInfo newPossibleHand) { if (remainingTiles.IndexOf(tile) != remainingTiles.LastIndexOf(tile) && !impossibleTilesToDraw.Contains(tile)) { int indexOne = remainingTiles.IndexOf(tile); int indexTwo = remainingTiles.LastIndexOf(tile); List <Tile> newTiles = new List <Tile>(remainingTiles); List <Tile[]> newUnfinishedMelds = new List <Tile[]>(unfinishedMelds); newUnfinishedMelds.Add(new Tile[] { remainingTiles[indexOne], remainingTiles[indexTwo] }); newTiles.RemoveAt(indexTwo); newTiles.RemoveAt(indexOne); newPossibleHand = new HandInfo(newTiles, numberOfMelds, newUnfinishedMelds, isolatedTiles, hasPair, shanten, maxShanten, impossibleTilesToDraw); } else { newPossibleHand = null; } }
public int DetermineKokushiShanten(out HandInfo kokushiHand) { kokushiHand = new HandInfo(remainingTiles); kokushiHand.kokushi = true; if (kokushiHand.remainingTiles.Count >= 13) { int answer = 13; for (int i = kokushiHand.remainingTiles.Count - 1; i >= 0; i--) { if (!kokushiHand.remainingTiles[i].IsKokushiRelated) { kokushiHand.isolatedTiles.Add(kokushiHand.remainingTiles[i]); kokushiHand.remainingTiles.RemoveAt(i); } } if (kokushiHand.IsThereAnyKokushiPair()) { kokushiHand.hasPair = true; answer--; } kokushiHand.remainingTiles = RemoveAllDoubles(kokushiHand.remainingTiles); answer -= kokushiHand.remainingTiles.Count; kokushiHand.shanten = answer; return(answer); } else { for (int tile = 0; tile < kokushiHand.remainingTiles.Count; tile++) { kokushiHand.isolatedTiles.Add(kokushiHand.remainingTiles[tile]); } kokushiHand.remainingTiles.Clear(); return(int.MaxValue); } }
private void DetermineBestHands() { Queue shantenCounterQueue = new Queue(); HandInfo allPairsHand = null; int shantenPairs = 100; if (_startingHand.remainingTiles.Count >= 13) { shantenPairs = _startingHand.DetermineAllPairsShanten(out allPairsHand); } HandInfo kokushiHand = null; int shantenKokushi = 100; if (_startingHand.remainingTiles.Count >= 13) { shantenKokushi = _startingHand.DetermineKokushiShanten(out kokushiHand); } if (shantenPairs <= _bestShanten) { _bestShanten = shantenPairs; _bestHands.Add(allPairsHand); } if (shantenKokushi < _bestShanten) { _bestShanten = shantenKokushi; _bestHands.Clear(); _bestHands.Add(kokushiHand); } if (shantenKokushi == _bestShanten) { _bestHands.Add(kokushiHand); } if (_startingHand.remainingTiles.Count != 14) { switch (_startingHand.remainingTiles.Count) { case 11: _startingHand.numberOfMelds = 1; break; case 8: _startingHand.numberOfMelds = 2; break; case 5: _startingHand.numberOfMelds = 3; break; case 2: _startingHand.numberOfMelds = 4; break; } } shantenCounterQueue.Enqueue(_startingHand); do { var currentHand = (HandInfo)shantenCounterQueue.Dequeue(); if (_bestHands.Count > 0 && currentHand.isolatedTiles.Count > _bestHands[_bestHands.Count - 1].isolatedTiles.Count + 1) //NOT SURE ABOUT THIS ONE.? { continue; } int currentHandShanten; var newPossibleHands = new List <HandInfo>(); if (currentHand.remainingTiles.Count != 0) { currentHand.ElaborateHand(out newPossibleHands, out currentHandShanten); } else { currentHand.DetermineShanten(); currentHandShanten = currentHand.shanten; } if (currentHandShanten < _bestShanten && currentHand.remainingTiles.Count == 0) { _bestShanten = currentHandShanten; _bestHands.Clear(); _bestHands.Add(currentHand); } else if (currentHandShanten == _bestShanten && currentHand.remainingTiles.Count == 0) { _bestHands.Add(currentHand); } if (newPossibleHands != null) { foreach (var hand in newPossibleHands) { shantenCounterQueue.Enqueue(hand); } } }while (shantenCounterQueue.Count != 0); }