Skip to content

Instantly share code, notes, and snippets.

@onodes
Created January 11, 2010 12:37
Show Gist options
  • Save onodes/274203 to your computer and use it in GitHub Desktop.
Save onodes/274203 to your computer and use it in GitHub Desktop.
#niku.rb
#
#
#
#
require 'rubygems'
require 'pp'
require 'narray'
class Cell
@@def_table = Array.new(13).map{Array.new(26)}#NArray.int(13,26)
@@new_table = Array.new(13).map{Array.new(26)}#NArray.int(13,26)
def initialize(x,y,data)
@@def_table[x][y] = data
@@new_table[x][y] = data == ' ' ? '$' : data
@@start = [x,y] if data =='S'
@@goal = [x,y] if data == 'G'
@x = x
@y = y
end
def get_table(str)
pp str=='new' ? @@new_table : @@def_table
end
def get_weight
return [@x,@y]
end
def around_weight
end
end
data = File.open("q.txt","r")
instance_table = Array.new(13).map{Array.new(26)}
lines = []
line_num = 0
data.each do |line|
state_num = 0
lines[line_num] = line.chomp!
lines[line_num].split(//).each do |state|
#pp state_num
#pp line_num
#pp state_num
# pp Cell.new(line_num,state_num,state_num)
instance_table[line_num][state_num] = Cell.new(line_num,state_num,state)
state_num += 1
end
line_num += 1
end
#pp lines
pp instance_table[1][1].get_table('new')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment