Skip to content

Instantly share code, notes, and snippets.

@yvan
Created November 5, 2017 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yvan/b402af3eb54724993973c10ef3f81cd3 to your computer and use it in GitHub Desktop.
Save yvan/b402af3eb54724993973c10ef3f81cd3 to your computer and use it in GitHub Desktop.
import random
import numpy as np
def display_cave(matrix):
for i in range(matrix.shape[0]):
for j in range(matrix.shape[1]):
char = "#" if matrix[i][j] == WALL else "."
print(char, end='')
print()
# the cave should be 42x42
shape = (42,42)
# walls will be 0
# floors will be 1
WALL = 0
FLOOR = 1
# create a random map choosing
# walls 40% of the time, floor
# 60% of the time.
new_map = np.ones(shape)
# for each row
for i in range(shape[0]):
# for each column
for j in range(shape[1]):
# choose a number between 0-1
choice = random.uniform(0, 1)
# choose a wall or a floor
new_map[i][j] = WALL if choice < 0.5 else FLOOR
display_cave(new_map)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment