automaze 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- automazerb
1
+ automaze
2
2
 
3
3
  The MIT License
4
4
 
data/README.rdoc CHANGED
@@ -1,8 +1,12 @@
1
1
 
2
- = automazerb
2
+ = automaze
3
3
 
4
4
  == description
5
- automazerb is maze generator library for ruby.
5
+ automaze is a maze generator library for ruby.
6
+ some algorithms include.
7
+
8
+ ex) Boutaoshi (simple)
9
+ DugTunnels (little complex)
6
10
 
7
11
  == installation
8
12
 
@@ -12,11 +16,13 @@ automazerb is maze generator library for ruby.
12
16
 
13
17
  require "automaze"
14
18
  maze = Automaze::Automaze.new
15
- puts maze
19
+ puts maze # printing maze
16
20
 
21
+ # access panels(x, y)
17
22
  panel = maze.panels(3,4)
18
23
  panel.wall? #=> true or false
19
24
 
25
+ # each panels
20
26
  maze.each_panels do |panel,x,y|
21
27
  if panel.wall?
22
28
  print "XX"
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ begin
23
23
  gemspec.summary = "maze generator"
24
24
  gemspec.email = "toshi.hirooka@gmail.com"
25
25
  gemspec.homepage = "http://github.com/tosik/automazerb"
26
- gemspec.description = "maze generator"
26
+ gemspec.description = "automaze is a maze generator library for ruby."
27
27
  gemspec.authors = ["Toshiyuki Hirooka"]
28
28
 
29
29
  gemspec.add_dependency("activesupport", ">= 3.0.1")
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/automaze.gemspec CHANGED
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{automaze}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Toshiyuki Hirooka"]
12
12
  s.date = %q{2010-10-31}
13
- s.description = %q{maze generator}
13
+ s.description = %q{automaze is a maze generator library for ruby.}
14
14
  s.email = %q{toshi.hirooka@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -11,15 +11,10 @@ module DugTunnels
11
11
  init_panels
12
12
 
13
13
  # start point
14
- xy = random_even_xy
15
- panels(*xy).set_kind(:floor)
16
-
17
- while !dug_all?
14
+ panels(*random_even_xy).set_kind(:floor)
18
15
 
19
- # select random floor
20
- begin
21
- xy = random_even_xy
22
- end while panels(*xy).wall?
16
+ until dug_all?
17
+ xy = random_floor_xy(even_hash_panels)
23
18
 
24
19
  while can_dig(*xy)
25
20
  dir = random_direction
@@ -34,11 +29,7 @@ module DugTunnels
34
29
  end
35
30
 
36
31
  def random_direction
37
- return rand(4)
38
- @dir ||= 0
39
- @dir += 1
40
- @dir = 0 if @dir == 4
41
- @dir
32
+ rand(4)
42
33
  end
43
34
 
44
35
  def next_xy(x, y, dir)
@@ -54,10 +45,6 @@ module DugTunnels
54
45
  panels(*next_xy(x, y, dir))
55
46
  end
56
47
 
57
- def random_even_xy
58
- [rand(@size_x/2 + 1) * 2, rand(@size_y/2 + 1) * 2]
59
- end
60
-
61
48
  def can_dig(x, y)
62
49
  (0..3).each do |dir|
63
50
  unless out_of_map?(*next_xy(x, y, dir))
@@ -73,7 +60,6 @@ module DugTunnels
73
60
  return false if panel.wall?
74
61
  end
75
62
  end
76
-
77
63
  return true
78
64
  end
79
65
 
data/lib/automaze.rb CHANGED
@@ -27,12 +27,12 @@ require "panel"
27
27
 
28
28
  module Automaze
29
29
  class Automaze
30
- DEFAULT_ALGORITHM = :boutaoshi
30
+ DEFAULT_ALGORITHM = :dug_tunnels
31
31
 
32
32
  class << self
33
33
  def include_algorithm(algorithm)
34
34
  raise "cannot include because algorithm is nil" if algorithm.nil?
35
- require_relative "algorithms/#{algorithm.to_s}"
35
+ require "algorithms/#{algorithm.to_s}"
36
36
  include algorithm.to_s.camelize.constantize
37
37
  end
38
38
  end
@@ -78,11 +78,27 @@ module Automaze
78
78
  ]
79
79
  end
80
80
 
81
+ def even_hash_panels
82
+ @panels.select {|xy, panel|
83
+ xy[0].even? && xy[1].even?
84
+ }
85
+ end
86
+
81
87
  def random_floor(panels)
82
- loop do
83
- panel = panels[rand(panels.length)]
84
- return panel if panel.floor?
85
- end
88
+ floors = panels.select {|panel| panel.floor?}
89
+ raise "no floors" if floors.empty?
90
+ floors[rand(floors.length)]
91
+ end
92
+
93
+ def random_even_xy
94
+ [rand(@size_x/2 + 1) * 2, rand(@size_y/2 + 1) * 2]
95
+ end
96
+
97
+ def random_floor_xy(hash_panels)
98
+ floors = hash_panels.select {|xy, panel| panel.floor?}
99
+ raise "no floors" if floors.empty?
100
+ return floors.to_a.first.first if floors.length == 1
101
+ floors.to_a[rand(floors.length)].first
86
102
  end
87
103
 
88
104
  def out_of_map?(x, y)
data/sample.rb CHANGED
@@ -2,11 +2,15 @@ $: << "lib"
2
2
  require "automaze"
3
3
 
4
4
  algorithm = ARGV[0] || :dug_tunnels
5
+
6
+ start = Time.now
5
7
  maze = Automaze::Automaze.new(
6
8
  :algorithm=>algorithm,
7
9
  :size_x=>40,
8
10
  :size_y=>30)
9
11
 
12
+ puts "#{Time.now - start} seconds"
13
+
10
14
  # building rooms
11
15
  5.times do
12
16
  room_size_x = rand(2) * 2 + 1
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Toshiyuki Hirooka
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 3.0.1
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
- description: maze generator
35
+ description: automaze is a maze generator library for ruby.
36
36
  email: toshi.hirooka@gmail.com
37
37
  executables: []
38
38