//加入中獎支付表項目 public void AddCombinationItem(CombinationPrizeInfo Item) { sumPrize += Item.prizeMoney; PrizeItemList.Add(Item); }
//中獎判定 //[output] List<PrizeInfo> = 中獎資訊列表 //[param] sensorInfo = 位置偵測器資訊(各座標上對應的圖格類型) , prizeTable = 支付表設定 public PrizeLineInfo RewardJudgement(List <SensorInfo> sensorInfo, List <PrizeCombination> prizeTableSource) { PrizeLineInfo _resultList = new PrizeLineInfo(); if (level == 0 || !isWorking) { return(null); //中獎線等級為0 或 線段未啟用 則不計算中獎 } List <ElementImageType> _imageLine = new List <ElementImageType>(); //線上的圖格類型 for (int i = 0; i < coordinates.Count; i++) //遍歷線上所有點的座標 { for (int j = 0; j < sensorInfo.Count; j++) //遍歷所有圖格資訊 { if (sensorInfo[j].coordinate == coordinates[i]) //取得指定位置上的圖格 { _imageLine.Add(sensorInfo[j].elementType); continue; } } } if (_imageLine.Count != coordinates.Count) { throw new System.Exception("[ERROR]線段各點座標與圖格位置座標不完全一致"); } //for (int i = 0; i < _imageLine.Count; i++) //{ // Debug.Log(string.Format("({0}, {1}) : {2}", coordinates[i].x, coordinates[i].y, _imageLine[i])); //} List <PrizeCombination> prizeTable = new List <PrizeCombination>(); prizeTable.AddRange(prizeTableSource); //排序支付表組合(組合長度多排到少) prizeTable.Sort((PrizeCombination x, PrizeCombination y) => { if (x.combinations.Count > y.combinations.Count) { return(-1); } if (x.combinations.Count < y.combinations.Count) { return(1); } return(0); }); List <PrizeCombination> _drawedCombs = new List <PrizeCombination>(); //判定成功(有中獎)的支付表組合 //Debug.Log("[ 線段 " + this.gameObject.name + " 開始判斷]"); for (int i = 0; i < prizeTable.Count; i++) //逐一檢查支付表所有組合 { bool _isMatch = false; //任一項有符合(淺層判斷) bool _matchPass = false; //跳過淺層判斷 for (int j = 0; j < _imageLine.Count; j++) //若線上有任一狂野符號, 直接進入深層判斷(中獎判斷) { if (ScrollManager.Instance.Dict_wildSymbol[_imageLine[j]]) { _matchPass = true; _isMatch = true; break; } } if (!_matchPass) //沒有狂野符號時, 檢測線上所有圖格是否有任意一項與支付表組合圖格相符(淺層判斷) { if (prizeTable[i].PureTest()) //若組合為純元素構成(只輸入一個圖格類型, 節省遍歷時間) { _isMatch = ElementListMatchTest(_imageLine, new List <ElementImageType>() { prizeTable[i].combinations[0] }); } else //若組合為混和元素構成 { _isMatch = ElementListMatchTest(_imageLine, prizeTable[i].combinations); } } if (_isMatch) //若有任意一項圖格相符時, 深入判斷中獎與否 { int _prize = 0; //中獎獎金 for (int j = 0; j < _drawedCombs.Count; j++) //判斷中獎的組合是否包含此組合 { _prize += prizeTable[i].Comparison(_drawedCombs[j].combinations).prizeMoney; } if (_prize == 0) //已經中獎的組合如果有包含此組合, 則跳過此組合的判斷, 避免重複中獎 { CombinationPrizeInfo _cbInfo = prizeTable[i].Comparison(_imageLine); //取得中獎資訊 if (_cbInfo.prizeMoney > 0) //若獎金大於0(有中獎) { _drawedCombs.Add(prizeTable[i]); //加入判定成功組合列表 for (int j = 0; j < _cbInfo.matchedPosList.Count; j++) //對照索引值紀錄相應的座標 { _resultList.drawedPosList.Add(coordinates[_cbInfo.matchedPosList[j]]); } _resultList.AddCombinationItem(_cbInfo); } } } } _resultList.lineLevel = level; //設定中獎線等級 _resultList.drawedPosList = ListExtensibleScript <Vector2> .RepetitionFilter(_resultList.drawedPosList); //篩掉列表中的重複元素 return(_resultList); }
//列表比對(判斷是否中獎) //[output] CombinationPrizeInfo = 支付表項目比對中獎資訊 //[param] mainList = 主圖格列表 public CombinationPrizeInfo Comparison(List <ElementImageType> mainList) { CombinationPrizeInfo _info = new CombinationPrizeInfo(); _info.prizeMoney = 0; _info.prizeType = prizeLineType; //設定連線獎項類型 _info.patternList = combinations; //設定圖案串接形式 //string _s = ""; //for (int i = 0; i < combinations.Count; i++) //{ // _s += combinations[i] + ( i == combinations.Count - 1 ? "" : "," ); //} //Debug.Log("[組合]" + _s); List <int> _matchedPos = new List <int>(); if (freeOrder) //可任意順序排列 { for (int i = 0; i < mainList.Count - (combinations.Count - 1); i++) //遍歷線段圖格至(組合長度 - 1)位置 { int _k = i; //索引定位標記 bool _anchor = true; //索引定位與否 int _wildCount = 0; //狂野符號數量 List <ElementImageType> _comb = new List <ElementImageType>(); _comb.AddRange(combinations); //暫存支付表組合 _matchedPos = new List <int>(); //初始化判斷成功的索引值列表 while (_anchor) { _anchor = false; //假設判斷會失敗 for (int j = 0; j < _comb.Count; j++) //遍歷支付表組合 { bool isWild = ScrollManager.Instance.Dict_wildSymbol[mainList[_k]]; //是否為狂野符號 if (isWild) { _wildCount += 1; //紀錄狂野符號數量 } if (mainList[_k] == _comb[j] || isWild) //若線段上第 i 項與支付表組合相符 或 該圖格為狂野符號時 { if (!isWild) { _comb.RemoveAt(j); //將組合中符合的項目抽掉(若為狂野符號則不抽掉任何元素) } _matchedPos.Add(_k); //紀錄符合的索引 if (_k + 1 == mainList.Count) { break; //若預判斷的圖格已經到最後一項則直接結束 } _k++; _anchor = true; //判斷成功, 繼續判斷下一項是否符合 break; } } //Debug.Log(string.Format("i = {0}, WildCount = {1}", i, _wildCount)); if (_comb.Count - _wildCount == 0) //若組合元素全部被抽光, 表示元素全部比對成功 { _info.matchedPosList = _matchedPos; _info.prizeMoney = this.prizeMoney; break; } } } } else //按照固定順序排列 { for (int i = 0; i < mainList.Count; i++) //遍歷線段圖格列表 { int _k = i; //索引定位標記 int _matchCount = 0; //符合的數量 _matchedPos = new List <int>(); //初始化判斷成功的索引值列表 for (int j = 0; j < combinations.Count; j++) //遍歷支付表組合 { //當捲軸第 i 項判斷成功時, 則以該索引為開頭, 逐一往後比對 if (mainList[_k] != combinations[j] && !ScrollManager.Instance.Dict_wildSymbol[mainList[_k]]) { break; } else { _matchCount++; //累計符合數量 _matchedPos.Add(_k); //紀錄符合的索引 if (_k + 1 == mainList.Count) { break; //若預判斷的圖格已經到最後一項則直接結束 } _k++; } } if (_matchCount == combinations.Count) //若符合數量等於列表長度(所有皆比對成功), 跳出迴圈並返回結果 { _info.matchedPosList = _matchedPos; _info.prizeMoney = this.prizeMoney; break; } } } return(_info); }