/// <summary> /// Gets the chance that the specified point can be hit by an opposing player. /// </summary> /// <param name="pointID"></param> /// <returns></returns> public float GetVulnerability(BGPointID pointID) { BGPoint point = GetPoint(pointID); if (point.IsVulnerable()) { float vulnerability = 0f; bool[,] hitTable = new bool[6, 6]; BGPlayerID player = point.Player; BGPlayerID opponent = (player == BGPlayerID.Player1) ? BGPlayerID.Player2 : BGPlayerID.Player1; for (int roll1 = 1; roll1 <= 6; roll1++) { BGPoint point1 = GetPreviousPoint(pointID, opponent, roll1); if (point1 != null) { if (point1.IsOccupiedBy(opponent)) { //Debug.Log(string.Format("{0} is vulnerable to any roll with {1}", point.ID, roll1)); for (int i = 0; i < 6; i++) { hitTable[roll1 - 1, i] = hitTable[i, roll1 - 1] = true; } } else if (!point1.IsControlledBy(player)) { for (int roll2 = 1; roll2 <= 6; roll2++) { BGPoint point2 = GetPreviousPoint(point1.ID, opponent, roll2); if (point2 != null && point2.IsOccupiedBy(opponent)) { //Debug.Log(string.Format("{0} is vulnerable to roll ({1}, {2}) from {3}", point.ID, roll1, roll2, point2)); hitTable[roll1 - 1, roll2 - 1] = hitTable[roll2 - 1, roll1 - 1] = true; } } } } } for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (hitTable[i, j]) { //Debug.Log(string.Format(">> {0},{1}", i + 1, j + 1)); vulnerability += 1f / 36f; } } } //Debug.Log(string.Format("Total vulnerability for {0} = {1}", point.ID, vulnerability)); return(vulnerability); } else { return(0f); } }
/// <summary> /// Gets a list of all moves that can be made for the specified player with the specified board and dice roll. /// </summary> private List <BGMove> GetMoves(BGPlayerID player, BGBoardMap board, BGDiceRoll diceRoll) { List <BGMove> moves = new List <BGMove>(); if (player == BGPlayerID.None) { return(moves); } BGPoint home = board.GetHome(player); BGPoint jail = board.GetJail(player); BGPoint[] innerTable = board.GetInnerTable(player); BGPoint[] outerTable = board.GetOuterTable(player); // Find available moves. if (jail.Count > 0) { for (int roll = 1; roll <= 6; roll++) { if (diceRoll.CanUse(roll) && !outerTable[roll - 1].IsBlocking(player)) { moves.Add(new BGMove(jail, outerTable[roll - 1], roll)); } } } else { for (int roll = 1; roll <= 6; roll++) { if (diceRoll.CanUse(roll)) { for (BGPointID point = BGPointID.Point1; point <= BGPointID.Point24; point++) { BGPoint from = board.GetPoint(point); if (from.IsOccupiedBy(player)) { BGPoint to = null; if (player == BGPlayerID.Player1 && ((point - roll) >= BGPointID.Point1)) { to = board.GetPoint(point - roll); } else if (player == BGPlayerID.Player2 && ((point + roll) <= BGPointID.Point24)) { to = board.GetPoint(point + roll); } if (to != null && !to.IsBlocking(player)) { moves.Add(new BGMove(from, to, roll)); } } } } } if (!outerTable.Any(point => point.IsOccupiedBy(player))) { // Get max distance from home. int maxDistance = 0; for (int i = 0; i < innerTable.Length; i++) { if (innerTable[i].IsOccupiedBy(player)) { maxDistance = i + 1; } } // Find moves that can be used to bear off. for (int roll = 1; roll <= 6; roll++) { if (diceRoll.CanUse(roll)) { if (innerTable[roll - 1].IsOccupiedBy(player)) { moves.Add(new BGMove(innerTable[roll - 1], home, roll)); } else if (maxDistance > 0 && innerTable[maxDistance - 1].IsOccupiedBy(player) && roll >= maxDistance) { moves.Add(new BGMove(innerTable[maxDistance - 1], home, roll)); } } } } } return(moves); }