[code]
import numpy as np
# Create a 10x10 matrix with all zeros
grid = np.zeros((10, 10))
# Place some rocks and food in the grid
grid[2, 2] = -1 # Rock
grid[5, 7] = -1 # Rock
grid[3, 6] = 1 # Food
grid[8, 1] = 1 # Food
# Set the character's starting position
x, y = 0, 0
# Move the character through the grid
while True:
# Display the grid and the character's position
for i in range(10):
for j in range(10):
if i == y and j == x:
print('C', end=' ') # Character
elif grid[i, j] == -1:
print('X', end=' ') # Rock
elif grid[i, j] == 1:
print('F', end=' ') # Food
elif grid[i, j] == 2:
print('*', end=' ') # Path
else:
print('_', end=' ') # Empty
print()
# Check for food and rocks at the current position
if grid[y, x] == -1:
print("Oops! You hit a rock.")
break
elif grid[y, x] == 1:
print("Yum! You found some food.")
grid[y, x] = 0
# Mark the current position as a path
grid[y, x] = 2
# Prompt the user for the next move
direction = input("Which way do you want to move? (up/down/left/right) ")
# Update the character's position based on the input
if direction == 'up' and y > 0:
y -= 1
elif direction == 'down' and y < 9:
y += 1
elif direction == 'left' and x > 0:
x -= 1
elif direction == 'right' and x < 9:
x += 1
else:
print("Invalid move. Try again.")
# Clear the console to make the grid easier to read
print("\n" * 100)
[/code]