berlin-ai 0.0.22 → 0.0.23

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.
Files changed (3) hide show
  1. data/lib/ai/fake.rb +55 -0
  2. data/lib/version.rb +1 -1
  3. metadata +2 -2
@@ -1,3 +1,5 @@
1
+ require 'rainbow'
2
+
1
3
  module Berlin
2
4
  module Fake
3
5
 
@@ -100,6 +102,57 @@ module Berlin
100
102
  end
101
103
  end
102
104
 
105
+ class Display
106
+
107
+ attr_accessor *(1..8).map{ |n| "n#{n}"}
108
+
109
+ COLORS = [:red, :green, :yellow, :blue]
110
+
111
+ Node = Struct.new(:id, :ns)
112
+
113
+ def initialize(state)
114
+ js = state.as_json
115
+ @player_ids = js.map{ |n| n['player_id'] }.uniq
116
+
117
+ js.each do |node|
118
+ id = node['node_id'].to_s.rjust(2)
119
+ ns = node['number_of_soldiers'].to_s.rjust(2).foreground(color(node['player_id']))
120
+
121
+ display_node = Display::Node.new(id, ns)
122
+ self.send("n#{node['node_id']}=", display_node)
123
+ end
124
+ end
125
+
126
+ def color(player_id)
127
+ player_id.nil? ? :white : COLORS[@player_ids.index(player_id)]
128
+ end
129
+
130
+ def as_display
131
+ ## The map is fully dynamic
132
+ <<-MAP
133
+ ____ ____ ____
134
+ / \\ / \\ / \\
135
+ | #{n1.id} |---------| #{n2.id} |---------| #{n3.id} |
136
+ | #{n1.ns} | | #{n2.ns} | | #{n3.ns} |
137
+ \\____/ \\____/ \\____/
138
+ | \\ |
139
+ | \\ |
140
+ _+__ \\ _+__
141
+ / \\ \\ / \\
142
+ | #{n4.id} |-----\\ \\------| #{n5.id} |
143
+ | #{n4.ns} | \\ | #{n5.ns} |
144
+ \\____/ \\ \\____/
145
+ | \\ |
146
+ | \\ |
147
+ _+__ \\___ _+__
148
+ / \\ / \\ / \\
149
+ | #{n6.id} |---------| #{n7.id} |---------| #{n8.id} |
150
+ | #{n6.ns} | | #{n7.ns} | | #{n8.ns} |
151
+ \\____/ \\____/ \\____/
152
+ MAP
153
+ end
154
+ end
155
+
103
156
  class State
104
157
  def initialize(from_json)
105
158
  @state = from_json.inject({}) do |h, node|
@@ -194,6 +247,8 @@ class Berlin::Fake::Game
194
247
  turn
195
248
  puts "Press any key"
196
249
  gets
250
+ puts Berlin::Fake::Display.new(@state).as_display
251
+ gets
197
252
  end
198
253
  end
199
254
 
@@ -2,7 +2,7 @@ module Berlin
2
2
  module AI
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- BUILD = 22
5
+ BUILD = 23
6
6
 
7
7
  VERSION = "#{MAJOR}.#{MINOR}.#{BUILD}"
8
8
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: berlin-ai
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.22
5
+ version: 0.0.23
6
6
  platform: ruby
7
7
  authors:
8
8
  - Christian Blais
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-07-22 00:00:00.000000000 Z
14
+ date: 2013-07-25 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  version_requirements: !ruby/object:Gem::Requirement