Skip to content

Commit

Permalink
Merge pull request #37 from zond/hundred
Browse files Browse the repository at this point in the history
Hundred
  • Loading branch information
tttppp authored Apr 4, 2018
2 parents 5ec7d97 + a60811b commit fd31afd
Show file tree
Hide file tree
Showing 23 changed files with 12,607 additions and 91 deletions.
2 changes: 0 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,9 @@ type Phase interface {
Season() Season
Type() PhaseType
Next() Phase
Prev() Phase
PostProcess(State) error
DefaultOrder(Province) Adjudicator
Options(Validator, Nation) (result Options)
Winner(Validator) *Nation
}

type PathFilter func(n Province, edgeFlags, provFlags map[Flag]bool, sc *Nation, trace []Province) bool
Expand Down
1 change: 1 addition & 0 deletions variants/classical/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
Disband OrderType = "Disband"

ViaConvoy Flag = "C"
Anywhere Flag = "A"
)

var Coast = []Flag{Sea, Land}
Expand Down
50 changes: 36 additions & 14 deletions variants/classical/orders/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (

var BuildOrder = &build{}

var BuildAnywhereOrder = &build{
flags: map[dip.Flag]bool{
cla.Anywhere: true,
},
}

func Build(source dip.Province, typ dip.UnitType, at time.Time) *build {
return &build{
targets: []dip.Province{source},
Expand All @@ -18,10 +24,22 @@ func Build(source dip.Province, typ dip.UnitType, at time.Time) *build {
}
}

func BuildAnywhere(source dip.Province, typ dip.UnitType, at time.Time) *build {
return &build{
targets: []dip.Province{source},
typ: typ,
at: at,
flags: map[dip.Flag]bool{
cla.Anywhere: true,
},
}
}

type build struct {
targets []dip.Province
typ dip.UnitType
at time.Time
flags map[dip.Flag]bool
}

func (self *build) Type() dip.OrderType {
Expand Down Expand Up @@ -49,8 +67,8 @@ func (self *build) At() time.Time {
}

func (self *build) Adjudicate(r dip.Resolver) error {
me := r.Graph().SC(self.targets[0])
builds, _, _ := cla.AdjustmentStatus(r, *me)
me := r.SupplyCenters()[self.targets[0].Super()]
builds, _, _ := cla.AdjustmentStatus(r, me)
if len(builds) == 0 || self.at.After(builds[len(builds)-1].At()) {
return cla.ErrIllegalBuild
}
Expand Down Expand Up @@ -95,9 +113,11 @@ func (self *build) Options(v dip.Validator, nation dip.Nation, src dip.Province)
if nation != me {
return
}
owner := v.Graph().SC(src.Super())
if owner == nil || *owner != me {
return
if !self.flags[cla.Anywhere] {
owner := v.Graph().SC(src.Super())
if owner == nil || *owner != me {
return
}
}
if _, _, ok = v.Unit(src); ok {
return
Expand Down Expand Up @@ -137,12 +157,14 @@ func (self *build) Validate(v dip.Validator) (dip.Nation, error) {
if me, _, ok = v.SupplyCenter(self.targets[0]); !ok {
return "", cla.ErrMissingSupplyCenter
}
// is there a home sc here
owner := v.Graph().SC(self.targets[0].Super())
if owner == nil {
return "", fmt.Errorf("Should be SOME owner of %v", self.targets[0])
} else if *owner != me {
return "", cla.ErrHostileSupplyCenter
if !self.flags[cla.Anywhere] {
// is there a home sc here
owner := v.Graph().SC(self.targets[0].Super())
if owner == nil {
return "", fmt.Errorf("Should be SOME owner of %v", self.targets[0])
} else if *owner != me {
return "", cla.ErrHostileSupplyCenter
}
}
// is there a unit here
if _, _, ok := v.Unit(self.targets[0]); ok {
Expand All @@ -167,10 +189,10 @@ func (self *build) Validate(v dip.Validator) (dip.Nation, error) {
if self.typ == cla.Fleet && !v.Graph().Flags(self.targets[0])[cla.Sea] {
return "", cla.ErrIllegalUnitType
}
return *owner, nil
return me, nil
}

func (self *build) Execute(state dip.State) {
me := state.Graph().SC(self.targets[0].Super())
state.SetUnit(self.targets[0], dip.Unit{self.typ, *me})
me := state.SupplyCenters()[self.targets[0].Super()]
state.SetUnit(self.targets[0], dip.Unit{self.typ, me})
}
62 changes: 4 additions & 58 deletions variants/classical/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,7 @@ func (self *phase) Options(s dip.Validator, nation dip.Nation) (result dip.Optio
return s.Options(orders.ClassicalParser.Orders(), nation)
}

func (self *phase) Winner(s dip.Validator) *dip.Nation {
sizes := map[dip.Nation]int{}
for _, nat := range s.SupplyCenters() {
sizes[nat]++
}
var biggest *dip.Nation
var bigSize int
for nat, size := range sizes {
if biggest == nil || size > bigSize {
natCpy := nat
biggest = &natCpy
bigSize = size
}
}
if bigSize > 17 {
return biggest
}
return nil
}

func (self *phase) shortestDistance(s dip.State, src dip.Province, dst []dip.Province) (result int, err error) {
func shortestDistance(s dip.State, src dip.Province, dst []dip.Province) (result int, err error) {
var unit dip.Unit
var ok bool
unit, src, ok = s.Unit(src)
Expand Down Expand Up @@ -144,14 +124,14 @@ func (self remoteUnitSlice) Less(i, j int) bool {
return self.distances[self.provinces[i]] > self.distances[self.provinces[j]]
}

func (self *phase) sortedUnits(s dip.State, n dip.Nation) (result []dip.Province, err error) {
func SortedUnits(s dip.State, n dip.Nation) (result []dip.Province, err error) {
provs := remoteUnitSlice{
distances: make(map[dip.Province]int),
units: make(map[dip.Province]dip.Unit),
}
provs.provinces, _, _ = s.Find(func(p dip.Province, o dip.Order, u *dip.Unit) bool {
if u != nil && u.Nation == n {
if provs.distances[p], err = self.shortestDistance(s, p, s.Graph().SCs(n)); err != nil {
if provs.distances[p], err = shortestDistance(s, p, s.Graph().SCs(n)); err != nil {
return false
}
provs.units[p] = *u
Expand Down Expand Up @@ -198,7 +178,7 @@ func (self *phase) PostProcess(s dip.State) (err error) {
_, _, balance := cla.AdjustmentStatus(s, nationality)
if balance < 0 {
var su []dip.Province
if su, err = self.sortedUnits(s, nationality); err != nil {
if su, err = SortedUnits(s, nationality); err != nil {
return
}
su = su[:-balance]
Expand Down Expand Up @@ -242,40 +222,6 @@ func (self *phase) Type() dip.PhaseType {
return self.typ
}

func (self *phase) Prev() dip.Phase {
if self.typ == cla.Retreat {
return &phase{
year: self.year,
season: self.season,
typ: cla.Movement,
}
} else if self.typ == cla.Movement {
if self.season == cla.Spring {
if self.year == 1901 {
return nil
}
return &phase{
year: self.year - 1,
season: cla.Fall,
typ: cla.Adjustment,
}
} else {
return &phase{
year: self.year,
season: cla.Spring,
typ: cla.Retreat,
}
}
} else {
return &phase{
year: self.year,
season: cla.Fall,
typ: cla.Retreat,
}
}
return nil
}

func (self *phase) Next() dip.Phase {
if self.typ == cla.Movement {
return &phase{
Expand Down
38 changes: 22 additions & 16 deletions variants/generator/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,51 @@
### Data to be gathered for the variant. ###

# The name of the variant
VARIANT = 'Youngstown Redux'
VARIANT = 'Hundred'
# The starting units
#START_UNITS = {'NATO': {'Army': ['New York', 'Los Angeles', 'Paris'], 'Fleet': ['London', 'Istanbul', 'Australia']},
# # Fleet should be Leningrad South Coast
# 'USSR': {'Army': ['Moscow', 'Shanghai', 'Vladivostok'], 'Fleet': ['Leningrad', 'Albania', 'Havana']}}
START_UNITS = {'Russia': {'Army': ['Moscow', 'Omsk', 'Warsaw'], 'Fleet': ['Sevastopol', 'St. Petersburg', 'Vladivostok']},
'China': {'Army': ['Peking', 'Guangzhou', 'Wuhan'], 'Fleet': ['Shanghai']},
'Japan': {'Army': ['Kyoto'], 'Fleet': ['Tokyo', 'Osaka', 'Sapporo']},
'India': {'Army': ['Delhi', 'Calcutta'], 'Fleet': ['Bombay', 'Madras']},
'Turkey': {'Army': ['Constantinople', 'Baghdad', 'Mecca'], 'Fleet': ['Ankara']},
'France': {'Army': ['Paris', 'Marseilles'], 'Fleet': ['Brest', 'Saigon']},
'Britain': {'Fleet': ['London', 'Liverpool', 'Edinburgh', 'Aden', 'Singapore']},
'Italy': {'Army': ['Rome', 'Milan'], 'Fleet': ['Naples', 'Mogadishu']},
'Germany': {'Army': ['Berlin', 'Munich', 'Cologne'], 'Fleet': ['Tsingtao', 'Kiel']},
'Austria': {'Army': ['Vienna', 'Budapest', 'Trieste'], 'Fleet': ['Sarajevo']}}
#START_UNITS = {'Russia': {'Army': ['Moscow', 'Omsk', 'Warsaw'], 'Fleet': ['Sevastopol', 'St. Petersburg', 'Vladivostok']},
# 'China': {'Army': ['Peking', 'Guangzhou', 'Wuhan'], 'Fleet': ['Shanghai']},
# 'Japan': {'Army': ['Kyoto'], 'Fleet': ['Tokyo', 'Osaka', 'Sapporo']},
# 'India': {'Army': ['Delhi', 'Calcutta'], 'Fleet': ['Bombay', 'Madras']},
# 'Turkey': {'Army': ['Constantinople', 'Baghdad', 'Mecca'], 'Fleet': ['Ankara']},
# 'France': {'Army': ['Paris', 'Marseilles'], 'Fleet': ['Brest', 'Saigon']},
# 'Britain': {'Fleet': ['London', 'Liverpool', 'Edinburgh', 'Aden', 'Singapore']},
# 'Italy': {'Army': ['Rome', 'Milan'], 'Fleet': ['Naples', 'Mogadishu']},
# 'Germany': {'Army': ['Berlin', 'Munich', 'Cologne'], 'Fleet': ['Tsingtao', 'Kiel']},
# 'Austria': {'Army': ['Vienna', 'Budapest', 'Trieste'], 'Fleet': ['Sarajevo']}}
START_UNITS = {'Burgundy': {'Army': ['Dijon', 'Luxembourg', 'Flanders'], 'Fleet': ['Holland']},
'England': {'Army': ['Calais', 'Guyenne', 'Normandy'], 'Fleet': ['London', 'Devon']},
'France': {'Army': ['Dauphine', 'Orleanais', 'Paris', 'Toulouse', 'Provence'], 'Fleet': []}}
# The nations in the variant
NATIONS = START_UNITS.keys()
# The first year of the game
START_YEAR = 1901
START_YEAR = 1425
# Abbreviations that should be used (rather than letting the script try to guess an abbreviation).
#ABBREVIATIONS = {'Iran': 'irn', 'Iraq': 'irq', 'Japan': 'jap', 'Arabia': 'ara', 'India': 'ind', 'Sea of Japan': 'soj'}
#ABBREVIATIONS = {'North Atlantic': 'nat', 'Norwegian Sea': 'nrg', 'St Petersburg': 'stp', 'North Africa': 'naf', 'Liverpool': 'lvp', 'North Sea': 'nth', 'Norway': 'nwy', 'Livonia': 'lvn', 'Gulf of Bothnia': 'bot', 'Gulf of Lyon': 'gol', 'Tyrolia': 'tyr', 'Tyrrhenian Sea': 'tys'}
ABBREVIATIONS = {'Box A bcd': 'bxa', 'Box B ace': 'bxb', 'Box C abfgh': 'bxc', 'Box D aef': 'bxd', 'Box E bdf': 'bxe', 'Box F cdegh': 'bxf', 'Box G cfh': 'bxg', 'Box H cfg': 'bxh', 'Java Sea': 'jvs', 'Arabian Sea': 'ars', 'Persian Gulf': 'psg'}
#ABBREVIATIONS = {'Box A bcd': 'bxa', 'Box B ace': 'bxb', 'Box C abfgh': 'bxc', 'Box D aef': 'bxd', 'Box E bdf': 'bxe', 'Box F cdegh': 'bxf', 'Box G cfh': 'bxg', 'Box H cfg': 'bxh', 'Java Sea': 'jvs', 'Arabian Sea': 'ars', 'Persian Gulf': 'psg'}
ABBREVIATIONS = {'North Sea': 'nos'}
# Overrides to swap centers. This only needs to contain something if the greedy algorithm fails.
#CENTER_OVERRIDES = [('Caribbean Sea', 'Havana'), ('West Atlantic', 'Brazil'), ('Black Sea', 'Istanbul'), ('Indian Ocean', 'Arabian Sea'), ('Caribbean Sea', 'Colombia'), ('Caribbean Sea', 'Venezuala'), ('Finland', 'Leningrad')]
#CENTER_OVERRIDES = [('Sweden', 'Gulf of Bothnia'), ('Mid Atlantic', 'Portugal')]
CENTER_OVERRIDES = [('Kamchatka', 'North Pacific Ocean'), ('Awdal', 'Gulf of Aden'), ('Hebei', 'Tsingtao'), ('Red Sea', 'Mecca'), ('Galicia', 'Vienna'), ('Awdal', 'Mogadishu'), ('Liverpool', 'Irish Sea')]
#CENTER_OVERRIDES = [('Kamchatka', 'North Pacific Ocean'), ('Awdal', 'Gulf of Aden'), ('Hebei', 'Tsingtao'), ('Red Sea', 'Mecca'), ('Galicia', 'Vienna'), ('Awdal', 'Mogadishu'), ('Liverpool', 'Irish Sea')]
CENTER_OVERRIDES = [('Lorraine', 'Dijon')]
# Overrides to swap region names. This only needs to contain something if the greedy algorithm fails.
#REGION_OVERRIDES = [('West Atlantic', 'Brazil'), ('South China Sea', 'Saigon'), ('Black Sea', 'Istanbul')]
#REGION_OVERRIDES = [('Finland', 'Gulf of Bothnia'), ('Mid Atlantic', 'Portugal')]
REGION_OVERRIDES = [('Red Sea', 'Mecca')]#, ('Galicia', 'Vienna'), ('Awdal', 'Mogadishu')]
#REGION_OVERRIDES = [('Red Sea', 'Mecca')]#, ('Galicia', 'Vienna'), ('Awdal', 'Mogadishu')]
REGION_OVERRIDES = [('Lorraine', 'Dijon')]
# Whether to highlight the region abbreviation in bold or not.
BOLD_ABBREVIATIONS = True

### Constants ###

INK = '{http://www.inkscape.org/namespaces/inkscape}'
SVG = '{http://www.w3.org/2000/svg}'
MAP = 'youngstownredux_input.svg'
MAP = 'hundred_input.svg'
# Any junctions within GUTTER pixels from the edge of the page will be moved to the edge.
GUTTER = 5
# How curvy the edges should be made
Expand Down
Loading

0 comments on commit fd31afd

Please sign in to comment.