Draft

2D Player Movement

Description:

You're making a basic 2D game, and you're trying to write a simple alogrithm that determines if the user can move the player in any given direction.

Given a 2D Array of binary digits (arr), and the players current position (pos) return True if the player can move up, down, left, and right. else return False.

A 0 indicates the player can move to that position while a 1 indicates a player can NOT move to that position.

Example:
arr = [[0, 1, 0, 0, 1],
       [1, 1, 0, 1, 1],
       [0, 0, 1, 0, 0],
       [0, 1, 0, 0, 1],
       [1, 0, 0, 1, 0]]
pos = (3,3)

This example should return False, as the player can move up or left, but the player can NOT move down or right.

The player can't move through an edge. You'll need to handle potential listIndex errors for edge positions.

The value of the players current position is irrelivent.

Arrays
Lists
Algorithms
Fundamentals

More By Author:

Check out these other kata created by ok-john

Stats:

CreatedFeb 24, 2019
Warriors Trained6
Total Skips0
Total Code Submissions6
Total Times Completed4
Python Completions4
Total Stars1
% of votes with a positive feedback rating50% of 2
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes0
Total Rank Assessments2
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • ok-john Avatar
Ad