gondorlibrary 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +21 -0
- data/License +21 -0
- data/MANIFEST +18 -0
- data/README +40 -0
- data/Rakefile +138 -0
- data/gondorlibrary.rb +26 -0
- data/lib/entity.rb +163 -0
- data/lib/exception.rb +14 -0
- data/lib/messages.rb +44 -0
- data/lib/queue.rb +80 -0
- data/lib/relationships.rb +40 -0
- data/test/test_entity.rb +73 -0
- data/test/test_messages.rb +40 -0
- data/test/test_queue.rb +50 -0
- data/test/test_relationships.rb +44 -0
- metadata +78 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
== gondorlibrary
|
|
2
|
+
|
|
3
|
+
Copyright (c) Mar 31, 2008 Phillip Gawlowski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/License
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
== gondorlibrary
|
|
2
|
+
|
|
3
|
+
Copyright (c) Mar 31, 2008 Phillip Gawlowski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/MANIFEST
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
lib/entity.rb
|
|
2
|
+
lib/exception.rb
|
|
3
|
+
lib/messages.rb
|
|
4
|
+
lib/queue.rb
|
|
5
|
+
lib/relationships.rb
|
|
6
|
+
gondorlibrary.rb
|
|
7
|
+
html
|
|
8
|
+
lib
|
|
9
|
+
License
|
|
10
|
+
MANIFEST
|
|
11
|
+
nbproject
|
|
12
|
+
Rakefile
|
|
13
|
+
README
|
|
14
|
+
test
|
|
15
|
+
test/test_entity.rb
|
|
16
|
+
test/test_messages.rb
|
|
17
|
+
test/test_queue.rb
|
|
18
|
+
test/test_relationships.rb
|
data/README
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
=gondorlibrary
|
|
2
|
+
|
|
3
|
+
The Gondor Library enables users of the Ruby language (on the MRI, JRuby or IronRuby)
|
|
4
|
+
to quickly implement agents for all kinds of situations (for example game AI, or
|
|
5
|
+
stock market modeling), while focusing on the task at hand, instead of writing a
|
|
6
|
+
full agent simulation.
|
|
7
|
+
|
|
8
|
+
It is currently fully implemented in Ruby itself, with no outside dependencies.
|
|
9
|
+
|
|
10
|
+
=Installation and Usage
|
|
11
|
+
|
|
12
|
+
gem install gondorlibrary
|
|
13
|
+
|
|
14
|
+
require "rubygems"
|
|
15
|
+
require "gondor"
|
|
16
|
+
|
|
17
|
+
braveheart = Gondor::AI:Entity.new("William Wallace")
|
|
18
|
+
braveheart.killed_english_men 100
|
|
19
|
+
braveheart.update_killed_english_men 50
|
|
20
|
+
puts braveheart.killed_english_men
|
|
21
|
+
|
|
22
|
+
Get the source:
|
|
23
|
+
|
|
24
|
+
svn checkout http://gondorlibrary.googlecode.com/svn/trunk/ gondorlibrary-read-only
|
|
25
|
+
|
|
26
|
+
=About
|
|
27
|
+
Milestone 1 (Version 0.1.0) contains a very basic, but working Entity system, featuring message sending, queues, and flexible entity creation.
|
|
28
|
+
|
|
29
|
+
=Features
|
|
30
|
+
|
|
31
|
+
* Entity attributes, that can be changed over time, and can be arbitrarily defined at runtime (either at the first call, or beforehand).
|
|
32
|
+
* Simple message queuing and retrieval (nothing more implemented yet).
|
|
33
|
+
|
|
34
|
+
=The Near Future
|
|
35
|
+
GL will receive its own language (a DSL, I guess), to create rules and messages for the entities, to make use as easy as possible.
|
|
36
|
+
|
|
37
|
+
= Online
|
|
38
|
+
* Project home and source code and end user documentation: http://code.google.com/p/gondorlibrary/
|
|
39
|
+
* API and hacker's documentation: http://gondorlibrary.rubyforge.org/
|
|
40
|
+
* Discussion: http://groups.google.com/group/gondor-library-discussion
|
data/Rakefile
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#
|
|
2
|
+
# ENV['svn']: SVN log message
|
|
3
|
+
# ENV['version']: Gondor Library Version to release
|
|
4
|
+
#
|
|
5
|
+
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'rake'
|
|
8
|
+
require 'rake/testtask'
|
|
9
|
+
require 'rake/rdoctask'
|
|
10
|
+
require 'rcov/rcovtask'
|
|
11
|
+
require "rake/gempackagetask"
|
|
12
|
+
require 'FileUtils'
|
|
13
|
+
|
|
14
|
+
#Helper to make GMail work.
|
|
15
|
+
#See http://d.hatena.ne.jp/zorio/20060416 and
|
|
16
|
+
#http://www.jamesbritt.com/2007/12/18/sending-mail-through-gmail-with-ruby-s-net-smtp
|
|
17
|
+
#require 'smtp_tls'
|
|
18
|
+
|
|
19
|
+
RCOV = "rcov"
|
|
20
|
+
GL_DEFAULT_VERSION = "0.1.0"
|
|
21
|
+
|
|
22
|
+
ENV['version'] = GL_DEFAULT_VERSION unless ENV['version']
|
|
23
|
+
|
|
24
|
+
task :default => ["test"]
|
|
25
|
+
task :all => ["coverage","rdoc"]
|
|
26
|
+
task :gem => ["coverage"]
|
|
27
|
+
|
|
28
|
+
desc "runs all tests without RCov"
|
|
29
|
+
Rake::TestTask.new("test") do |test|
|
|
30
|
+
#test.name = "test"
|
|
31
|
+
test.warning = true
|
|
32
|
+
test.verbose = true
|
|
33
|
+
test.test_files = FileList['test/test*.rb']
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
desc "Runs tests with coverage by RCov"
|
|
37
|
+
Rcov::RcovTask.new do |task|
|
|
38
|
+
task.libs << "test"
|
|
39
|
+
task.name = "coverage"
|
|
40
|
+
task.test_files = FileList["test/test*.rb"]
|
|
41
|
+
task.verbose = true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
desc "create RDoc documentation"
|
|
45
|
+
rd = Rake::RDocTask.new do |rdoc|
|
|
46
|
+
rdoc.name = "rdoc"
|
|
47
|
+
rdoc.main = "README"
|
|
48
|
+
rdoc.rdoc_files.include("README","LICENSE","lib/*.rb")
|
|
49
|
+
rdoc.options << '--line-numbers' << '--inline-source' <<
|
|
50
|
+
'--main' << 'README' <<
|
|
51
|
+
'--title' << "Gondor Library #{ENV['version']}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
desc "write the MANIFEST out"
|
|
55
|
+
task :manifest do
|
|
56
|
+
files = FileList['lib/**/*.rb', '[A-Z]*', 'test/**/*'].exclude('smtp_tls.rb').to_a
|
|
57
|
+
File.open("MANIFEST","w") do |f|
|
|
58
|
+
f.puts files
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
gem = Gem::Specification.new do |g|
|
|
63
|
+
g.platform = Gem::Platform::RUBY
|
|
64
|
+
g.summary = "A library for agent based computing"
|
|
65
|
+
g.name = "gondorlibrary"
|
|
66
|
+
g.version = ENV['version']
|
|
67
|
+
g.files = FileList['lib/**/*.rb', '[A-Z]*', 'test/**/*'].exclude('smtp_tls.rb').to_a
|
|
68
|
+
# This is needed to include files in ./ by RubyGems. Yes, they are included in FileList.
|
|
69
|
+
g.extra_rdoc_files = ["README", "LICENSE"]
|
|
70
|
+
|
|
71
|
+
g.description = <<EOF
|
|
72
|
+
Gondor Libraray provides a framework to work with agent based computing,
|
|
73
|
+
from game AIs, to swarm simulations.
|
|
74
|
+
EOF
|
|
75
|
+
g.rdoc_options = rd.options
|
|
76
|
+
g.has_rdoc = true
|
|
77
|
+
g.author = "Phillip Gawlowski"
|
|
78
|
+
g.homepage = "http://code.google.com/p/gondorlibrary/"
|
|
79
|
+
g.email = "p.gawlowski@gmail.com"
|
|
80
|
+
g.rubyforge_project = "gondorlibrary"
|
|
81
|
+
end
|
|
82
|
+
desc "Build the #{gem.name} gem"
|
|
83
|
+
Rake::GemPackageTask.new(gem) do |pkg|
|
|
84
|
+
pkg.need_zip = true
|
|
85
|
+
pkg.need_tar = true
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
desc "Publishes RDoc to Rubyforge"
|
|
89
|
+
task :publishdoc => [:rdoc] do
|
|
90
|
+
system "cd html && pscp -load rubyforge -r * cynicalryan@rubyforge.org:/var/www/gforge-projects/gondorlibrary/"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
desc "commit changes to svn"
|
|
94
|
+
task :commit => [:test,:publishdoc] do
|
|
95
|
+
system "svn ci -m \"#{ENV['svn']}\""
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
Rake::PackageTask.new("gondorlibrary", ENV['version']) do |p|
|
|
99
|
+
p.need_tar = true
|
|
100
|
+
p.need_zip = true
|
|
101
|
+
p.package_files.include(FileList['lib/**/*.rb', '[A-Z]*', 'test/**/*'].exclude('smtp_tls.rb').to_a)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
desc "Upload release to RubyForge"
|
|
106
|
+
task :upload => [:test,:package]do
|
|
107
|
+
puts "Loggin into Rubyforge"
|
|
108
|
+
system "rubyforge login"
|
|
109
|
+
puts "Adding release"
|
|
110
|
+
bla = system "rubyforge -n README add_release 5933 7575 #{ENV['version']} pkg/gondorlibrary-#{ENV['version']}.gem"
|
|
111
|
+
puts bla
|
|
112
|
+
system "rubyforge -n README add_release 5933 7575 #{ENV['version']} pkg/gondorlibrary-#{ENV['version']}.tgz"
|
|
113
|
+
system "rubyforge -n README add_release 5933 7575 #{ENV['version']} pkg/gondorlibrary-#{ENV['version']}.zip"
|
|
114
|
+
puts "Adding File"
|
|
115
|
+
bla = system "rubyforgeadd_file 5933 7575 #{ENV['version']} pkg/gondorlibrary-#{ENV['version']}.gem"
|
|
116
|
+
puts bla
|
|
117
|
+
system "rubyforge add_file 5933 7575 #{ENV['version']} pkg/gondorlibrary-#{ENV['version']}.tgz"
|
|
118
|
+
system "rubyforge add_file 5933 7575 #{ENV['version']} pkg/gondorlibrary-#{ENV['version']}.zip"
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
desc "Announce Release"
|
|
122
|
+
#task :announce => [:commit,:upload] do
|
|
123
|
+
# require "net/smtp"
|
|
124
|
+
# from = "Phillip Gawlowski <cmdjackryan@gmail.com>"
|
|
125
|
+
# to = "Ruby Talk ML <ruby-talk@ruby-lang.org>, Gondor Library Discussion <gondor-library-discussion@googlegroups.com>"
|
|
126
|
+
# header =<<EOH
|
|
127
|
+
#From: Phillip Gawlowski <cmdjackryan@gmail.com>
|
|
128
|
+
#To: Ruby Talk ML <ruby-talk@ruby-lang.org>, Gondor Library Discussion <gondor-library-discussion@googlegroups.com>
|
|
129
|
+
#Subject [ANN] Gondor Library #{ENV['version']}
|
|
130
|
+
#EOH
|
|
131
|
+
# message = File.read("README")
|
|
132
|
+
# mail = header + message
|
|
133
|
+
# username = ENV['user']
|
|
134
|
+
# password = ENV['password']
|
|
135
|
+
# Net::SMTP.start('smtp.gmail.com', 597, 'localhost.localdomain', username, password, 'plain' ){|smtp|
|
|
136
|
+
# smtp.send_message(mail, from, to)
|
|
137
|
+
# }
|
|
138
|
+
#end
|
data/gondorlibrary.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) Apr 1, 2008 Phillip Gawlowski
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
# furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
|
12
|
+
# all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
# THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
require 'lib/entity'
|
|
24
|
+
require 'lib/queue'
|
|
25
|
+
require 'lib/relationships'
|
|
26
|
+
require 'lib/messages'
|
data/lib/entity.rb
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) Mar 31, 2008 Phillip Gawlowski
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
# furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
|
12
|
+
# all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
# THE SOFTWARE.
|
|
21
|
+
#
|
|
22
|
+
# The Module Gondor::AI:Entity contains the methods related to +Entities+:
|
|
23
|
+
#
|
|
24
|
+
# You can create a new Entity by passing some, non, or all of the arguments. If
|
|
25
|
+
# for all arguments provided, the instantiation will use the default falues
|
|
26
|
+
# defined in Gondor::AI:Entity:DEFAULT_AI_OPTIONS. However, these options can be
|
|
27
|
+
# overriden at any time.
|
|
28
|
+
#
|
|
29
|
+
# For exmaple:
|
|
30
|
+
#
|
|
31
|
+
# +irb(main):001:0> agent = Gondor::AI::Entity.new+
|
|
32
|
+
# => #<Gondor::AI::Entity:0x2832fa0 @message_queue=[], @y=0, @courage=0, @x=0,
|
|
33
|
+
# @net_worth=0, @name="John Doe", @patience=100, @hunger=100, @z=0>
|
|
34
|
+
#
|
|
35
|
+
# Default values:
|
|
36
|
+
# DEFAULT_AI_OPTIONS = {
|
|
37
|
+
# :name => "John Doe",
|
|
38
|
+
# :hunger => 100,
|
|
39
|
+
# :patience => 100,
|
|
40
|
+
# :courage => 0,
|
|
41
|
+
# :net_worth => 0,
|
|
42
|
+
# :message_queue => [],
|
|
43
|
+
# :x => 0,
|
|
44
|
+
# :y => 0,
|
|
45
|
+
# :z => 0
|
|
46
|
+
# }
|
|
47
|
+
#
|
|
48
|
+
|
|
49
|
+
require "lib/exception"
|
|
50
|
+
|
|
51
|
+
module Gondor
|
|
52
|
+
|
|
53
|
+
module AI
|
|
54
|
+
|
|
55
|
+
class Entity
|
|
56
|
+
# The default values for a new AI +Entity+.
|
|
57
|
+
DEFAULT_AI_OPTIONS = {
|
|
58
|
+
:name => "John Doe",
|
|
59
|
+
:hunger => 0,
|
|
60
|
+
:patience => 0,
|
|
61
|
+
:courage => 0,
|
|
62
|
+
:net_worth => 0,
|
|
63
|
+
:x => 0,
|
|
64
|
+
:y => 0,
|
|
65
|
+
:z => 0,
|
|
66
|
+
:parent => [],
|
|
67
|
+
:child => []
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
attr_accessor :hunger,:name,:courage,:patience,:net_worth
|
|
71
|
+
attr_accessor :x,:y,:z
|
|
72
|
+
attr_reader :parent, :child
|
|
73
|
+
|
|
74
|
+
# Initializes a new Entity with +DEFAULT_AI_OPTIONS+, unless these values
|
|
75
|
+
# are overridden when a new +Entity+ is created.
|
|
76
|
+
def initialize(options = {})
|
|
77
|
+
options = DEFAULT_AI_OPTIONS.merge(options)
|
|
78
|
+
@name = options[:name]
|
|
79
|
+
@hunger = options[:hunger]
|
|
80
|
+
@net_worth = options[:net_worth]
|
|
81
|
+
@courage = options[:courage]
|
|
82
|
+
@patience = options[:patience]
|
|
83
|
+
@x = options[:x]
|
|
84
|
+
@y = options[:y]
|
|
85
|
+
@z = options[:z]
|
|
86
|
+
@parent = options[:parent]
|
|
87
|
+
@child = options[:child]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Modifies the patience value by +update_factor+.
|
|
91
|
+
def update_patience(update_factor)
|
|
92
|
+
@patience += update_factor
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Updates the courage value by +update_factor+.
|
|
96
|
+
def update_courage(update_factor)
|
|
97
|
+
@courage += update_factor
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Updates the hunger value by +update_factor+.
|
|
101
|
+
def update_hunger(update_factor)
|
|
102
|
+
@hunger += update_factor
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Updates the net_worth value by +update_factor+.
|
|
106
|
+
def update_net_worth(update_factor)
|
|
107
|
+
@net_worth += update_factor
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Moves the actor across a *spatial* axis for *distance* units.
|
|
111
|
+
def move(spatial,distance)
|
|
112
|
+
case spatial.downcase
|
|
113
|
+
when "x" then @x += distance
|
|
114
|
+
when "y" then @y += distance
|
|
115
|
+
when "z" then @z += distance
|
|
116
|
+
else raise ArgumentError("Axis not found")
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Returns the current +location+ as +String+
|
|
121
|
+
def entity_location
|
|
122
|
+
"x: #{@x} | y: #{@y} | z: #{@z}"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
# Calculates the relative +distance_to+ an arbitrary actor
|
|
127
|
+
# Note: The algorithm is not yet optimized for speed.
|
|
128
|
+
# Hopefully, it is accurate, though.
|
|
129
|
+
def distance_to(actor)
|
|
130
|
+
# Stub, will use vector math or so to approximate the true distance
|
|
131
|
+
distance = (self.x - actor.x) ** 2 + (self.y - actor.y) ** 2 + (self.z - actor.z) ** 2
|
|
132
|
+
Math::sqrt(distance)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def stats #:nodoc:
|
|
136
|
+
puts "#{@name}'s Stats"
|
|
137
|
+
puts "Hunger: #{@hunger}"
|
|
138
|
+
puts "Courage: #{@courage}"
|
|
139
|
+
puts "Net worth: #{@net_worth}"
|
|
140
|
+
puts "Patience: #{@patience}"
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# +method_missing+ creates all these nifty little methods you need to grab
|
|
144
|
+
# instance variables (nee attributes) of your actors. It uses a rather
|
|
145
|
+
# specific format: You call the attribute you want to set with a value to
|
|
146
|
+
# set it to. With this information, +method_missing+ creates an instance
|
|
147
|
+
# variable for you, and sets it to the value you gave. After this, it
|
|
148
|
+
# creates a *getter* and *setter* *method* (the method name you used),
|
|
149
|
+
# to pull the value of the attribute out, as well as set it. An update method
|
|
150
|
+
# method is created, called +update_methodname+, and allows you to update
|
|
151
|
+
# the attribute.
|
|
152
|
+
#
|
|
153
|
+
# TODO: Example for method_missing workflow.
|
|
154
|
+
#
|
|
155
|
+
def method_missing symbol, *args
|
|
156
|
+
eval "self.instance_variable_set :@#{symbol},*args"
|
|
157
|
+
eval "def #{symbol}; @#{symbol};end"
|
|
158
|
+
eval "def #{symbol}=(update_value); @#{symbol} = update_value;end"
|
|
159
|
+
eval "def update_#{symbol} update_value; @#{symbol} += update_value;end"
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
data/lib/exception.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Gondor
|
|
2
|
+
|
|
3
|
+
# Gondor Library's Exceptions.
|
|
4
|
+
class ImplementationException < Exception
|
|
5
|
+
def initialize(*args)
|
|
6
|
+
puts "Exception:\nThe method '#{args}' has to yet to be implemented"
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
class QueueException < Exception
|
|
10
|
+
def initialize(*args)
|
|
11
|
+
puts "Exception:\nThe queue '#{args}' does not exist"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/lib/messages.rb
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) Apr 3, 2008 Phillip Gawlowski
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
# furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
|
12
|
+
# all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
# THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
require 'queue'
|
|
24
|
+
require 'exception'
|
|
25
|
+
|
|
26
|
+
module Gondor
|
|
27
|
+
module AI
|
|
28
|
+
class Messages
|
|
29
|
+
# Collects the messages pending from sender in a given queue.
|
|
30
|
+
def initialize options
|
|
31
|
+
@sender = options[:from]
|
|
32
|
+
@in_queue = options[:in_queue]
|
|
33
|
+
@queue = nil
|
|
34
|
+
Gondor::Queues.each do |q|
|
|
35
|
+
@queue = q if q.name == @in_queue
|
|
36
|
+
end
|
|
37
|
+
@messages = @queue.queue[@sender]
|
|
38
|
+
end
|
|
39
|
+
def open
|
|
40
|
+
@messages
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/queue.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
#
|
|
2
|
+
# This contains the logic for the Gondor Library Queues. All queues derive from
|
|
3
|
+
# this, and extend it, where necessary.
|
|
4
|
+
#
|
|
5
|
+
# The Queue takes its name as argument during initialization.
|
|
6
|
+
|
|
7
|
+
require 'exception'
|
|
8
|
+
|
|
9
|
+
module Gondor
|
|
10
|
+
|
|
11
|
+
# Stores all the queues initialized during the usage.
|
|
12
|
+
Queues = []
|
|
13
|
+
|
|
14
|
+
class Queue
|
|
15
|
+
attr_reader :name,:queue
|
|
16
|
+
|
|
17
|
+
# Initializes a new Queue, with the +name+ "name", and adds the name of
|
|
18
|
+
# the queue to +Queues+, a Module Constant, containing references
|
|
19
|
+
# to the queues themselves, for future access.
|
|
20
|
+
def initialize(name)
|
|
21
|
+
@name = name
|
|
22
|
+
@content = {}
|
|
23
|
+
@queue = {}
|
|
24
|
+
store self
|
|
25
|
+
end
|
|
26
|
+
# Adds *one* message from one +sender+ to *multiple* *+recipients+* to the
|
|
27
|
+
# queue, with a given priority.
|
|
28
|
+
#
|
|
29
|
+
# Currently, each receiver can have only *one* *message* from each sender!
|
|
30
|
+
#
|
|
31
|
+
def add_message(options = {})
|
|
32
|
+
@receiver = []
|
|
33
|
+
@message = []
|
|
34
|
+
@sender = options[:sender]
|
|
35
|
+
@receiver.push options[:receiver]
|
|
36
|
+
@priority = options[:priority]
|
|
37
|
+
@message.push options[:message]
|
|
38
|
+
@placeholder = [] unless @placeholder
|
|
39
|
+
@placeholder.push options[:message]
|
|
40
|
+
if @queue.empty?
|
|
41
|
+
@receiver.each do |receiver_key|
|
|
42
|
+
@queue = { receiver_key => {@sender => {@priority => @message}}}
|
|
43
|
+
end
|
|
44
|
+
else
|
|
45
|
+
@receiver.each do |queue_key|
|
|
46
|
+
@priority_hash = @queue[queue_key]
|
|
47
|
+
priorities = @priority_hash.keys
|
|
48
|
+
priorities.each do ||
|
|
49
|
+
@new_message = {@sender => {@priority => @message}}
|
|
50
|
+
@priority_hash = @priority_hash.merge @new_message
|
|
51
|
+
@new_message.clear
|
|
52
|
+
end
|
|
53
|
+
@queue[queue_key] = @queue[queue_key].merge @priority_hash
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
@priorities = {@priority => @placeholder}
|
|
57
|
+
@receiver.clear
|
|
58
|
+
@sender = nil
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def receiver
|
|
62
|
+
@queue.keys
|
|
63
|
+
end
|
|
64
|
+
def senders
|
|
65
|
+
receivers = receiver
|
|
66
|
+
@temp = []
|
|
67
|
+
receivers.each{ |r| @temp = @queue[r]}
|
|
68
|
+
result = @temp.keys
|
|
69
|
+
@temp.clear
|
|
70
|
+
return result.sort
|
|
71
|
+
end
|
|
72
|
+
def priority
|
|
73
|
+
@priorities
|
|
74
|
+
end
|
|
75
|
+
private
|
|
76
|
+
def store q
|
|
77
|
+
Gondor::Queues.push q
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) Apr 3, 2008 Phillip Gawlowski
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
# furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
|
12
|
+
# all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
# THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
module Gondor
|
|
23
|
+
|
|
24
|
+
class Relationships
|
|
25
|
+
attr_reader :name, :parents,:children
|
|
26
|
+
def initialize(name)
|
|
27
|
+
@name = name
|
|
28
|
+
@parents = []
|
|
29
|
+
@children = []
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def set_parent(name)
|
|
33
|
+
@parents.push name
|
|
34
|
+
end
|
|
35
|
+
def set_child(name)
|
|
36
|
+
@children.push name
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
data/test/test_entity.rb
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) Mar 31, 2008 Phillip Gawlowski
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
# furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
|
12
|
+
# all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
# THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
24
|
+
|
|
25
|
+
require 'test/unit'
|
|
26
|
+
require 'entity'
|
|
27
|
+
|
|
28
|
+
class TestGondorAI < Test::Unit::TestCase
|
|
29
|
+
def test_init
|
|
30
|
+
actor1 = Gondor::AI::Entity.new
|
|
31
|
+
assert(true, actor1)
|
|
32
|
+
actor2 = Gondor::AI::Entity.new(:name => "William", :patience => 100, :net_worth => 10000, :hunger => 50, :courage => -50)
|
|
33
|
+
assert_equal "William", actor2.name
|
|
34
|
+
assert_equal 100, actor2.patience
|
|
35
|
+
assert_equal 10000, actor2.net_worth
|
|
36
|
+
assert_equal 50, actor2.hunger
|
|
37
|
+
assert_equal(-50, actor2.courage)
|
|
38
|
+
end
|
|
39
|
+
def test_distance
|
|
40
|
+
actor1 = Gondor::AI::Entity.new(:x => 10, :y=>10, :z => 10)
|
|
41
|
+
actor2 = Gondor::AI::Entity.new(:x => 17, :y=>17, :z => 17)
|
|
42
|
+
assert_equal Math::sqrt(((actor1.x - actor2.x) ** 2 + (actor1.y - actor2.y) ** 2 + (actor1.z - actor2.z) ** 2)), actor1.distance_to(actor2)
|
|
43
|
+
actor1 = Gondor::AI::Entity.new(:x => 5, :y=>5, :z => 5)
|
|
44
|
+
actor2 = Gondor::AI::Entity.new(:x => 17, :y=>17, :z => 17)
|
|
45
|
+
assert_equal Math::sqrt(((actor1.x - actor2.x) ** 2 + (actor1.y - actor2.y) ** 2 + (actor1.z - actor2.z) ** 2)), actor1.distance_to(actor2)
|
|
46
|
+
end
|
|
47
|
+
def test_update_attributes
|
|
48
|
+
actor1 = Gondor::AI::Entity.new
|
|
49
|
+
assert_equal(-5,actor1.update_patience(-5))
|
|
50
|
+
assert_equal(900,actor1.update_hunger(900))
|
|
51
|
+
assert_equal(50,actor1.update_courage(50))
|
|
52
|
+
assert_equal(1,actor1.update_net_worth(1))
|
|
53
|
+
end
|
|
54
|
+
def test_spatial_movement_and_location
|
|
55
|
+
actor1 = Gondor::AI::Entity.new
|
|
56
|
+
actor1.move "x",10
|
|
57
|
+
assert_equal 10,actor1.x
|
|
58
|
+
actor1.move("y", -10)
|
|
59
|
+
assert_equal(-10,actor1.y)
|
|
60
|
+
actor1.move("z",5000)
|
|
61
|
+
assert_equal 5000,actor1.z
|
|
62
|
+
#assert_equal(ArgumentError("Axis not found"), actor1.move("d",50))
|
|
63
|
+
#TODO: code test for exception handling
|
|
64
|
+
assert_equal("x: 10 | y: -10 | z: 5000",actor1.entity_location)
|
|
65
|
+
end
|
|
66
|
+
def test_unhandled_methods
|
|
67
|
+
actor = Gondor::AI::Entity.new
|
|
68
|
+
actor.no_such_method 20
|
|
69
|
+
assert_equal 20,actor.no_such_method
|
|
70
|
+
actor.update_no_such_method(-10)
|
|
71
|
+
assert_equal 10,actor.no_such_method
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) Apr 3, 2008 Phillip Gawlowski
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
# furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
|
12
|
+
# all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
# THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
24
|
+
|
|
25
|
+
require 'test/unit'
|
|
26
|
+
require 'queue'
|
|
27
|
+
require 'messages'
|
|
28
|
+
|
|
29
|
+
class TestMessages < Test::Unit::TestCase
|
|
30
|
+
def test_init
|
|
31
|
+
# Create a queue
|
|
32
|
+
queue = Gondor::Queue.new("test_message")
|
|
33
|
+
# Populate the queue
|
|
34
|
+
queue.add_message(:sender => "Sender", :receiver => "Receiver", :priority => :one, :message => "A message")
|
|
35
|
+
# The actual test
|
|
36
|
+
messages = Gondor::AI::Messages.new(:from => "Receiver",:in_queue => "test_message")
|
|
37
|
+
assert(true, messages)
|
|
38
|
+
assert_equal({"Sender" => {:one => ["A message"]}}, messages.open)
|
|
39
|
+
end
|
|
40
|
+
end
|
data/test/test_queue.rb
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) Apr 3, 2008 Phillip Gawlowski
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
# furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
|
12
|
+
# all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
# THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
24
|
+
|
|
25
|
+
require 'test/unit'
|
|
26
|
+
require 'queue'
|
|
27
|
+
|
|
28
|
+
class TestEntityQueue < Test::Unit::TestCase
|
|
29
|
+
def test_initialize
|
|
30
|
+
queue = Gondor::Queue.new("test_initialize")
|
|
31
|
+
assert(true, queue)
|
|
32
|
+
assert_equal "test_initialize", queue.name
|
|
33
|
+
end
|
|
34
|
+
def test_queue_content
|
|
35
|
+
queue = Gondor::Queue.new("test_queue_content")
|
|
36
|
+
assert_equal({},queue.queue)
|
|
37
|
+
end
|
|
38
|
+
def test_add_queue_message
|
|
39
|
+
queue = Gondor::Queue.new("test_add_queue_message")
|
|
40
|
+
queue.add_message(:sender => "Sender", :receiver => "Receiver", :priority => :one, :message => "A message")
|
|
41
|
+
queue.add_message(:sender => "Another Sender", :receiver => "Receiver", :priority => :one, :message => "Another message")
|
|
42
|
+
assert_equal ["Receiver"],queue.receiver
|
|
43
|
+
assert_equal ["Sender","Another Sender"].sort,queue.senders
|
|
44
|
+
assert_equal({:one => ["A message","Another message"]},queue.priority)
|
|
45
|
+
end
|
|
46
|
+
def test_store_queue
|
|
47
|
+
queue = Gondor::Queue.new("test_store_queue")
|
|
48
|
+
assert_equal(true,Gondor::Queues.include?(queue))
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (c) Apr 3, 2008 Phillip Gawlowski
|
|
3
|
+
#
|
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
# furnished to do so, subject to the following conditions:
|
|
10
|
+
#
|
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
|
12
|
+
# all copies or substantial portions of the Software.
|
|
13
|
+
#
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
# THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
24
|
+
|
|
25
|
+
require 'test/unit'
|
|
26
|
+
require 'relationships'
|
|
27
|
+
|
|
28
|
+
class TestRelationships < Test::Unit::TestCase
|
|
29
|
+
def test_init
|
|
30
|
+
relation = Gondor::Relationships.new("My Relations")
|
|
31
|
+
assert(true, relation)
|
|
32
|
+
assert_equal "My Relations",relation.name
|
|
33
|
+
end
|
|
34
|
+
def test_parents
|
|
35
|
+
relation = Gondor::Relationships.new("test_parents")
|
|
36
|
+
relation.set_parent("A Parent")
|
|
37
|
+
assert_equal ["A Parent"], relation.parents
|
|
38
|
+
end
|
|
39
|
+
def test_children
|
|
40
|
+
relation = Gondor::Relationships.new("test_children")
|
|
41
|
+
relation.set_child("A Child")
|
|
42
|
+
assert_equal ["A Child"],relation.children
|
|
43
|
+
end
|
|
44
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gondorlibrary
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Phillip Gawlowski
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-04-05 00:00:00 +02:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Gondor Libraray provides a framework to work with agent based computing, from game AIs, to swarm simulations.
|
|
17
|
+
email: p.gawlowski@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README
|
|
24
|
+
- LICENSE
|
|
25
|
+
files:
|
|
26
|
+
- lib/entity.rb
|
|
27
|
+
- lib/exception.rb
|
|
28
|
+
- lib/messages.rb
|
|
29
|
+
- lib/queue.rb
|
|
30
|
+
- lib/relationships.rb
|
|
31
|
+
- coverage
|
|
32
|
+
- gondorlibrary.rb
|
|
33
|
+
- lib
|
|
34
|
+
- License
|
|
35
|
+
- MANIFEST
|
|
36
|
+
- nbproject
|
|
37
|
+
- pkg
|
|
38
|
+
- Rakefile
|
|
39
|
+
- README
|
|
40
|
+
- test
|
|
41
|
+
- test/test_entity.rb
|
|
42
|
+
- test/test_messages.rb
|
|
43
|
+
- test/test_queue.rb
|
|
44
|
+
- test/test_relationships.rb
|
|
45
|
+
- LICENSE
|
|
46
|
+
has_rdoc: true
|
|
47
|
+
homepage: http://code.google.com/p/gondorlibrary/
|
|
48
|
+
post_install_message:
|
|
49
|
+
rdoc_options:
|
|
50
|
+
- --line-numbers
|
|
51
|
+
- --inline-source
|
|
52
|
+
- --main
|
|
53
|
+
- README
|
|
54
|
+
- --title
|
|
55
|
+
- Gondor Library 0.1.0
|
|
56
|
+
require_paths:
|
|
57
|
+
- lib
|
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: "0"
|
|
63
|
+
version:
|
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: "0"
|
|
69
|
+
version:
|
|
70
|
+
requirements: []
|
|
71
|
+
|
|
72
|
+
rubyforge_project: gondorlibrary
|
|
73
|
+
rubygems_version: 1.1.0
|
|
74
|
+
signing_key:
|
|
75
|
+
specification_version: 2
|
|
76
|
+
summary: A library for agent based computing
|
|
77
|
+
test_files: []
|
|
78
|
+
|