Last active
          December 20, 2015 23:49 
        
      - 
      
- 
        Save wallstop/6215868 to your computer and use it in GitHub Desktop. 
    Daily Programming Challenge #131
  
        
  
    
      This file contains hidden or 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 math | |
| def raycast(grid, x, y, radian): | |
| radian += math.pi | |
| unitVector = [math.cos(radian), math.sin(radian)] | |
| found = False | |
| while not found: | |
| x += unitVector[0] | |
| y += unitVector[1] | |
| # Collision found | |
| if(grid[int(x)][int(y)]): | |
| found = True | |
| prevBox = [int(x - unitVector[0]), int(y - unitVector[1])] | |
| if prevBox[0] == int(x): | |
| y = int(y) | |
| elif prevBox[1] == int(y): | |
| x = int(x) | |
| print("x: " + str(round(x, 3)) + " y: " + str(round(y, 3))) | |
| def handleInput(): | |
| rowsCols = input("Rows and Columns: ").split() | |
| rows = int(rowsCols[0]) | |
| cols = int(rowsCols[1]) | |
| grid = "" | |
| print("Enter grid:") | |
| for x in range(0, rows): | |
| grid += input() | |
| if len(grid) != rows * cols: | |
| print("Invalid grid size!") | |
| return False | |
| gridArray = [[0 for x in range(cols)] for y in range(rows)] | |
| for x in range(0, cols): | |
| for y in range(0, rows): | |
| if grid[x*cols + y] == 'x': | |
| gridArray[x][y] = 1 | |
| elif grid[x*cols + y] == ' ': | |
| gridArray[x][y] = 0 | |
| else: | |
| print("Invalid grid!") | |
| return False | |
| x = float(input("X pos: ")) | |
| if x < 0 or x >= cols: | |
| print("Invalid X coordinate!") | |
| return False | |
| y = float(input("Y pos: ")) | |
| if y < 0 or y >= rows: | |
| print("Invalid Y coordinate!") | |
| return False | |
| radian = float(input("Z pos: ")) | |
| raycast(gridArray, x, y, radian) | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment