Skip to content
Snippets Groups Projects
Knight.java 621 B
Newer Older
  • Learn to ignore specific revisions
  • Teo Blaise Kaplanski's avatar
    Teo Blaise Kaplanski committed
    public class Knight extends Piece {
    
        public Knight(int x, int y, Player owner){
    		super(x, y, owner);
    		
        }
    
        public boolean isMoveAuthorized(Board board, Coordinates destination){
    	int dx = destination.getX();
    	int dy = destination.getY();
    	int ox = this.getX();
    	int oy = this.getY();
    	for(int i=-2; i <= 2; i++) {
    		for(int j=-2; j <= 2; j++) {
    			if(((dx-ox)%2==1 && (dy-oy)%2==0) || ((dx-ox)%2==0 && (dy-oy)%2==1)) {
    				return true;
    			}
    		}
    	}
    
    
    	return false;
        }
    
        @Override
        public Type getType() {
    	return Type.KNIGHT;
        }
    
        @Override
        public int getValue() {
    	return 3;
        }
        
    }