From 16367bd88fdbbc4865fcfb2f2ed5be87c3f9bbc6 Mon Sep 17 00:00:00 2001
From: Alan <alanjfogel@gmail.com>
Date: Fri, 31 Jan 2025 13:23:32 -0600
Subject: [PATCH] Added upgrades for pawns

---
 scripts/Pawn.gd  | 14 +++++++++++++-
 scripts/Piece.gd |  5 +++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/scripts/Pawn.gd b/scripts/Pawn.gd
index 13dc0b0..bd1c304 100644
--- a/scripts/Pawn.gd
+++ b/scripts/Pawn.gd
@@ -2,8 +2,13 @@ extends Piece
 
 class_name Pawn
 
+enum Upgrade { DOUBLE_MOVE, DIAGONAL_MOVE }
+
 func _init(is_white: bool, position: Vector2):
 	super._init(is_white, position)
+	# Testing upgrades
+	upgrades.append(Upgrade.DOUBLE_MOVE)
+	upgrades.append(Upgrade.DIAGONAL_MOVE)
 
 
 func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
@@ -13,7 +18,7 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
 
 	if is_white:
 		# Check if the pawn is at the starting position
-		if y > 6 and board_state[x][y - 1] == null:
+		if (y == 7 or Upgrade.DOUBLE_MOVE in upgrades) and board_state[x][y - 1] == null:
 			valid_moves.append(Vector2(x, y - 1))
 			if board_state[x][y - 2] == null:
 				valid_moves.append(Vector2(x, y - 2))
@@ -25,6 +30,13 @@ func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
 			valid_moves.append(Vector2(x - 1, y - 1))
 		if x < 7 and y > 0 and board_state[x + 1][y - 1] != null and not board_state[x + 1][y - 1].is_white:
 			valid_moves.append(Vector2(x + 1, y - 1))
+		
+		# Check if the pawn can move diagonally without capturing
+		if Upgrade.DIAGONAL_MOVE in upgrades:
+			if x > 0 and y > 0 and board_state[x - 1][y - 1] == null:
+				valid_moves.append(Vector2(x - 1, y - 1))
+			if x < 7 and y > 0 and board_state[x + 1][y - 1] == null:
+				valid_moves.append(Vector2(x + 1, y - 1))
 
 	else:
 		if y < 1 and board_state[x][y + 1] == null:
diff --git a/scripts/Piece.gd b/scripts/Piece.gd
index 185059d..9a7de82 100644
--- a/scripts/Piece.gd
+++ b/scripts/Piece.gd
@@ -5,6 +5,11 @@ class_name Piece
 # Properties
 var piece_position: Vector2
 var is_white: bool
+
+# Array for upgrades
+var upgrades: Array = []
+
+
 # initialization method
 func _init(is_white: bool, piece_position: Vector2) -> void:
 	self.is_white = is_white
-- 
GitLab