Scala Programming - Recursive functions based on Shapes and Location