public void OnClickTipHand() { string cmd = _gameAI.GetPlayCommand(ListPokerInHand, _deck); List <string> listStr = BigTwoCommandQueue.Instance.SplitCMDToList(cmd); List <BigTwoPoker> listPoker = _deck.GetPokerListFromPokerCMDListStr(listStr); for (int i = 0; i < _listPokerInHand.Count; i++) { BigTwoPoker pokerInHand = _listPokerInHand [i]; for (int j = 0; j < listPoker.Count; j++) { BigTwoPoker pokerInTip = listPoker [j]; if (pokerInHand == pokerInTip) { pokerInHand.IsSelected = true; break; } } } }
private int PokerTypeGrade(BigTwoPoker poker) { if (poker._pokerType == BigTwoPoker.TYPE.DIAMONDS) { return(1); } if (poker._pokerType == BigTwoPoker.TYPE.CLUBS) { return(2); } if (poker._pokerType == BigTwoPoker.TYPE.HEARTS) { return(3); } if (poker._pokerType == BigTwoPoker.TYPE.SPADES) { return(4); } return(0); }
// e.g. // listStr: [HEARTS_FIVE HEARTS_SIX] public List <BigTwoPoker> GetPokerListFromPokerCMDListStr(List <string> listStr) { List <BigTwoPoker> listPoker = new List <BigTwoPoker> (); for (int i = 0; i < listStr.Count; i++) { string pokerStr = listStr [i]; string[] pokerData = pokerStr.Split(BigTwoCommandQueue.SPACE_CHAR_POKER); if (pokerData.Length < 2) { continue; } string pokerType = pokerData [0]; string pokerFace = pokerData [1]; BigTwoPoker poker = GetPokerByData(pokerType, pokerFace); if (null != poker) { listPoker.Add(poker); } } return(listPoker); }
public CompareResult IsPokerBigger(BigTwoPoker pokerA, BigTwoPoker pokerB) { int faceA = PokerFaceGrade(pokerA); int faceB = PokerFaceGrade(pokerB); if (faceA > faceB) { return(CompareResult.BIGGER); } if (faceA < faceB) { return(CompareResult.SMALLER); } int typeA = PokerTypeGrade(pokerA); int typeB = PokerTypeGrade(pokerB); if (typeA > typeB) { return(CompareResult.BIGGER); } return(CompareResult.SMALLER); }
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); }
private int PokerStraightFlushGrade(List <BigTwoPoker> list) { int grade = 0; if (list.Count != 5) { return(grade); } BigTwoPoker p1 = list [0]; BigTwoPoker p2 = list [1]; BigTwoPoker p3 = list [2]; BigTwoPoker p4 = list [3]; BigTwoPoker p5 = list [4]; int gradeStraight = PokerStraightGrade(list); int gradeFlower = PokerFlowerGrade(list); if (gradeStraight == 0 || gradeFlower == 0) { return(grade); } grade = gradeFlower; return(grade); }
public void InsertPokerToHand(BigTwoPoker poker) { poker.transform.SetParent(_pokerHandParent); poker.transform.localPosition = new Vector3(0f, 0f, 0); _listPokerInHand.Add(poker); }
protected void GetBiggerSetForThree(WEIGHT weight, ref List <BigTwoPoker> currentSet, List <BigTwoPoker> currentHand, List <BigTwoPoker> lastSet, BigTwoDeck deck) { if (3 != lastSet.Count) { return; } if (lastSet [0]._pokerFace != lastSet [1]._pokerFace || lastSet [0]._pokerFace != lastSet [2]._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) { for (int k = j + 1; k < currentHand.Count; k++) { BigTwoPoker poker3 = currentHand [k]; if (poker1._pokerFace == poker3._pokerFace) { List <BigTwoPoker> listPoker = new List <BigTwoPoker> (); listPoker.Add(poker1); listPoker.Add(poker2); listPoker.Add(poker3); if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsThreeBigger(listPoker, lastSet)) { int insertPos = 0; for (int l = listTargetPair.Count - 1; l >= 0; l--) { List <BigTwoPoker> pairInList = listTargetPair [l]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsThreeBigger(listPoker, pairInList)) { insertPos = l + 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); } }
// Update is called once per frame void Update() { if (_isTouching) { MouseMoveOrientation mouseMoveOrientation = _mouseMoveOrientation; if (Input.mousePosition.x - _lastMousePos.x < 0f) { mouseMoveOrientation = MouseMoveOrientation.LEFTWARD; } else if (Input.mousePosition.x - _lastMousePos.x > 0f) { mouseMoveOrientation = MouseMoveOrientation.RIGHTWARD; } if (_mouseMoveOrientation == MouseMoveOrientation.NONE) { _mouseMoveOrientation = mouseMoveOrientation; } _lastMousePos = Input.mousePosition; if (mouseMoveOrientation != _mouseMoveOrientation) { _mouseMoveOrientation = mouseMoveOrientation; ResetPokerTouchState(true); } BigTwoPoker selectedCollider = null; float minZ = 1000f; Collider2D[] colliders = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition)); if (colliders.Length > 0) { foreach (Collider2D collider in colliders) { if (collider.GetComponent <BigTwoPoker> ()) { if (collider.transform.localPosition.z < minZ) { minZ = collider.transform.localPosition.z; selectedCollider = collider.GetComponent <BigTwoPoker> (); } } } } if (selectedCollider) { BigTwoPoker poker = selectedCollider.GetComponent <BigTwoPoker> (); if (poker.IsTouchEnabled) { bool lastState = poker.IsSelected; poker.IsSelected = !poker.IsSelected; if (lastState != poker.IsSelected) { poker.IsTouchEnabled = false; OnSelectPoker.Invoke(poker); } } } if (_isTouchUp) { ResetPokerTouchState(false); _isTouching = false; } } }
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 GetBiggerSetForPair(WEIGHT weight, ref List <BigTwoPoker> currentSet, List <BigTwoPoker> currentHand, List <BigTwoPoker> lastSet, BigTwoDeck deck) { if (2 != lastSet.Count) { return; } for (int i = 0; i < lastSet.Count - 1; i++) { if (lastSet [i + 1]._pokerFace != lastSet [i]._pokerFace) { 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 (poker1._pokerFace != poker2._pokerFace) { continue; } 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)) { continue; } int insertPos = 0; for (int k = listTarget.Count - 1; k >= 0; k--) { List <BigTwoPoker> pairInList = listTarget [k]; if (BigTwoRule.CompareResult.BIGGER == deck.Rule.IsPairBigger(listPoker, pairInList)) { insertPos = k + 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 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); } }