public static BoardLocation?Neighbor(this BoardLocation currentLocation, Direction direction) { switch (direction) { case Direction.East: return(currentLocation.East()); case Direction.North: return(currentLocation.North()); case Direction.NorthEast: return(currentLocation.NorthEast()); case Direction.NorthWest: return(currentLocation.NorthWest()); case Direction.South: return(currentLocation.South()); case Direction.SouthEast: return(currentLocation.SouthEast()); case Direction.SouthWest: return(currentLocation.SouthWest()); case Direction.West: return(currentLocation.West()); default: return(null); } }
private void AddPawnThreats( Board board, Player player, BoardLocation playerKingLocation, BoardLocation opposingPieceBoardLocation, ThreatMatrix threatMatrix) { //PGN format for the board // A B C D E F G H //8:| 7|15|23|31|39|47|55|63| //7:| 6|14|22|30|38|46|54|62| //6:| 5|13|21|29|37|45|53|61| //5:| 4|12|20|28|36|44|52|60| //4:| 3|11|19|27|35|43|51|59| //3:| 2|10|18|26|34|42|50|58| //2:| 1| 9|17|25|33|41|49|57| //1:| 0| 8|16|24|32|40|48|56| BoardLocation?[] moves = new BoardLocation?[2]; if (player == Player.White) { //then we are worried about the black guys pieces moves[0] = opposingPieceBoardLocation.SouthEast(); moves[1] = opposingPieceBoardLocation.SouthWest(); } else { moves[0] = opposingPieceBoardLocation.NorthEast(); moves[1] = opposingPieceBoardLocation.NorthWest(); } moves .Where(a => a.HasValue) .ForEach(a => AddThreat(threatMatrix, playerKingLocation, opposingPieceBoardLocation, a.Value, ThreatDirection.Direct)); }