Exemplo n.º 1
0
func verifyPosition(t *testing.T, s *state.State, match []string, scCollector map[dip.Province]dip.Nation, unitCollector, dislodgedCollector map[dip.Province]dip.Unit, fails *int) {
	if match[2] == "supply" {
		if nation, _, ok := s.SupplyCenter(dip.Province(match[3])); ok && nation == dip.Nation(match[1]) {
			scCollector[dip.Province(match[3])] = nation
		} else {
			t.Errorf("%v: Expected %v to own SC in %v, but found %v, %v", s.Phase(), match[1], match[3], nation, ok)
			*fails += 1
		}
	} else if match[2] == "army" {
		if unit, _, ok := s.Unit(dip.Province(match[3])); ok && unit.Nation == dip.Nation(match[1]) && unit.Type == cla.Army {
			unitCollector[dip.Province(match[3])] = unit
		} else {
			t.Errorf("%v: Expected to find %v %v in %v, but found %v, %v", s.Phase(), match[1], cla.Army, match[3], unit, ok)
			*fails += 1
		}
	} else if match[2] == "fleet" {
		if unit, _, ok := s.Unit(dip.Province(match[3])); ok && unit.Nation == dip.Nation(match[1]) && unit.Type == cla.Fleet {
			unitCollector[dip.Province(match[3])] = unit
		} else {
			t.Errorf("%v: Expected to find %v %v in %v, but found %v, %v", s.Phase(), match[1], cla.Fleet, match[3], unit, ok)
			*fails += 1
		}
	} else if match[2] == "fleet/dislodged" {
		if unit, _, ok := s.Dislodged(dip.Province(match[3])); ok && unit.Nation == dip.Nation(match[1]) && unit.Type == cla.Fleet {
			dislodgedCollector[dip.Province(match[3])] = unit
		} else {
			t.Errorf("%v: Expected to find %v %v dislodged in %v, but found %v, %v", s.Phase(), match[1], cla.Army, match[3], unit, ok)
			*fails += 1
		}
	} else if match[2] == "army/dislodged" {
		if unit, _, ok := s.Dislodged(dip.Province(match[3])); ok && unit.Nation == dip.Nation(match[1]) && unit.Type == cla.Army {
			dislodgedCollector[dip.Province(match[3])] = unit
		} else {
			t.Errorf("%v: Expected to find %v %v dislodged in %v, but found %v, %v", s.Phase(), match[1], cla.Army, match[3], unit, ok)
			*fails += 1
		}
	} else {
		t.Fatalf("Unknown position description %v", match)
	}
}
Exemplo n.º 2
0
func AdminGetOptions(c *common.HTTPContext) (err error) {
	gameId, err := base64.URLEncoding.DecodeString(c.Vars()["game_id"])
	if err != nil {
		return
	}
	game := &Game{Id: gameId}
	if err = c.DB().Get(game); err != nil {
		return
	}
	_, last, err := game.Phase(c.DB(), 0)
	if err != nil {
		return
	}
	opts, err := last.Options(dip.Nation(c.Vars()["nation"]))
	if err != nil {
		return
	}
	return c.RenderJSON(opts)
}