# Problem Description
This is a problem about a tank moving through a 1D map with obstacles. The tank needs to traverse from left to right, starting at index 0. The tank has two states: 'ready' and 'loading'. The goal is to determine if the tank can successfully reach the end of the map.

# Visual Facts
1. The map is represented as a 1D array with indices starting from 0
2. The tank starts at index 0 in 'ready' state (shown by green indicator)
3. Black blocks represent obstacles ('x' in the code)
4. Empty spaces are shown as blank cells ('.' in the code)
5. The tank has two states:
   - Ready (green)
   - Loading (red)
6. The image shows multiple test cases with success/failure outcomes
   - Example 1: the map has only one obstacle, which the tank can handle
   - Example 2: the map has one obstacle, we can see that after the tank breaks the first obstacle, it turns to 'loading' state. While after moving to the next empty cell, it turns back to 'ready' state
   - Example 3: the map has two consecutive obstacles, the tank first breaks the first obstacle and turns to 'loading' state. Then it encounters the second obstacle, which leads to failure
   - Example 4：the map has two obstacles with a space between them, the tank can successfully pass through

# Visual Patterns
1. Tank State Transition Rules:
   - When in 'ready' state (green), the tank can break through one obstacle and transitions to 'loading' state
   - When in 'loading' state (red), the tank cannot break through obstacles

2. Success Conditions:
   - The tank successfully passes if it can reach the end without encountering obstacles while in 'loading' state
   - Single obstacles can be handled when the tank is in 'ready' state

3. Failure Conditions:
   - The tank fails if it encounters an obstacle while in 'loading' state
   - The tank fails if it encounters two consecutive obstacles ('x') because:
     * First obstacle changes state from ready to loading
     * Second obstacle cannot be handled in loading state

4. Key Pattern:
   - The fundamental pattern is that two consecutive obstacles ('xx') always leads to failure
   - Any other arrangement of obstacles with at least one space between them can be passed successfully


# Solution
from typing import List

def solution(input_map: List[str]) -> bool:
    """
    Determines if a tank can successfully navigate through a 1D map.

    Args:
        input_map (List[str]): A list of strings representing the map layout, where:
            - '.' represents an empty space
            - 'x' represents an obstacle

    Returns:
        bool: True if the tank can successfully navigate through the map, False otherwise.
    """
    state = 'ready'
    for cell in input_map:
        if cell == 'x':
            if state == 'ready':
                state = 'loading'
            else:
                return False
        else:
            state = 'ready'
    return True


# Test Script
def test():
    test_cases = [
        {
            "input_map": [".", ".", "x"],
            "expected": True
        },
        {
            "input_map": [".", "x", "x"],
            "expected": False
        },
        {
            "input_map": [".", "x", ".", "x", "."],
            "expected": True
        },
        {
            "input_map": [".", "x", "x", "x", "."],
            "expected": False
        },
        {
            "input_map": [".", ".", ".", "x", "x"],
            "expected": False
        },
        {
            "input_map": [".", ".", ".", ".", "x", ".", "x"],
            "expected": True
        },
        {
            "input_map": [".", ".", ".", "x", "x", ".", "x"],
            "expected": False
        },
    ]

    for i, test_case in enumerate(test_cases, start=1):
        try:
            output = solution(test_case["input_map"])
        except Exception as e:
            error_message = (
                f"An exception occurred while running the test case:\n"
                f"`input_map`: {test_case['input_map']}\n\n"
                f"Exception: '{str(e)}'"
            )
            assert False, error_message

        if output != test_case["expected"]:
            error_message = (
                f"The following Test Case failed:\n"
                f"`input_map`: {test_case['input_map']}\n\n"
                f"Actual Output: {output}\n"
                f"Expected Output: {test_case['expected']}"
            )
            assert False, error_message

test()