def test_build_strong_hold(self) -> None: # Let's build a dwelling and trading post. a1 = board.ParsePosition("A1") assert a1 is not None self.default_board.build(a1, common.Structure.DWELLING) self.default_board.build(a1, common.Structure.TRADING_POST) self.default_board.build(a1, common.Structure.STRONGHOLD) self.assertEqual(self.default_board.get_structure(a1), common.Structure.STRONGHOLD) # We can build nothing! self.assertFalse( self.default_board.can_be_built(a1, common.Structure.DWELLING, [common.Terrain.PLAIN])) self.assertFalse( self.default_board.can_be_built(a1, common.Structure.TRADING_POST, [common.Terrain.PLAIN])) self.assertFalse( self.default_board.can_be_built(a1, common.Structure.TEMPLE, [common.Terrain.PLAIN])) self.assertFalse( self.default_board.can_be_built(a1, common.Structure.SANCTUARY, [common.Terrain.PLAIN])) self.assertFalse( self.default_board.can_be_built(a1, common.Structure.STRONGHOLD, [common.Terrain.PLAIN]))
def testcan_be_built_basic(self) -> None: # Swamps can be built on A13. a13 = board.ParsePosition("A13") assert a13 is not None self.assertTrue( self.default_board.can_be_built(a13, common.Structure.DWELLING, [common.Terrain.SWAMP])) # We can build as long as one of the terrains can be built.DWELLING self.assertTrue( self.default_board.can_be_built( a13, common.Structure.DWELLING, [common.Terrain.MOUNTAIN, common.Terrain.SWAMP])) # But we can't build anything other than a dwelling.DWELLING self.assertFalse( self.default_board.can_be_built(a13, common.Structure.TRADING_POST, [common.Terrain.SWAMP])) self.assertFalse( self.default_board.can_be_built(a13, common.Structure.TEMPLE, [common.Terrain.SWAMP])) self.assertFalse( self.default_board.can_be_built(a13, common.Structure.SANCTUARY, [common.Terrain.SWAMP])) self.assertFalse( self.default_board.can_be_built(a13, common.Structure.STRONGHOLD, [common.Terrain.SWAMP])) # We also can't build anything that's not our terrain. self.assertFalse( self.default_board.can_be_built(a13, common.Structure.DWELLING, [common.Terrain.MOUNTAIN]))
def request_location(self, pl: player.Player) -> board.Position: self._vertical_space() while True: reqStr = self._request_string("%s - Select a tile for the action: " % self._name_prefix(pl)) pos: Optional[board.Position] = board.ParsePosition(reqStr) if pos: return pos print("Invalid position %s requested. Please try again." % reqStr)
def test_cannot_build_on_water(self) -> None: b2 = board.ParsePosition("B2") assert b2 is not None self.assertFalse( self.default_board.can_be_built(b2, common.Structure.DWELLING, [ common.Terrain.MOUNTAIN, common.Terrain.SWAMP, common.Terrain.PLAIN, common.Terrain.LAKE, common.Terrain.DESERT, common.Terrain.FOREST ]))
def test_default_game_board_neighbors_structure_owners(self) -> None: # No structures anywhere! a13 = board.ParsePosition("A13") assert a13 is not None self.assertTrue( len(self.default_board.neighbor_structure_owners(a13)) == 0) # We build some structures. a12 = board.ParsePosition("A12") assert a12 is not None b12 = board.ParsePosition("B12") assert b12 is not None self.default_board.build(a12, common.Structure.DWELLING) self.default_board.build(b12, common.Structure.DWELLING) self.assertCountEqual( self.default_board.neighbor_structure_owners(a13), [ (common.Structure.DWELLING, common.Terrain.WASTELAND), (common.Structure.DWELLING, common.Terrain.DESERT), ])
def test_build_failures(self) -> None: a1 = board.ParsePosition("A1") assert a1 is not None with self.assertRaises(utils.InternalError): self.default_board.build(a1, common.Structure.TRADING_POST) self.default_board.build(a1, common.Structure.DWELLING) with self.assertRaises(utils.InternalError): self.default_board.build(a1, common.Structure.TEMPLE) self.default_board.build(a1, common.Structure.TRADING_POST) self.default_board.build(a1, common.Structure.TEMPLE) with self.assertRaises(utils.InternalError): self.default_board.build(a1, common.Structure.STRONGHOLD)
def test_default_game_board_neighbors(self) -> None: # We include the pseudo-tile 'b13' a13 = board.ParsePosition("A13") assert a13 is not None a12 = board.ParsePosition("A12") assert a12 is not None b12 = board.ParsePosition("B12") assert b12 is not None b13 = board.ParsePosition("B13") assert b13 is not None self.assertCountEqual(self.default_board.get_neighbor_tiles(a13), [ a12, b12, b13, ]) e1 = board.ParsePosition("E1") assert e1 is not None f1 = board.ParsePosition("F1") assert f1 is not None e2 = board.ParsePosition("E2") assert e2 is not None d1 = board.ParsePosition("D1") assert d1 is not None self.assertCountEqual(self.default_board.get_neighbor_tiles(e1), [f1, e2, d1]) e6 = board.ParsePosition("E6") assert e6 is not None e5 = board.ParsePosition("E5") assert e5 is not None d5 = board.ParsePosition("D5") assert d5 is not None d6 = board.ParsePosition("D6") assert d6 is not None e7 = board.ParsePosition("E7") assert e7 is not None f6 = board.ParsePosition("F6") assert f6 is not None f5 = board.ParsePosition("F5") assert f5 is not None self.assertCountEqual(self.default_board.get_neighbor_tiles(e6), [e5, d5, d6, e7, f6, f5])
def test_parse_position_failure(self) -> None: self.assertIsNone(board.ParsePosition("J1")) self.assertIsNone(board.ParsePosition("A14"))
def test_parse_position(self) -> None: self.assertEqual(board.ParsePosition("A13"), board.Position(row="A", column=13)) self.assertEqual(board.ParsePosition("I1"), board.Position(row="I", column=1))