public static Direction ToDirection(this ThreatDirection threatDirection) { switch (threatDirection) { case ThreatDirection.East: return(Direction.East); case ThreatDirection.North: return(Direction.North); case ThreatDirection.NorthEast: return(Direction.NorthEast); case ThreatDirection.NorthWest: return(Direction.NorthWest); case ThreatDirection.South: return(Direction.South); case ThreatDirection.SouthEast: return(Direction.SouthEast); case ThreatDirection.SouthWest: return(Direction.SouthWest); case ThreatDirection.West: return(Direction.West); default: throw new InvalidOperationException(); } }
public static bool HasThreats(this ThreatDirection?threatDirection, ThreatDirection threat) { if (threatDirection.HasValue) { return((threatDirection.Value & threat) > 0); } return(false); }
public void AddPin(ThreatDirection newPin) { if (Pin.HasValue) { Pin |= newPin; } else { Pin = newPin; } }
public void Add(BoardLocation boardLocation, ThreatDirection threatDirection, ThreatDirection?pin) { var threat = new Threat(); threat.AddDirection(threatDirection); if (pin.HasValue) { threat.AddPin(pin.Value); } Add(boardLocation, threat); }
private void AddThreat( ThreatMatrix threatMatrix, BoardLocation playerKingLocation, BoardLocation threateningPieceLocation, BoardLocation boardLocationBeingThreatening, ThreatDirection direction, ThreatDirection?pin = null) { if (!threatMatrix.ContainsKey(boardLocationBeingThreatening)) { threatMatrix.Add(boardLocationBeingThreatening, direction, pin); } else { //update the threat direction threatMatrix[boardLocationBeingThreatening].AddDirection(direction); //can only be pinned in one direction (since there is only one king) if (pin != null) { threatMatrix[boardLocationBeingThreatening].AddPin(pin.Value); } } //if this is a king threat if (playerKingLocation == boardLocationBeingThreatening) { //we set the piece that is threatening the king here. Please note that it is possible more than one piece //is threatening the king but it is IMPOSSIBLE for a triple check to occur. var threat = threatMatrix[boardLocationBeingThreatening]; if (threat.FirstPieceThreateningKingBoardLocation.HasValue) { threat.SecondPieceThreateningKingBoardLocation = threateningPieceLocation; } else { threat.FirstPieceThreateningKingBoardLocation = threateningPieceLocation; } } }
public void AddDirection(ThreatDirection newDirection) { ThreatDirection |= newDirection; }