extends Piece

class_name Rook

enum Upgrade {
	DIAGONAL_MOVE_ONE,
}

func _init(is_white: bool, position: Vector2):
	super._init(is_white, position)

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

	# Check moves to the right
	for i in range(x + 1, 8):
		if board_state[i][y] == null:
			valid_moves.append(Vector2(i, y))
		elif board_state[i][y] != null and not board_state[i][y].is_white:
			valid_moves.append(Vector2(i, y))
			break
		else:
			break

	# Check moves to the left
	for i in range(x - 1, -1, -1):
		if board_state[i][y] == null:
			valid_moves.append(Vector2(i, y))
		elif board_state[i][y] != null and not board_state[i][y].is_white:
			valid_moves.append(Vector2(i, y))
			break
		else:
			break

	# Check moves upwards
	for i in range(y - 1, -1, -1):
		# Check if the square is empty
		if board_state[x][i] == null:
			valid_moves.append(Vector2(x, i))
		# Check if the square has an enemy piece
		elif board_state[x][i] != null and not board_state[x][i].is_white:
			valid_moves.append(Vector2(x, i))
			break
		else:
			break

	# Check moves downwards
	for i in range(y + 1, 8):
		# Check if the square is empty
		if board_state[x][i] == null:
			valid_moves.append(Vector2(x, i))
		# Check if the square has an enemy piece
		elif board_state[x][i] != null and not board_state[x][i].is_white:
			valid_moves.append(Vector2(x, i))
			break
		else:
			break

	return valid_moves