extends Piece

class_name Knight

enum Upgrade {
	LONGER_L_MOVE,
}

func _init(is_white_param: bool, position_param: Vector2):
	super._init(is_white_param, position_param)
	# Testing upgrades
	#upgrades.append(Upgrade.LONGER_L_MOVE)

func get_valid_moves(board_state: Array, pos: Vector2) -> Array[Vector2]:
	var valid_moves: Array[Vector2] = []
	var x = pos.x
	var y = pos.y

	# Define all possible moves for a knight
	var moves = [
		Vector2(x + 2, y + 1), Vector2(x + 2, y - 1),
		Vector2(x - 2, y + 1), Vector2(x - 2, y - 1),
		Vector2(x + 1, y + 2), Vector2(x + 1, y - 2),
		Vector2(x - 1, y + 2), Vector2(x - 1, y - 2)
	]
	
	# Check for LONGER_L_MOVE upgrade
	if Upgrade.LONGER_L_MOVE in upgrades:
		moves += [
			Vector2(x + 3, y + 1), Vector2(x + 3, y - 1),
			Vector2(x - 3, y + 1), Vector2(x - 3, y - 1),
			Vector2(x + 1, y + 3), Vector2(x + 1, y - 3),
			Vector2(x - 1, y + 3), Vector2(x - 1, y - 3)
		]
	for move in moves:
		if move.x >= 0 and move.x < 8 and move.y >= 0 and move.y < 8:
			if board_state[move.x][move.y] == null or board_state[move.x][move.y].is_white != is_white:
				valid_moves.append(move)

	return valid_moves