Created
April 8, 2015 03:50
-
-
Save anonymous/e6d5555887927581b1a0 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
def load_board(file) | |
gameboard = File.readlines(file)[1..-1] | |
gameboard.map! do |line| | |
line.split.map(&:to_s) | |
end | |
$globalboard = gameboard | |
end | |
def pp_board(board) | |
puts Array.new(board[0].size*2+4, '-').join('') | |
board.each do |row| | |
puts "|" + row.join('|') + "|" | |
puts Array.new(row.size*2+4, '-').join('') | |
end | |
end | |
def create_hint_board(board) | |
hintboard = [[],[]] | |
board.each{ |row| | |
row.each { |col| | |
if board[row][col] != "*" | |
hintboard[row][col] = 0 | |
end | |
if board[row][col] = "*" | |
hintboard[row+1][col+1] += 1 | |
hintboard[row-1][col-1] += 1 | |
hintboard[row+1][col-1] += 1 | |
hintboard[row-1][col+1] += 1 | |
end | |
} | |
} | |
end | |
load_board('mines.txt') | |
create_hint_board($globalboard) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment