Skip to content

Instantly share code, notes, and snippets.

@edgarshurtado
Created December 9, 2015 09:26
Show Gist options
  • Save edgarshurtado/21e7bf4696baa0a2f499 to your computer and use it in GitHub Desktop.
Save edgarshurtado/21e7bf4696baa0a2f499 to your computer and use it in GitHub Desktop.
Movimiento Caballo
void horseMov(int *position){
int row = position[0];
int col = position[1];
int straightMov = 2;
int bendMov = 1;
//Moves with +- 2 col positions and +- 1 row positions
if(col + straightMov < COLS){
if(row - bendMov >= 0 && board[row - bendMov][col + straightMov] == EMPTY){
board[row - bendMov][col + straightMov] = MOVEMENT;
}
if (row + bendMov < ROWS && board[row + bendMov][col + straightMov] == EMPTY){
board[row + bendMov][col + straightMov] = MOVEMENT;
}
}
if(col - straightMov >= 0){
if(row - bendMov >= 0 && board[row - bendMov][col - straightMov] == EMPTY){
board[row - bendMov][col - straightMov] = MOVEMENT;
}
if (row + bendMov < ROWS && board[row + bendMov][col - straightMov] == EMPTY){
board[row + bendMov][col - straightMov] = MOVEMENT;
}
}
//Moves with +- 2 row positions and +- 1 col position
if(row - straightMov >= 0){
if(col + bendMov < COLS && board[row-straightMov][col+bendMov] == EMPTY){
board[row-straightMov][col+bendMov]=MOVEMENT;
}
if(col - bendMov >= 0 && board[row-straightMov][col-bendMov] == EMPTY){
board[row-straightMov][col-bendMov]=MOVEMENT;
}
}
if(row + straightMov >= 0){
if(col + bendMov < COLS && board[row+straightMov][col+bendMov] == EMPTY){
board[row+straightMov][col+bendMov]=MOVEMENT;
}
if(col - bendMov >= 0 && board[row+straightMov][col-bendMov] == EMPTY){
board[row+straightMov][col-bendMov]=MOVEMENT;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment