Guest User

Untitled

a guest
Jun 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. public class Knight : ChessFigure
  2. {
  3. public override bool[,] PossibleMove()
  4. {
  5. bool[,] r = new bool[8, 8];
  6.  
  7. // Up / Left
  8. KnightMove(CurrentX - 1, CurrentY + 2, ref r);
  9. KnightMove(CurrentX - 2, CurrentY + 1, ref r);
  10.  
  11. // Up / Right
  12. KnightMove(CurrentX + 1, CurrentY + 2, ref r);
  13. KnightMove(CurrentX + 2, CurrentY + 1, ref r);
  14.  
  15. // Down / Left
  16. KnightMove(CurrentX - 1, CurrentY - 2, ref r);
  17. KnightMove(CurrentX - 2, CurrentY - 1, ref r);
  18.  
  19. // Down / Right
  20. KnightMove(CurrentX + 1, CurrentY - 2, ref r);
  21. KnightMove(CurrentX + 2, CurrentY - 1, ref r);
  22.  
  23. return r;
  24. }
  25.  
  26. public void KnightMove(int x, int y, ref bool[,] r)
  27. {
  28. ChessFigure c;
  29. if(x >= 0 && x < 8 && y >= 0 && y < 8)
  30. {
  31. c = BoardManager.Instance.ChessFigurePositions[x, y];
  32. if (c == null) r[x, y] = true;
  33. else if (c.isWhite != isWhite) r[x, y] = true;
  34. }
  35. }
  36. }
Add Comment
Please, Sign In to add comment