Example #1
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()
Example #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()
Example #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
Example #4
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()
Example #5
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
Example #6
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
Example #7
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
Example #8
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
Example #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
Example #10
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
Example #11
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()
Example #12
0
def test_is_ok_for_warehouse():
    w = World([])
    c = Computer(w, DummyClient())
    a1 = Square(w, 0, 0, 12)
    assert a1.name == "a1"
    assert not c.is_ok_for_warehouse(a1, 0)
    a1.objects.append(Deposit(0))
    assert c.is_ok_for_warehouse(a1, 0)
    a1.objects.append(Warehouse([1]))
    assert c.is_ok_for_warehouse(a1, 0)
    a1.objects.append(Warehouse([0]))
    assert not c.is_ok_for_warehouse(a1, 0)
Example #13
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
Example #14
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
Example #15
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()
Example #16
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
Example #17
0
def world():
    w = World([])
    w.load_and_build_map(Map("soundrts/tests/jl1_cyclic.txt"))
    return w
Example #18
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
Example #19
0
def world():
    w = World([])
    w.load_and_build_map(Map("soundrts/tests/height.txt"))
    return w
Example #20
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"))
Example #21
0
 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()
Example #22
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"))
Example #23
0
def world():
    w = World([])
    w.load_and_build_map(Map("soundrts/tests/jl1_cyclic.txt"))
    return w