From 8ac22249f126d6ef5c5c633a0242d7b8d5a6b007 Mon Sep 17 00:00:00 2001
From: ACIKBAS TUNA BATIKAN <tuna.acikbas@etu.unistra.fr>
Date: Fri, 28 Apr 2023 22:20:52 +0200
Subject: [PATCH] EnPassant rule added

---
 MavenChess/.idea/MavenChess.iml               |  6 --
 MavenChess/.idea/misc.xml                     | 14 ----
 MavenChess/MavenChess/.idea/misc.xml          | 14 ----
 .../MavenChess/src/main/java/model/Pawn.java  | 64 ++++++++++++++++++-
 4 files changed, 63 insertions(+), 35 deletions(-)
 delete mode 100644 MavenChess/.idea/MavenChess.iml
 delete mode 100644 MavenChess/.idea/misc.xml
 delete mode 100644 MavenChess/MavenChess/.idea/misc.xml

diff --git a/MavenChess/.idea/MavenChess.iml b/MavenChess/.idea/MavenChess.iml
deleted file mode 100644
index 6054576..0000000
--- a/MavenChess/.idea/MavenChess.iml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module version="4">
-  <component name="AdditionalModuleElements">
-    <content url="file://$MODULE_DIR$" />
-  </component>
-</module>
\ No newline at end of file
diff --git a/MavenChess/.idea/misc.xml b/MavenChess/.idea/misc.xml
deleted file mode 100644
index abcc7fd..0000000
--- a/MavenChess/.idea/misc.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="ExternalStorageConfigurationManager" enabled="true" />
-  <component name="MavenProjectsManager">
-    <option name="originalFiles">
-      <list>
-        <option value="$PROJECT_DIR$/MavenChess/pom.xml" />
-      </list>
-    </option>
-  </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK">
-    <output url="file://$PROJECT_DIR$/out" />
-  </component>
-</project>
\ No newline at end of file
diff --git a/MavenChess/MavenChess/.idea/misc.xml b/MavenChess/MavenChess/.idea/misc.xml
deleted file mode 100644
index 0a5c358..0000000
--- a/MavenChess/MavenChess/.idea/misc.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="ExternalStorageConfigurationManager" enabled="true" />
-  <component name="MavenProjectsManager">
-    <option name="originalFiles">
-      <list>
-        <option value="$PROJECT_DIR$/MavenChess/pom.xml" />
-      </list>
-    </option>
-  </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK">
-    <output url="file://$PROJECT_DIR$/out" />
-  </component>
-</project>
\ No newline at end of file
diff --git a/MavenChess/MavenChess/src/main/java/model/Pawn.java b/MavenChess/MavenChess/src/main/java/model/Pawn.java
index 226e685..69509fc 100644
--- a/MavenChess/MavenChess/src/main/java/model/Pawn.java
+++ b/MavenChess/MavenChess/src/main/java/model/Pawn.java
@@ -3,6 +3,8 @@ package model;
 import java.util.ArrayList;
 
 public class Pawn extends Piece {
+
+	private boolean enPassant = true; // temporarily given true but has to be changed in the controller
 	public Pawn(Position p, int color) {
 		super(p, color);
 	}
@@ -11,7 +13,8 @@ public class Pawn extends Piece {
 
 		// creates a dynamic list of available moves
 		ArrayList<Position> moves = new ArrayList<>();
-		Position arrival;
+		Position arrival,enPassantEnemy;
+
 
 		int y = -1;
 		if(color == Piece.WHITE) { // black and white have an opposite direction behavior
@@ -37,7 +40,66 @@ public class Pawn extends Piece {
 		arrival = new Position(p.getX() - 1, p.getY() + y);
 		if(b.isEnemy(arrival, p)) { moves.add(arrival); }
 
+
+
+		if(Piece.WHITE == color){
+			if(p.getY() == 5){
+				enPassantEnemy = new Position(p.getX()-1,p.getY());
+				arrival = new Position(p.getX()-1,p.getY()+1);
+				if(b.isEnemy(enPassantEnemy,p)&&
+						b.isPawn(enPassantEnemy)&&
+						((Pawn) b.getPiece(enPassantEnemy)).isEnPassant()&&
+						b.isFree(arrival)){
+						moves.add(arrival);
+				}
+
+				enPassantEnemy = new Position(p.getX()+1,p.getY());
+				arrival = new Position(p.getX()+1,p.getY()+1);
+				if(b.isEnemy(enPassantEnemy,p)&&
+						b.isPawn(enPassantEnemy)&&
+						((Pawn) b.getPiece(enPassantEnemy)).isEnPassant()&&
+						b.isFree(arrival)){
+					moves.add(arrival);
+				}
+			}
+
+		}else {
+			if(p.getY() == 4){
+
+				enPassantEnemy = new Position(p.getX()-1,p.getY());
+				arrival = new Position(p.getX()-1,p.getY()-1);
+				if(b.isEnemy(enPassantEnemy,p)&&
+						b.isPawn(enPassantEnemy)&&
+						((Pawn) b.getPiece(enPassantEnemy)).isEnPassant()&&
+						b.isFree(arrival)){
+					moves.add(arrival);
+				}
+
+				enPassantEnemy = new Position(p.getX()+1,p.getY());
+				arrival = new Position(p.getX()+1,p.getY()-1);
+				if(b.isEnemy(enPassantEnemy,p)&&
+						b.isPawn(enPassantEnemy)&&
+						((Pawn) b.getPiece(enPassantEnemy)).isEnPassant()&&
+						b.isFree(arrival)){
+					moves.add(arrival);
+				}
+			}
+		}
+
+
 		return moves;
+
+
+	}
+
+
+	public boolean isEnPassant() {
+		return enPassant;
 	}
+
+	public void setEnPassant(boolean enPassant) {
+		this.enPassant = enPassant;
+	}
+
 }
 
-- 
GitLab