Created
November 5, 2017 15:18
-
-
Save yvan/b402af3eb54724993973c10ef3f81cd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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