public ChessPiece this[BoardLocation boardLocation] { get { return(_board[boardLocation.ToByte()]); } set { _board[boardLocation.ToByte()] = value; } }
public static bool IsPawnStartingLocation(this BoardLocation boardLocation, Player player) { if (player == Player.White) { return(boardLocation.ToByte() % 8 == 1); } else { return(boardLocation.ToByte() % 8 == 6); } }
public static BoardLocation?South(this BoardLocation currentLocation) { var val = currentLocation.ToByte() - 1; //if we hop columns we are out of bounds if (val / 8 != currentLocation.Column()) { return(null); } return((val >= 0) ? (BoardLocation)val : default(BoardLocation?)); }
public static BoardLocation?North(this BoardLocation currentLocation) { var val = currentLocation.ToByte() + 1; //if we hop columns we are out of bounds if (val / 8 != currentLocation.Column()) { return(null); } return((val < Constants.BoardSize) ? (BoardLocation)val : default(BoardLocation?)); }
public static BoardLocation?SouthEast(this BoardLocation currentLocation) { var val = currentLocation.ToByte() + 7; //if we are not the next column this is invalid if ((val / 8) == currentLocation.Column()) { return(null); } return((val < Constants.BoardSize) ? (BoardLocation)val : default(BoardLocation?)); }
public static BoardLocation?SouthWest(this BoardLocation currentLocation) { var val = currentLocation.ToByte() - 9; //if we are not the next column this is invalid if ((val / 8) + 1 != currentLocation.Column()) { return(null); } return((val >= 0) ? (BoardLocation)val : default(BoardLocation?)); }
public static BoardLocation?NorthWest(this BoardLocation currentLocation) { var val = currentLocation.ToByte() - 7; //if we DONT hop columns we are out of bounds if (val / 8 == currentLocation.Column()) { return(null); } return((val >= 0) ? (BoardLocation)val : default(BoardLocation?)); }
public static bool IsNorthWestFrom(this BoardLocation source, BoardLocation target) { //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| return((source.ToByte() < target.ToByte()) && source.IsOnSameSlopeAs(target)); }
public static bool IsSouthEastFrom(this BoardLocation source, BoardLocation target) { return((source.ToByte() > target.ToByte()) && source.IsOnSameSlopeAs(target)); }
public static bool IsSouthWestFrom(this BoardLocation source, BoardLocation target) { return((source.ToByte() < target.ToByte()) && source.IsOnSameGradeAs(target)); }
public static bool IsNorthFrom(this BoardLocation source, BoardLocation target) { return((source.ToByte() > target.ToByte()) && source.IsOnSameColumnAs(target)); }
public static BoardLocationColor Color(this BoardLocation boardLocation) { return(((boardLocation.ToByte() + boardLocation.Column() % 2) % 2 == 0) ? BoardLocationColor.Dark : BoardLocationColor.Light); }
public static BoardLocation?West(this BoardLocation currentLocation) { var val = currentLocation.ToByte() - Constants.BoardWidth; return((val >= 0) ? (BoardLocation)val : default(BoardLocation?)); }
public static BoardLocation?East(this BoardLocation currentLocation) { var val = currentLocation.ToByte() + Constants.BoardWidth; return((val < Constants.BoardSize) ? (BoardLocation)val : default(BoardLocation?)); }
private void AddKnightThreats( 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| |22| |38|46|54|62| //6:| |13|21|29| |45|53|61| //5:| 4|12|20|28|36|44|52|60| //4:| |11|19|27| |43|51|59| //3:| 2| |18| |34|42|50|58| //2:| 1| 9|17|25|33|41|49|57| //1:| 0| 8|16|24|32|40|48|56| //A knights move from postion 20. //-17 //-15 //-10 //-6 //+17 //+15 //+10 //+6 List <BoardLocation> possibleMoves = new List <BoardLocation>(); var knightLocation = opposingPieceBoardLocation.ToByte(); //same column var leftDown = knightLocation - 17; var leftUp = knightLocation - 15; //same row var upLeft = knightLocation - 6; var upRight = knightLocation + 10; //same column var rightUp = knightLocation + 17; var rightDown = knightLocation + 15; //same row var downLeft = knightLocation - 10; var downRight = knightLocation + 6; if ((leftDown >= 0) && ((knightLocation / 8) - (leftDown / 8) == 2)) { possibleMoves.Add((BoardLocation)leftDown); } if ((leftUp >= 0) && ((knightLocation / 8) - (leftUp / 8) == 2)) { possibleMoves.Add((BoardLocation)leftUp); } if ((upLeft >= 0) && ((knightLocation / 8) - (upLeft / 8) == 1)) { possibleMoves.Add((BoardLocation)upLeft); } if ((downLeft >= 0) && ((knightLocation / 8) - (downLeft / 8) == 1)) { possibleMoves.Add((BoardLocation)downLeft); } if ((upRight < Constants.BoardSize) && ((knightLocation / 8) - (upRight / 8) == -1)) { possibleMoves.Add((BoardLocation)upRight); } if ((downRight < Constants.BoardSize) && ((knightLocation / 8) - (downRight / 8) == -1)) { possibleMoves.Add((BoardLocation)downRight); } if ((rightUp < Constants.BoardSize) && ((knightLocation / 8) - (rightUp / 8) == -2)) { possibleMoves.Add((BoardLocation)rightUp); } if ((rightDown < Constants.BoardSize) && ((knightLocation / 8) - (rightDown / 8) == -2)) { possibleMoves.Add((BoardLocation)rightDown); } possibleMoves .ForEach(a => AddThreat(threatMatrix, playerKingLocation, opposingPieceBoardLocation, a, ThreatDirection.Direct)); }