Orig Description
Problem D:Battle Town
You decided to develop a game with your friends.
The title of the game is "Battle Town".
The game is themed around urban tank warfare.
As the first step in game development, you decided to develop the following prototype.
In this prototype, only the player's tank appears, and the enemy tanks do not appear.
The player's tank performs various actions on the map according to the player's input.
Below are specifications for tank behavior.
The map elements are as shown in Table 1.
Tanks can only move on flat terrain in the map.
Table 1: Map elements
CharacterElement
.Flat terrain
*Brick wall
#Iron wall
-Water
^Tank (Facing up)
vTank (Facing down)
Tank (Facing right)
The player's input is given as a sequence of characters.
The corresponding actions for each character are as shown in Table 2.
Table 2: Actions for player input
CharacterAction
U
Up: Rotate the tank upward, and if the space above the tank is flat terrain, move to that space
D
Down: Rotate the tank downward, and if the space below the tank is flat terrain, move to that space
L
Left: Rotate the tank to the left, and if the space to the left of the tank is flat terrain, move to that space
R
Right: Rotate the tank to the right, and if the space to the right of the tank is flat terrain, move to that space
S
Shoot: Fire a bullet in the direction the tank is currently facing
Bullets continue to move straight until they hit a brick wall or iron wall or go outside of the map.
If a bullet hits a brick wall, the bullet disappears, and the brick wall changes to flat terrain.
If a bullet hits an iron wall, the bullet disappears, but the iron wall does not change.
When the bullet goes outside of the map, the bullet disappears as it is.
Your task is to create a program that outputs the final map state when the initial map and player input sequence are given.
Input
The first line of the input contains an integer T, which represents the number of datasets.
(0 < T ≤ 100).
This is followed by T datasets.
The first line of each dataset contains two integers, H and W
Extracted Specification
An integer T (0 < T ≤ 100), representing the number of datasets.
For each dataset:
1. An integer H, representing some quantity or size.
2. An integer W, representing some quantity or size.
3. A list of H strings, each of length W, consisting of characters from the set {'.', '*', '#', '-', '^', 'v', '<', '>'}.
4. A string, consisting of characters from the set {'U', 'D', 'L', 'R', 'S'}.
### Example Input:
```
1
4 4
....
.^..
....
....
UDLSR
```
### Function Signature:
Write a function f(inputs) that takes in the input.
```python
def f(inputs: List[Tuple[int, int, int, List[str], str]]):
'''
inputs: a list of tuples, where each tuple contains:
- an integer
- an integer
- a list of strings
- a string
'''
```
Test Case Generator
Certainly! Below is a test case generator for the given "Battle Town" problem statement. The generator will produce multiple datasets according to the constraints and specifications provided.
```python
import random
def generate_map(H, W):
elements = ['.', '*', '#', '-', '^', 'v', '<', '>']
game_map = []
for _ in range(H):
row = ''.join(random.choice(elements) for _ in range(W))
game_map.append(row)
return game_map
def generate_action_sequence(length):
actions = ['U', 'D', 'L', 'R', 'S']
action_sequence = ''.join(random.choice(actions) for _ in range(length))
return action_sequence
def tcgen():
T = random.randint(1, 100)
datasets = []
for _ in range(T):
H = random.randint(1, 20)
W = random.randint(1, 20)
game_map = generate_map(H, W)
action_sequence_length = random.randint(1, 50)
action_sequence = generate_action_sequence(action_sequence_length)
datasets.append((H, W, game_map, action_sequence))
return T, datasets
# Example usage
T, datasets = tcgen()
print('Number of datasets:', T)
for i, (H, W, game_map, action_sequence) in enumerate(datasets):
print(f"Dataset {i+1}:")
print(H, W)
for row in game_map:
print(row)
print(action_sequence)
```
### Explanation:
1. **`generate_map(H, W)` function:**
- This function generates a map of height `H` and width `W` filled with random map elements (flat terrain, brick wall, iron wall, water, tanks facing different directions).
2. **`generate_action_sequence(length)` function:**
- This function generates a random sequence of actions (`U`, `D`, `L`, `R`, `S`) of the given length.
3. **`tcgen()` function:**
- This function generates the complete test case. It first decides the number of datasets `T` (between 1 and 100).
- For each dataset, it generates random values for `H` and `W` (both between 1 and 20 for simplicity in the example). It then creates a map and an action sequence.
- All datasets are stored in a list and returned.
### Example Usage:
- The example usage part at the end demonstrates how to call the `tcgen()` function and print the generated datasets.
Feel free to adjust the ranges and parameters to better fit the constraints or specific requirements of your problem.
Extract Arguments
def extract_arguments(fh):
T = int(fh.readline().strip())
datasets = []
for _ in range(T):
H, W = map(int, fh.readline().strip().split())
map_data = [fh.readline().strip() for _ in range(H)]
commands = fh.readline().strip()
datasets.append((H, W, map_data, commands))
return datasets
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# datasets = extract_arguments(fh)
# for data in datasets:
# f(data)