//=======================// //Разрабатываемые функции// //=======================// private void Standardize(ref MTable.SBone domino) { if (domino.First > domino.Second) { domino.Exchange(); } }
private void SaveTable(ref MTable.SBone domino, bool end, int iEnemyBoneCount, ushort number) { if (end) { _pRight = domino; if (number != _pRight.First) { _pRight.Exchange(); } } else { _pLeft = domino; if (number != _pLeft.Second) { _pLeft.Exchange(); } } _pEnemyBoneCount = iEnemyBoneCount; }
//Сделать ход public override bool MakeStep(out MTable.SBone sb, out bool end) { #region TableLoad //Получаем состояние стола List <MTable.SBone> lTableCondition = MTable.GetGameCollection(); //Кости на концах цепочки MTable.SBone sLeft = lTableCondition[0]; MTable.SBone sRight = lTableCondition[lTableCondition.Count - 1]; //Standardize(ref sLeft ); //Standardize(ref sRight); //Получение числа костей на столе, в руке оппонента int iShopBoneCount = MTable.GetShopCount(); int iEnemyBoneCount = 28 - _lHand.Count - iShopBoneCount - lTableCondition.Count; #endregion //Поиск изменений стола с предыдущего хода #region TableUpdate //Первичная инициализация if (!_pInit) { foreach (var item in lTableCondition) { var t = item; Standardize(ref t); DominoIsUsed(t); } foreach (var item in _lHand) { DominoIsUsed(item); } } //Подсчет количества новых домино в руке оппонента int iEnemyBoneCountDeltha = iEnemyBoneCount - _pEnemyBoneCount; DominoIsUsed(sLeft); DominoIsUsed(sRight); if (iEnemyBoneCountDeltha > 0) { for (ushort i = 0; i < 7; i++) { for (ushort j = 0; j < 7; j++) { if (j > i) { break; } if (!_lsbUsed.Contains(new MTable.SBone { First = i, Second = j }) && !_lsbUsed.Contains(new MTable.SBone { First = j, Second = i }) && _pInit) { _iProbabilityTable[j, i] += iEnemyBoneCountDeltha; if (i != j) { _iProbabilityTable[i, j] += iEnemyBoneCountDeltha; } } } } } else if (iEnemyBoneCountDeltha != 0) { for (ushort i = 0; i < 7; i++) { for (ushort j = 0; j < 7; j++) { if (j > i) { break; } if (!_lsbUsed.Contains(new MTable.SBone { First = i, Second = j }) && !_lsbUsed.Contains(new MTable.SBone { First = j, Second = i }) && _iProbabilityTable[i, j] == _pEnemyBoneCount) { _iProbabilityTable[i, j] -= 1; if (i != j) { _iProbabilityTable[j, i] -= 1; } } } } } if (!_pInit) { _pInit = !_pInit; } else if (iEnemyBoneCountDeltha >= 0) { if (Equals(_pLeft, sLeft)) { if (!Equals(_pRight, sRight)) { DominoIsUsed(sRight); for (ushort i = 0; i < 7; i++) { if (!_lsbUsed.Contains(new MTable.SBone { First = i, Second = _pLeft.First }) && !_lsbUsed.Contains(new MTable.SBone { First = _pLeft.First, Second = i })) { DominoIsntInEHand(new MTable.SBone { First = i, Second = _pLeft.First }); } if (!_lsbUsed.Contains(new MTable.SBone { First = i, Second = _pRight.Second }) && !_lsbUsed.Contains(new MTable.SBone { First = _pRight.Second, Second = i })) { DominoIsntInEHand(new MTable.SBone { First = i, Second = _pRight.Second }); } } } } else if (!Equals(_pLeft, sLeft)) { DominoIsUsed(sLeft); for (ushort i = 0; i < 7; i++) { if (!_lsbUsed.Contains(new MTable.SBone { First = i, Second = _pLeft.First }) && !_lsbUsed.Contains(new MTable.SBone { First = _pLeft.First, Second = i })) { DominoIsntInEHand(new MTable.SBone { First = i, Second = _pLeft.First }); } if (!_lsbUsed.Contains(new MTable.SBone { First = i, Second = _pRight.Second }) && !_lsbUsed.Contains(new MTable.SBone { First = _pRight.Second, Second = i })) { DominoIsntInEHand(new MTable.SBone { First = i, Second = _pRight.Second }); } } } } #endregion //Получаем все домино в руке, которые можно использовать на этот ход List <TurnOption> ltoUsefulDominoes = GetUsefulDomino(_lHand, sLeft, sRight); //Обновление сохраняемых параметров _pLeft = sLeft; _pRight = sRight; if (ltoUsefulDominoes.Count != 0) { TurnOption bestTo = GetBt(ltoUsefulDominoes); sb = bestTo.Bone; end = bestTo.End; SaveTable(ref sb, end, iEnemyBoneCount, end ? sRight.Second : sLeft.First); _lHand.Remove(sb); sb.Exchange(); _lHand.Remove(sb); return(true); } MTable.SBone sbNew; while (MTable.GetFromShop(out sbNew)) { DominoIsUsed(sbNew); List <MTable.SBone> lNew = new List <MTable.SBone> { sbNew }; ltoUsefulDominoes = GetUsefulDomino(lNew, sLeft, sRight); if (ltoUsefulDominoes.Count != 0) { TurnOption bestTo = GetBt(ltoUsefulDominoes); sb = bestTo.Bone; end = bestTo.End; SaveTable(ref sb, end, iEnemyBoneCount, end ? sRight.Second : sLeft.First); _lHand.Remove(sb); sb.Exchange(); _lHand.Remove(sb); return(true); } _lHand.Add(sbNew); } //Нельзя сделать ход sb.First = 322; sb.Second = 322; end = true; _pRight = sRight; _pLeft = sLeft; return(false); }