예제 #1
0
def test_isolated_map(test):
    res = test
    from soundrts.mapfile import Map
    from soundrts.definitions import rules, get_ai, style
    map1 = Map("soundrts/tests/single/map1")
    map1.load_resources()
    map1.load_rules_and_ai(res)
    map1.load_style(res)
    assert rules.get("test", "cost") == [0, 0]
    assert rules.get("peasant", "cost") == [6000, 0]
    assert get_ai("easy") == ['get 6 peasant', 'goto -1']
    assert style.get("peasant", "noise") == ["6"]
    assert sounds.get_text("0") == "map1"
    map1.unload_resources()
예제 #2
0
def test_short_status():
    g = Game(2)
    g.scenario = Map("soundrts/tests/jl1.txt")
    g._start_time = time.time() - 60  # 1 minute ago
    assert g.short_status == ("jl1", "0,1", 1)
    g._start_time = time.time() - .1  # a fraction of a second
    assert g.short_status[2] == 0  # not a float
예제 #3
0
 def set_up(self, alliance=(1, 2), cloak=False, map_name="jl1_extended"):
     self.w = World([])
     self.w.introduction = []
     self.w.load_and_build_map(Map("soundrts/tests/%s.txt" % map_name))
     if cloak:
         self.w.unit_class("new_flyingmachine").dct["is_a_cloaker"] = True
     self.w.populate_map([DummyClient(), DummyClient()], alliance)
     self.cp, self.cp2 = self.w.players
예제 #4
0
def test_isolated_map(test):
    res = test
    from soundrts.mapfile import Map
    from soundrts.definitions import rules, get_ai, style
    map1 = Map("soundrts/tests/single/map1")
    map1.load_resources()
    map1.load_rules_and_ai(res)
    map1.load_style(res)
    assert rules.get("test", "cost") == [0, 0]
    assert rules.get("peasant", "cost") == [6000, 0]
    assert get_ai("easy") == ['get 6 peasant', 'goto -1']
    assert style.get("peasant", "noise") == ["6"]
    assert sounds.get_text("0") == "map1"
    map1.unload_resources()
예제 #5
0
 def set_up(self, alliance=(1, 2), cloak=False):
     w = World([])
     w.introduction = []
     w.load_and_build_map(Map("soundrts/tests/jl1.txt"))
     w.players_starts[1][1].append(("b4", w.unit_class("lumbermill")))
     cl = DummyClient()
     cl2 = DummyClient()
     w.populate_map([cl, cl2], alliance)
     cp, self.cp2 = w.players
     return w, cl, cp
예제 #6
0
 def testSyncError(self):
     c = Coordinator(None, None, None)
     c.world = World([])
     c.world.load_and_build_map(Map("multi/m2.txt"))
     c.world.update()
     c.get_sync_debug_msg_1()
     c.get_sync_debug_msg_2()
     c.world.update()
     c.get_sync_debug_msg_1()
     c.get_sync_debug_msg_2()
예제 #7
0
 def set_up(self, alliance=(1, 2), cloak=False, map_name="jl1_extended"):
     w = World([])
     w.introduction = []
     w.load_and_build_map(Map("soundrts/tests/%s.txt" % map_name))
     if cloak:
         w.unit_class("new_flyingmachine").dct["is_a_cloaker"] = True
     cl = DummyClient()
     cl2 = DummyClient()
     w.populate_map([cl, cl2], alliance)
     cp, self.cp2 = w.players
     return w, cl, cp
예제 #8
0
def test_unpacked_folder_map_redefines_text(test):
    from soundrts.mapfile import Map

    default_text = sounds.get_text("0")
    m = Map(unpack=Map("soundrts/tests/single/map1").pack())
    m.load_resources()
    assert sounds.get_text("0") == "map1"
    assert sounds.get_text("0") != default_text
    m.unload_resources()
    assert sounds.get_text("0") == default_text
예제 #9
0
def test_unpacked_folder_map_redefines_sound(test):
    from soundrts.mapfile import Map

    default_sound = sounds.get_sound("9998")
    m = Map(unpack=Map("soundrts/tests/single/map1").pack())
    m.load_resources()
    assert isinstance(sounds.get_sound("9998"), pygame.mixer.Sound)
    assert sounds.get_sound("9998") is not default_sound
    m.unload_resources()
    assert sounds.get_sound("9998") is default_sound
예제 #10
0
def test_unpacked_folder_map_redefines_rules_ai_and_style(test):
    res = test
    from soundrts.definitions import get_ai, rules, style
    from soundrts.mapfile import Map

    m = Map(unpack=Map("soundrts/tests/single/map1").pack())
    m.load_rules_and_ai(res)
    m.load_style(res)
    assert rules.get("test", "cost") == [0, 0]
    assert rules.get("peasant", "cost") == [6000, 0]
    assert get_ai("easy") == ["get 6 peasant", "goto -1"]
    assert style.get("peasant", "noise") == ["6"]
예제 #11
0
 def set_up(self,
            alliance=(1, 2),
            cloak=False,
            map_name="jl1_extended",
            ai=("easy", "easy")):
     self.w = World([])
     self.w.load_and_build_map(Map("soundrts/tests/%s.txt" % map_name))
     if cloak:
         self.w.unit_class("new_flyingmachine").dct["is_a_cloaker"] = True
     cp = DummyClient(ai[0])
     cp2 = DummyClient(ai[1])
     cp.alliance, cp2.alliance = alliance
     self.w.populate_map([cp, cp2], random_starts=False)
     self.cp, self.cp2 = self.w.players
     self.cp.is_perceiving = is_perceiving_method(self.cp)
     self.cp2.is_perceiving = is_perceiving_method(self.cp2)
     self.w._update_buckets()
예제 #12
0
def test_nb_players_after_unpack():
    for n in ["jl1.txt", "jl4"]:
        m = Map(unpack=Map(f"multi/{n}").pack())
        assert m.nb_players_min == 2
예제 #13
0
 def setUp(self):
     self.w = World([])
     self.w.load_and_build_map(Map("multi/m2.txt"))
     self.w2 = World([])
     self.w2.load_and_build_map(Map("multi/jl2.txt"))
예제 #14
0
def add_digest(m):
    p = os.path.join(DIR, m)
    return "{} {}".format(m, Map(p).get_digest())
예제 #15
0
def world():
    w = World([])
    w.load_and_build_map(Map("soundrts/tests/jl1_cyclic.txt"))
    return w
예제 #16
0
def add_digest(m):
    p = os.path.join(DIR, m)
    return "%s %s" % (m, Map(p).get_digest())
예제 #17
0
def size(m):
    return Map(os.path.join(DIR, m)).size()
예제 #18
0
def world():
    w = World([])
    w.load_and_build_map(Map("soundrts/tests/height.txt"))
    return w