berlin-ai 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/berlin-ai.gemspec CHANGED
@@ -5,15 +5,18 @@ $:.unshift lib unless $:.include?(lib)
5
5
  require 'lib/version'
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "berlin-ai"
9
- s.version = Berlin::AI::VERSION
10
- s.platform = Gem::Platform::RUBY
11
- s.authors = ["Christian Blais", "Guillaume Malette", "Jodi Giordano"]
12
- s.email = ["christ.blais@gmail.com", "gmalette@gmail.com", "giordano.jodi@gmail.com"]
13
- s.homepage = "http://github.com/christianblais/berlin-ai"
14
- s.summary = "Berlin Artificial Intelligence"
15
- s.description = "Berlin Artificial Intelligence"
16
-
8
+ s.name = "berlin-ai"
9
+ s.version = Berlin::AI::VERSION
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = ["Christian Blais", "Guillaume Malette", "Jodi Giordano"]
12
+ s.email = ["christ.blais@gmail.com", "gmalette@gmail.com", "giordano.jodi@gmail.com"]
13
+ s.homepage = "http://github.com/christianblais/berlin-ai"
14
+ s.summary = "Berlin Artificial Intelligence"
15
+ s.description = "Berlin Artificial Intelligence"
16
+
17
+ s.requirements << 'sinatra'
18
+ s.requirements << 'yajl-ruby'
19
+
17
20
  s.files = [
18
21
  'LICENSE',
19
22
  'README',
data/lib/ai/map.rb CHANGED
@@ -35,14 +35,14 @@ module Berlin
35
35
  def owned_nodes
36
36
  @nodes.select do |id, node|
37
37
  node.player_id == player_id
38
- end
38
+ end.values
39
39
  end
40
40
 
41
41
  # We can now loop on our owned nodes in order to find our controlled nodes.
42
42
  def controlled_nodes
43
43
  owned_nodes.select do |id, node|
44
44
  node.occupied?
45
- end
45
+ end.values
46
46
  end
47
47
 
48
48
  # Is the map directed?
data/lib/berlin-ai.rb CHANGED
@@ -4,11 +4,10 @@ end
4
4
 
5
5
  post '/' do
6
6
  begin
7
- if ['turn', 'game_start', 'game_over'].include? params[:action]
7
+ if ['ping', 'turn', 'game_start', 'game_over'].include? params[:action]
8
8
  game = Berlin::AI::Game.create_or_update params[:action], params[:infos], params[:map], params[:state]
9
9
 
10
- if params[:action] == 'turn'
11
- # Respond with a json of our moves
10
+ if ['ping', 'turn'].include? params[:action]
12
11
  return game.turn_moves.to_json
13
12
  end
14
13
  else
@@ -18,6 +17,9 @@ post '/' do
18
17
  # For every other type of request, respond with 200 OK
19
18
  200
20
19
  rescue Exception => e
20
+ p e.inspect
21
+
22
+ # Internal server error
21
23
  500
22
24
  end
23
25
  end
data/lib/version.rb CHANGED
@@ -2,7 +2,7 @@ module Berlin
2
2
  module AI
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- BUILD = 1
5
+ BUILD = 2
6
6
 
7
7
  VERSION = "#{MAJOR}.#{MINOR}.#{BUILD}"
8
8
  end
data/test/test_ai.rb CHANGED
@@ -1,16 +1,18 @@
1
1
  require 'rubygems'
2
2
  require 'sinatra'
3
3
  require 'yajl/json_gem'
4
-
5
- %w(berlin-ai).each do |file|
6
- require File.expand_path( File.dirname( __FILE__ ) ) + "/../lib/#{file}"
7
- end
4
+ require 'berlin-ai'
8
5
 
9
6
  module Berlin
10
7
  module AI
11
8
  class Game
12
9
  def turn_moves
13
- p "salut"
10
+ @map.controlled_nodes do |node|
11
+ {
12
+ :from => node.id,
13
+ :to => node.adjacent_nodes.sample.id,
14
+ :number_of_soldiers => rand(node.number_of_soldiers + 1)
15
+ }
14
16
  end
15
17
  end
16
18
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berlin-ai
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
4
+ hash: 27
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Blais
@@ -70,10 +70,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  segments:
71
71
  - 0
72
72
  version: "0"
73
- requirements: []
74
-
73
+ requirements:
74
+ - sinatra
75
+ - yajl-ruby
75
76
  rubyforge_project:
76
- rubygems_version: 1.3.7
77
+ rubygems_version: 1.6.2
77
78
  signing_key:
78
79
  specification_version: 3
79
80
  summary: Berlin Artificial Intelligence