Hello, and welcome, code explorer! Today's journey takes us through the intricate paths within a 2-dimensional array, often likened to a game board. Our mission is to identify ideal spots for game piece placement. Sounds like an adventure, doesn't it? Let's embark!
Visualize a chessboard as a 2D array. Each cell contains either 'E' for an empty cell or 'P' for a cell that already has a piece.
Your task is to write a Python function named find_positions() that returns every empty cell where we could place a new piece and that new piece would have at least one legal move on its next turn.
A legal move means moving from the placed piece's cell to another empty cell that is immediately adjacent:
- directly above, below, left, or right
- not diagonally
Consider this 4x4 board for instance:
The function should render an output as: [(0, 1), (0, 2), (1, 2), (2, 1), (3, 1)]. This output represents the positions where a new piece can fit perfectly and then be able to move in the next turn.
Stepping right into action, we start with an empty positions list to help us log the sought positions. Understanding the dimensions of our ‘board’ paves the way for defining boundaries in our exploration mission. Now, how does one determine the size of a Python list? The answer lies in Python's function.
