예제 #1
0
class _PlayerBaseTestCase(unittest.TestCase):
    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()

    def find_player_unit(self, p, cls_name, index=0):
        for u in p.units:
            if u.type_name == cls_name:
                if index:
                    index -= 1
                else:
                    return u
예제 #2
0
class WorldTestCase(unittest.TestCase):
    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"))

    def tearDown(self):
        pass

    def testShortestPath(self):
        g = self.w.grid
        self.assertEqual(g["a1"].shortest_path_distance_to(g["a2"]), g["a1"].shortest_path_distance_to(g["b1"]))
        self.assertIn(g["a1"].shortest_path_to(g["e5"]).other_side.place.name, ("a2", "b1"))
        self.assertEqual(g["b1"].shortest_path_to(g["e5"]).other_side.place.name, "b2")
        self.assertEqual(g["b1"].shortest_path_to(g["d2"]).other_side.place.name, "c1")
        g2 = self.w2.grid
        self.assertEqual(g2["a1"].shortest_path_to(g2["c1"]), None)
        self.assertEqual(g2["c1"].shortest_path_to(g2["a1"]), None)

    def testCheckString(self):
        World([]).get_digest()
        self.assertEqual(self.w.get_digest(), self.w.get_digest())
        self.assertNotEqual(self.w.get_digest(), self.w2.get_digest())
        self.w.get_objects_string()
예제 #3
0
class WorldTestCase(unittest.TestCase):
    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"))

    def tearDown(self):
        pass

    def testShortestPath(self):
        g = self.w.grid
        self.assertEqual(
            g["a1"].shortest_path_distance_to(g["a2"]),
            g["a1"].shortest_path_distance_to(g["b1"]),
        )
        self.assertIn(
            g["a1"].shortest_path_to(g["e5"]).other_side.place.name, ("a2", "b1")
        )
        self.assertEqual(g["b1"].shortest_path_to(g["e5"]).other_side.place.name, "b2")
        self.assertEqual(g["b1"].shortest_path_to(g["d2"]).other_side.place.name, "c1")
        g2 = self.w2.grid
        self.assertEqual(g2["a1"].shortest_path_to(g2["c1"]), None)
        self.assertEqual(g2["c1"].shortest_path_to(g2["a1"]), None)

    def testCheckString(self):
        World([]).get_digest()
        self.assertEqual(self.w.get_digest(), self.w.get_digest())
        self.assertNotEqual(self.w.get_digest(), self.w2.get_digest())
        self.w.get_objects_string()
예제 #4
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
예제 #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 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
예제 #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
class _PlayerBaseTestCase(unittest.TestCase):
    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

    def find_player_unit(self, p, cls_name, index=0):
        for u in p.units:
            if u.type_name == cls_name:
                if index:
                    index -= 1
                else:
                    return u
예제 #9
0
class _PlayerBaseTestCase(unittest.TestCase):

    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

    def find_player_unit(self, p, cls_name, index=0):
        for u in p.units:
            if u.type_name == cls_name:
                if index:
                    index -= 1
                else:
                    return u
예제 #10
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[0][1].append(("b1", w.unit_class("new_flyingmachine")))
     w.players_starts[0][1].append(("b1", w.unit_class("flyingmachine")))
     w.players_starts[0][1].append(("b1", w.unit_class("dragon")))
     w.players_starts[0][1].append(("b1", w.unit_class("castle")))
     w.players_starts[1][1].append(("b4", w.unit_class("new_flyingmachine")))
     w.players_starts[1][1].append(("b4", w.unit_class("flyingmachine")))
     w.players_starts[1][1].append(("b4", w.unit_class("dragon")))
     w.players_starts[1][1].append(("b4", w.unit_class("castle")))
     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
예제 #11
0
class _PlayerBaseTestCase(unittest.TestCase):

    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()

    def find_player_unit(self, p, cls_name, index=0):
        for u in p.units:
            if u.type_name == cls_name:
                if index:
                    index -= 1
                else:
                    return u
예제 #12
0
def world():
    w = World([])
    w.load_and_build_map(Map("soundrts/tests/jl1_cyclic.txt"))
    return w
예제 #13
0
def world():
    w = World([])
    w.load_and_build_map(Map("soundrts/tests/height.txt"))
    return w
예제 #14
0
def world():
    w = World([])
    w.load_and_build_map(Map("soundrts/tests/jl1_cyclic.txt"))
    return w