Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool IllegalRookMove(int fromCol, int fromRow, int toCol, int toRow, int piece) {
- int moveX = abs(fromCol - toCol);
- int moveY = abs(fromRow - toRow);
- if(toCol != fromCol && toRow != fromRow) {
- return true;
- }
- if(fromCol == toCol) {
- if(fromRow > toRow) {
- for(int i = moveY; i > 0; i--) {
- if(IsOccupiedByTeam(piece, fromCol, fromRow - i)) {
- return true;
- }
- }
- for(int i = moveY; i > 1; i--) {
- if(IsOccupiedByEnemy(piece, fromCol, fromRow - i)) {
- return true;
- }
- }
- }
- if(toRow > fromRow) {
- for(int i = 0; i < moveY; i++) {
- if(IsOccupiedByTeam(piece, fromCol, fromRow + i)) {
- return true;
- }
- }
- for(int i = 0; i < moveY - 1; i++) {
- if(IsOccupiedByEnemy(piece, fromCol, fromRow + i)) {
- return true;
- }
- }
- }
- }
- if(fromRow == toRow) {
- if(fromCol > toCol) {
- for(int i = moveX; i > 0; i--) {
- if(IsOccupiedByTeam(piece, fromCol - i, fromRow)) {
- return true;
- }
- }
- for(int i = moveX; i > 1; i--) {
- if(IsOccupiedByEnemy(piece, fromCol - i, fromRow)) {
- return true;
- }
- }
- }
- if(toCol > fromCol) {
- for(int i = 0; i < moveX; i++) {
- if(IsOccupiedByTeam(piece, fromCol + i, fromRow)) {
- return true;
- }
- }
- for(int i = 0; i < moveX - 1; i++) {
- if(IsOccupiedByEnemy(piece, fromCol + i, fromRow)) {
- return true;
- }
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement