Commit 84749e14 authored by Parsa Safaei's avatar Parsa Safaei

...

parent 5aae2a80
Pipeline #531 failed with stages
package PACKAGE_NAME;
public class Field {
private boolean isFree;
private int num;
private char letter;
}
package PACKAGE_NAME;
public class Man {
}
private char color;
private int num;
private char letter;
private String type;
boolean hasMoved;
public Man(char color, int num, char letter, String type) {
this.color = color;
this.num = num;
this.letter = letter;
this.type = type;
this.hasMoved = false;
}
public boolean move(int num, char letter) {
if (this.type.equals("king") && Math.abs(num - this.num) <= 1 && Math.abs((int) letter - (int) this.letter) <= 1) {
this.num = num;
this.letter = letter;
hasMoved = true;
return true;
}
else if (this.type.equals("queen") && ((num == this.num || letter == this.letter) || (Math.abs(num - this.num) == Math.abs((int) letter - (int) this.letter)))) {
this.num = num;
this.letter = letter;
hasMoved = true;
return true;
}
else if (this.type.equals("rook") && (num == this.num || letter == this.letter)) {
this.num = num;
this.letter = letter;
hasMoved = true;
return true;
}
else if (this.type.equals("bishop") && Math.abs(num - this.num) == Math.abs((int) letter - (int) this.letter)) {
this.num = num;
this.letter = letter;
hasMoved = true;
return true;
}
else if (this.type.equals("knight") && (Math.abs(num - this.num) == 1 && Math.abs((int) letter - (int) this.letter) == 2) || (Math.abs(num - this.num) == 2 && Math.abs((int) letter - (int) this.letter) == 1)) {
this.num = num;
this.letter = letter;
hasMoved = true;
return true;
}
else if (this.type.equals("soldier")) {
if (this.color == 'w') {
if (!this.hasMoved && num - this.num == 2) {
this.num = num;
this.letter = letter;
hasMoved = true;
return true;
}
if (this.hasMoved && num - this.num == 1) {
this.num = num;
this.letter = letter;
hasMoved = true;
return true;
}
}
else if (this.color == 'b') {
if (!this.hasMoved && num - this.num == -2) {
this.num = num;
this.letter = letter;
hasMoved = true;
return true;
}
if (this.hasMoved && num - this.num == -1) {
this.num = num;
this.letter = letter;
hasMoved = true;
return true;
}
}
}
System.out.println("Wrong Input!");
return false;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment