public override string GetPlayCommand(List <BigTwoPoker> currentHand, BigTwoDeck deck) { List <BigTwoPoker> currentSet = new List <BigTwoPoker> (); GeneratePlaySet(ref currentSet, currentHand, deck); string cmd = deck.CombinePokerListToCMD(currentSet); return(cmd); }
private void GetBiggerSet(ref List <BigTwoPoker> currentSet, List <BigTwoPoker> currentHand, List <BigTwoPoker> lastSet, BigTwoDeck deck) { if (1 == lastSet.Count) { GetBiggerSetForSingle(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); return; } if (2 == lastSet.Count) { GetBiggerSetForPair(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); return; } if (3 == lastSet.Count) { GetBiggerSetForThree(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); return; } }
private void GeneratePlaySet(ref List <BigTwoPoker> currentSet, List <BigTwoPoker> currentHand, BigTwoDeck deck) { if (deck.IsFirstPlay() || deck.IsRoundPassed()) { GetBestInHand(ref currentSet, currentHand, deck); return; } List <BigTwoPoker> lastSet = deck.GetLastValidPlayPokerList(); if (0 == lastSet.Count) { return; } GetBiggerSet(ref currentSet, currentHand, lastSet, deck); }
private void GetBestInHand(ref List <BigTwoPoker> currentSet, List <BigTwoPoker> currentHand, BigTwoDeck deck) { currentSet.Add(currentHand [0]); return; }
protected void GetBiggerSetForPair(WEIGHT weight, ref List <BigTwoPoker> currentSet, List <BigTwoPoker> currentHand, List <BigTwoPoker> lastSet, BigTwoDeck deck) { if (2 != lastSet.Count) { return; } if (lastSet [0]._pokerFace != lastSet [1]._pokerFace) { return; } List <List <BigTwoPoker> > listTargetPair = new List <List <BigTwoPoker> > (); for (int i = 0; i < currentHand.Count; i++) { BigTwoPoker poker1 = currentHand [i]; for (int j = i + 1; j < currentHand.Count; j++) { BigTwoPoker poker2 = currentHand [j]; if (poker1._pokerFace == poker2._pokerFace) { List <BigTwoPoker> listPoker = new List <BigTwoPoker> (); listPoker.Add(poker1); listPoker.Add(poker2); // PrintListPoker (listPoker); // PrintListPoker (lastSet); if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsPairBigger(listPoker, lastSet)) { int insertPos = 0; for (int k = listTargetPair.Count - 1; k >= 0; k--) { List <BigTwoPoker> pairInList = listTargetPair [k]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsPairBigger(listPoker, pairInList)) { insertPos = k + 1; break; } } listTargetPair.Insert(insertPos, listPoker); } } } } if (0 == listTargetPair.Count) { return; } int weightIndex = Mathf.RoundToInt((int)weight * 1.0f / (int)WEIGHT.THIRTEEN * listTargetPair.Count) - 1; weightIndex = Mathf.Clamp(weightIndex, 0, listTargetPair.Count - 1); List <BigTwoPoker> targetPair = listTargetPair [weightIndex]; for (int i = 0; i < targetPair.Count; i++) { BigTwoPoker poker = targetPair [i]; currentSet.Add(poker); } }
private void GetBiggerSet(ref List <BigTwoPoker> currentSet, List <BigTwoPoker> currentHand, List <BigTwoPoker> lastSet, BigTwoDeck deck) { if (1 == lastSet.Count) { GetBiggerSetForSingle(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); return; } if (2 == lastSet.Count) { GetBiggerSetForPair(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); return; } if (3 == lastSet.Count) { GetBiggerSetForThree(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); return; } if (5 == lastSet.Count) { List <List <BigTwoPoker> > fiveSet = new List <List <BigTwoPoker> > (); Debug.Log("=====Get Five Set====="); GetFiveSetBigger(ref fiveSet, currentHand, lastSet, deck); for (int i = 0; i < fiveSet.Count; i++) { PrintListPoker(fiveSet [i]); } Debug.Log("=====Get Five Set====="); // TODO GetBiggerSetForStraightFlush(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); if (currentSet.Count == 0) { GetBiggerSetForKingKong(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); } if (currentSet.Count == 0) { GetBiggerSetForFullHouse(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); } if (currentSet.Count == 0) { GetBiggerSetForFlower(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); } if (currentSet.Count == 0) { GetBiggerSetForStraight(WEIGHT.ONE, ref currentSet, currentHand, lastSet, deck); } return; } }
public virtual string GetPlayCommand(List <BigTwoPoker> currentHand, BigTwoDeck deck) { return(null); }
protected void GetBiggerSetForSingle(WEIGHT weight, ref List <BigTwoPoker> currentSet, List <BigTwoPoker> currentHand, List <BigTwoPoker> lastSet, BigTwoDeck deck) { if (1 != lastSet.Count) { return; } BigTwoPoker lastPoker = lastSet [0]; List <BigTwoPoker> listTargetPoker = new List <BigTwoPoker> (); for (int i = 0; i < currentHand.Count; i++) { BigTwoPoker poker = currentHand [i]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsPokerBigger(poker, lastPoker)) { int insertPos = 0; for (int j = listTargetPoker.Count - 1; j >= 0; j--) { BigTwoPoker pokerInList = listTargetPoker [j]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsPokerBigger(poker, pokerInList)) { insertPos = j + 1; break; } } listTargetPoker.Insert(insertPos, poker); } } if (0 == listTargetPoker.Count) { return; } int weightIndex = Mathf.RoundToInt((int)weight * 1.0f / (int)WEIGHT.THIRTEEN * listTargetPoker.Count) - 1; weightIndex = Mathf.Clamp(weightIndex, 0, listTargetPoker.Count - 1); BigTwoPoker targetPoker = listTargetPoker [weightIndex]; currentSet.Add(targetPoker); }
protected void GetStraightFlush(ref List <List <BigTwoPoker> > outputSet, List <BigTwoPoker> currentHand, BigTwoDeck deck) { List <BigTwoPoker> listSortPoker = new List <BigTwoPoker> (); GetListPokerSortByFace(ref listSortPoker, currentHand); List <List <BigTwoPoker> > listTarget = new List <List <BigTwoPoker> > (); for (int i = 0; i < listSortPoker.Count; i++) { BigTwoPoker poker1 = listSortPoker [i]; for (int j = i + 1; j < listSortPoker.Count; j++) { BigTwoPoker poker2 = listSortPoker [j]; if (1 != (poker2._pokerFace - poker1._pokerFace) || poker2._pokerType != poker1._pokerType) { continue; } for (int k = j + 1; k < currentHand.Count; k++) { BigTwoPoker poker3 = currentHand [k]; if (1 != (poker3._pokerFace - poker2._pokerFace) || poker3._pokerType != poker2._pokerType) { continue; } for (int l = k + 1; l < currentHand.Count; l++) { BigTwoPoker poker4 = currentHand [l]; if (1 != (poker4._pokerFace - poker3._pokerFace) || poker4._pokerType != poker3._pokerType) { continue; } for (int m = l + 1; m < currentHand.Count; m++) { BigTwoPoker poker5 = currentHand [m]; if (1 != (poker5._pokerFace - poker4._pokerFace) || poker5._pokerType != poker4._pokerType) { continue; } List <BigTwoPoker> listPoker = new List <BigTwoPoker> (); listPoker.Add(poker1); listPoker.Add(poker2); listPoker.Add(poker3); listPoker.Add(poker4); listPoker.Add(poker5); int insertPos = 0; for (int n = listTarget.Count - 1; n >= 0; n--) { List <BigTwoPoker> target = listTarget [n]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsStraightFlushBigger(listPoker, target)) { insertPos = n + 1; break; } } listTarget.Insert(insertPos, listPoker); } } } } } for (int i = 0; i < listTarget.Count; i++) { List <BigTwoPoker> target = listTarget [i]; outputSet.Add(target); } }
protected void GetFiveSetByType(ref List <List <BigTwoPoker> > outputSet, List <BigTwoPoker> currentHand, List <BigTwoPoker> lastSet, BigTwoDeck deck) { if (IsStraight(lastSet)) { GetStraight(ref outputSet, currentHand, deck); GetFlower(ref outputSet, currentHand, deck); GetFullHouse(ref outputSet, currentHand, deck); GetKingKong(ref outputSet, currentHand, deck); GetStraightFlush(ref outputSet, currentHand, deck); return; } if (IsFlower(lastSet)) { GetFlower(ref outputSet, currentHand, deck); GetFullHouse(ref outputSet, currentHand, deck); GetKingKong(ref outputSet, currentHand, deck); GetStraightFlush(ref outputSet, currentHand, deck); return; } if (IsFullHouse(lastSet)) { GetFullHouse(ref outputSet, currentHand, deck); GetKingKong(ref outputSet, currentHand, deck); GetStraightFlush(ref outputSet, currentHand, deck); return; } if (IsKingKong(lastSet)) { GetKingKong(ref outputSet, currentHand, deck); GetStraightFlush(ref outputSet, currentHand, deck); return; } if (IsStraightFlush(lastSet)) { GetStraightFlush(ref outputSet, currentHand, deck); return; } }
protected void GetKingKong(ref List <List <BigTwoPoker> > outputSet, List <BigTwoPoker> currentHand, BigTwoDeck deck) { List <List <BigTwoPoker> > listFace = new List <List <BigTwoPoker> > (); GetListPokerFace(ref listFace, currentHand); List <List <BigTwoPoker> > listTarget = new List <List <BigTwoPoker> > (); for (int i = 0; i < listFace.Count; i++) { List <BigTwoPoker> listFacePoker = listFace [i]; if (listFacePoker.Count != 4) { continue; } List <BigTwoPoker> listPoker = new List <BigTwoPoker> (); for (int j = 0; j < listFacePoker.Count; j++) { listPoker.Add(listFacePoker [j]); } BigTwoPoker poker5 = null; for (int j = 1; j < 5; j++) { for (int k = 0; k < listFace.Count; k++) { List <BigTwoPoker> listPoker5 = listFace [k]; if (j == listPoker5.Count) { if (k == i) { continue; } poker5 = listPoker5 [0]; break; } } } if (null == poker5) { continue; } listPoker.Add(poker5); int insertPos = 0; for (int n = listTarget.Count - 1; n >= 0; n--) { List <BigTwoPoker> target = listTarget [n]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsKingKongBigger(listPoker, target)) { insertPos = n + 1; break; } } listTarget.Insert(insertPos, listPoker); } for (int i = 0; i < listTarget.Count; i++) { List <BigTwoPoker> target = listTarget [i]; outputSet.Add(target); } }
protected void GetFullHouse(ref List <List <BigTwoPoker> > outputSet, List <BigTwoPoker> currentHand, BigTwoDeck deck) { List <List <BigTwoPoker> > listFace = new List <List <BigTwoPoker> > (); GetListPokerFace(ref listFace, currentHand); List <List <BigTwoPoker> > listTarget = new List <List <BigTwoPoker> > (); for (int i = 0; i < listFace.Count; i++) { List <BigTwoPoker> listFacePoker = listFace [i]; if (listFacePoker.Count < 3) { continue; } List <BigTwoPoker> listPoker = new List <BigTwoPoker> (); for (int j = 0; j < 3; j++) { listPoker.Add(listFacePoker [j]); } List <BigTwoPoker> listPair = new List <BigTwoPoker> (); for (int j = 2; j < 5; j++) { for (int k = 0; k < listFace.Count; k++) { List <BigTwoPoker> listPokerPair = listFace [k]; if (j == listPokerPair.Count) { if (k == i) { continue; } listPair.Add(listPokerPair [0]); listPair.Add(listPokerPair [1]); break; } } } if (0 == listPair.Count) { continue; } listPoker.Add(listPair [0]); listPoker.Add(listPair [1]); int insertPos = 0; for (int n = listTarget.Count - 1; n >= 0; n--) { List <BigTwoPoker> target = listTarget [n]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsFullHouseBigger(listPoker, target)) { insertPos = n + 1; break; } } listTarget.Insert(insertPos, listPoker); } for (int i = 0; i < listTarget.Count; i++) { List <BigTwoPoker> target = listTarget [i]; outputSet.Add(target); } }
protected void GetFlower(ref List <List <BigTwoPoker> > outputSet, List <BigTwoPoker> currentHand, BigTwoDeck deck) { List <List <BigTwoPoker> > listType = new List <List <BigTwoPoker> > (); GetListPokerType(ref listType, currentHand); List <List <BigTwoPoker> > listTarget = new List <List <BigTwoPoker> > (); for (int i = 0; i < listType.Count; i++) { List <BigTwoPoker> listTypePoker = listType [i]; if (listTypePoker.Count < 5) { continue; } List <BigTwoPoker> listPoker = new List <BigTwoPoker> (); for (int j = 0; j <= listTypePoker.Count - 5; j++) { for (int k = j; k < j + 5; k++) { listPoker.Add(listTypePoker [k]); } } int insertPos = 0; for (int n = listTarget.Count - 1; n >= 0; n--) { List <BigTwoPoker> target = listTarget [n]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsFlowerBigger(listPoker, target)) { insertPos = n + 1; break; } } listTarget.Insert(insertPos, listPoker); } for (int i = 0; i < listTarget.Count; i++) { List <BigTwoPoker> target = listTarget [i]; outputSet.Add(target); } }
protected void GetBiggerSetForStraightFlush(WEIGHT weight, ref List <BigTwoPoker> currentSet, List <BigTwoPoker> currentHand, List <BigTwoPoker> lastSet, BigTwoDeck deck) { if (5 != lastSet.Count) { return; } for (int i = 0; i < lastSet.Count - 1; i++) { BigTwoPoker poker1 = lastSet [i]; BigTwoPoker poker2 = lastSet [i + 1]; if (1 != (poker2._pokerFace - poker1._pokerFace) || poker2._pokerType != poker1._pokerType) { return; } } List <List <BigTwoPoker> > listTarget = new List <List <BigTwoPoker> > (); for (int i = 0; i < currentHand.Count; i++) { BigTwoPoker poker1 = currentHand [i]; for (int j = i + 1; j < currentHand.Count; j++) { BigTwoPoker poker2 = currentHand [j]; if (1 != (poker2._pokerFace - poker1._pokerFace) || poker2._pokerType != poker1._pokerType) { continue; } for (int k = j + 1; k < currentHand.Count; k++) { BigTwoPoker poker3 = currentHand [k]; if (1 != (poker3._pokerFace - poker2._pokerFace) || poker3._pokerType != poker2._pokerType) { continue; } for (int l = k + 1; l < currentHand.Count; l++) { BigTwoPoker poker4 = currentHand [l]; if (1 != (poker4._pokerFace - poker3._pokerFace) || poker4._pokerType != poker3._pokerType) { continue; } for (int m = l + 1; m < currentHand.Count; m++) { BigTwoPoker poker5 = currentHand [m]; if (1 != (poker5._pokerFace - poker4._pokerFace) || poker5._pokerType != poker4._pokerType) { continue; } List <BigTwoPoker> listPoker = new List <BigTwoPoker> (); listPoker.Add(poker1); listPoker.Add(poker2); listPoker.Add(poker3); listPoker.Add(poker4); listPoker.Add(poker5); if (BigTwoRule.CompareResult.BIGGER != deck.Rule.IsStraightFlushBigger(listPoker, lastSet)) { continue; } int insertPos = 0; for (int n = listTarget.Count - 1; n >= 0; n--) { List <BigTwoPoker> pairInList = listTarget [n]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsStraightFlushBigger(listPoker, pairInList)) { insertPos = n + 1; break; } } listTarget.Insert(insertPos, listPoker); } } } } } if (0 == listTarget.Count) { return; } int weightIndex = Mathf.RoundToInt((int)weight * 1.0f / (int)WEIGHT.THIRTEEN * listTarget.Count) - 1; weightIndex = Mathf.Clamp(weightIndex, 0, listTarget.Count - 1); List <BigTwoPoker> targetPair = listTarget [weightIndex]; for (int i = 0; i < targetPair.Count; i++) { BigTwoPoker poker = targetPair [i]; currentSet.Add(poker); } }
protected void GetFiveSetBigger(ref List <List <BigTwoPoker> > outputSet, List <BigTwoPoker> currentHand, List <BigTwoPoker> lastSet, BigTwoDeck deck) { List <List <BigTwoPoker> > fiveSet = new List <List <BigTwoPoker> > (); GetFiveSetByType(ref fiveSet, currentHand, lastSet, deck); for (int i = 0; i < fiveSet.Count; i++) { List <BigTwoPoker> listPoker = fiveSet [i]; // if (IsStraightFlush (listPoker)) { // } // if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsStraightFlushBigger (listPoker, lastSet)) { // } } }