Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main
- {
- static Boolean rook(int x, int y, int xend, int yend)
- {
- if(x==xend || y==yend )return true;
- return false;
- }
- static Boolean bishop(int x,int y,int xend,int yend)
- {
- if(Math.abs(xend-x)==Math.abs(yend-y))return true;
- return false;
- }
- static Boolean queen(int x,int y,int xend,int yend)
- {
- if(rook(x,y,xend,yend)==true || bishop(x,y,xend,yend)==true)return true;
- return false;
- }
- static Boolean king (int x,int y,int xend,int yend)
- {
- if(x==xend && (y==yend-1 || y==yend+1))return true;
- if((x==xend+1||x==xend-1) && (y==yend|| y==yend-1 || y==yend+1))return true;
- return false;
- }
- static Boolean knight (int x,int y,int xend,int yend)
- {
- if(Math.abs(x-xend)==2 && Math.abs(y-yend)==1)return true;
- if(Math.abs(y-yend)==2 && Math.abs(x-xend)==1)return true;
- return false;
- }
- static Boolean whitepawn(int x,int y,int xend,int yend)
- {
- return(yend==y+1 && (xend==x+1 || xend == x-1));
- }
- static Boolean blackpawn(int x,int y,int xend,int yend)
- {
- return(yend==y-1 && (xend==x+1 || xend == x-1));
- }
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- String firstName=sc.next();
- String firstCoord=sc.next();
- String secondName=sc.next();
- String secondCoord=sc.next();
- int x1=firstCoord.charAt(0)-'A'+1;
- int y1=firstCoord.charAt(1)-'0';
- int x2=secondCoord.charAt(0)-'A'+1;
- int y2=secondCoord.charAt(1)-'0';
- if(firstName.equals("Queen")){
- if(queen(x1,y1,x2,y2)==true)
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- System.out.print(secondName);
- System.out.print(" can be captured by ");
- System.out.println(firstName);
- return;
- }
- else
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- System.out.println("None of them can be captured");
- return;
- }
- }
- //////////////////////////////////////////////////////////////////////
- if(firstName.equals("Rook")){
- if(rook(x1,y1,x2,y2)==true)
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- System.out.print(secondName);
- System.out.print(" can be captured by ");
- System.out.println(firstName);
- return;
- }
- else
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- System.out.println("None of them can be captured");
- return;
- }
- }
- //////////////////////////////////////////////////////////////////////
- if(firstName.equals("Bishop")){
- if(bishop(x1,y1,x2,y2)==true)
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- System.out.print(secondName);
- System.out.print(" can be captured by ");
- System.out.println(firstName);
- return;
- }
- else
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- System.out.println("None of them can be captured");
- return;
- }
- }
- //////////////////////////////////////////////////////////////////////
- if(firstName.equals("King")){
- if(king(x1,y1,x2,y2)==true)
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- System.out.print(secondName);
- System.out.print(" can be captured by ");
- System.out.println(firstName);
- return;
- }
- else
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- System.out.println("None of them can be captured");
- return;
- }
- }
- //////////////////////////////////////////////////////////////////////
- if(firstName.equals("Knight")){
- if(knight(x1,y1,x2,y2)==true)
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- System.out.print(secondName);
- System.out.print(" can be captured by ");
- System.out.println(firstName);
- return;
- }
- else {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- System.out.println("None of them can be captured");
- return;
- }
- }
- //////////////////////////////////////////////////////////////////////
- if(firstName.equals("Pawn")){
- if(whitepawn(x1,y1,x2,y2)==true)
- {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)==true) {
- System.out.println("Both of them can be captured from each other");
- return;
- }
- }
- System.out.print(secondName);
- System.out.print(" can be captured by ");
- System.out.println(firstName);
- return;
- }
- else {
- if(secondName.equals("Queen"))
- {
- if(queen(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Bishop"))
- {
- if(bishop(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Rook"))
- {
- if(rook(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Knight"))
- {
- if(knight(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("King"))
- {
- if(king(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- if(secondName.equals("Pawn"))
- {
- if(blackpawn(x2,y2,x1,y1)) {
- System.out.print(firstName);
- System.out.print(" can be captured by ");
- System.out.println(secondName);
- return;
- }
- }
- System.out.println("None of them can be captured");
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement