Skip to content

Commit

Permalink
Added coast parsing, corrected starting state.
Browse files Browse the repository at this point in the history
v0.4.1
  • Loading branch information
NamelessOne committed Jul 12, 2013
1 parent ca30f95 commit 7e312ae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/maps/standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ Standard:
- Edi
Powers:
Russia:
- FStP,AMos,FSev,AWar
- FStP(sc),AMos,FSev,AWar
- Ukr
- Lvn
- Fin
Expand Down
11 changes: 8 additions & 3 deletions lib/parser/state_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def parse_power_state(blob, power)
end

def parse_unit(blob, power)
m = /([AF])(\w{3})/.match(blob)
return m[2], AreaState.new(nil, Unit.new( power, unit_type(m[1])))
m = /(?'unit_type'[AF])(?'unit_area'\w{3})(?'unit_area_coast'\(.+?\))?/.match(blob)
return "#{m['unit_area']}#{m['unit_area_coast']}", AreaState.new(nil, Unit.new( power, unit_type(m['unit_type'])))
end

def parse_area_state(blob, power)
Expand Down Expand Up @@ -73,7 +73,7 @@ def dump_state
unless powers.has_key? area_state.owner
powers[area_state.owner] = { units: {}, areas: [] }
end
powers[area_state.owner][:areas] << area
powers[area_state.owner][:areas] << strip_coast(area)
end
end
powers.each do |power, state|
Expand Down Expand Up @@ -103,5 +103,10 @@ def dump_power(power, state)
def dump_unit(area, unit)
"#{unit.type_to_s}#{area}"
end

def strip_coast(area)
m = /^(?'abbrv'[^(]+)(\((?'coast'.+)\))?$/.match area
m['abbrv']
end
end
end
4 changes: 2 additions & 2 deletions ruby-adjudicator.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = "ruby-adjudicator"
s.version = "0.4.0"
s.date = "2013-07-07"
s.version = "0.4.1"
s.date = "2013-07-12"
s.summary = "Diplomacy adjudicator"
s.description = "A Diplomacy adjudicator written in ruby."
s.authors = ["NamelessOne"]
Expand Down
12 changes: 11 additions & 1 deletion spec/lib/state_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,17 @@ module Diplomacy
end

describe "dumping" do
# TODO add some tests!
it "dumps correctly the French starting position" do
gamestate = GameState.new
gamestate[:Par] = AreaState.new("France", Unit.new("France", Unit::ARMY))
gamestate[:Bre] = AreaState.new("France", Unit.new("France", Unit::FLEET))
gamestate[:Mar] = AreaState.new("France", Unit.new("France", Unit::ARMY))
gamestate[:Pic] = AreaState.new("France")
gamestate[:Bur] = AreaState.new("France")
gamestate[:Gas] = AreaState.new("France")
sp = StateParser.new gamestate
sp.dump_state.should eq("France:APar,FBre,AMar|Par,Bre,Mar,Pic,Bur,Gas")
end
end
end
end

0 comments on commit 7e312ae

Please sign in to comment.