Пример #1
0
        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();
            }
        }
Пример #2
0
        public static bool HasThreats(this ThreatDirection?threatDirection, ThreatDirection threat)
        {
            if (threatDirection.HasValue)
            {
                return((threatDirection.Value & threat) > 0);
            }

            return(false);
        }
Пример #3
0
 public void AddPin(ThreatDirection newPin)
 {
     if (Pin.HasValue)
     {
         Pin |= newPin;
     }
     else
     {
         Pin = newPin;
     }
 }
Пример #4
0
        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);
        }
Пример #5
0
        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;
                }
            }
        }
Пример #6
0
 public void AddDirection(ThreatDirection newDirection)
 {
     ThreatDirection |= newDirection;
 }