def test_add_settlement(self):
     g = Game()
     # Try to add a settlement without the cards
     g.add_settlement(0, 0, 0)
     # Add cards to build a settlement
     g.players[0].add_cards([
         ResCard.WOOD,
         ResCard.BRICK,
         ResCard.SHEEP,
         ResCard.WHEAT
     ])
     # Try adding an isolated settlement
     res = g.add_settlement(0, 0, 0)
     assert res == Statuses.ERR_ISOLATED
     assert g.board.points[0][0].building == None
     # Try adding a settlement at a point that is not on the board
     res = g.add_settlement(0, 500, 0)
     assert res == Statuses.ERR_BAD_POINT
     # Add starting settlement and two roads to ensure there is an available position
     assert g.add_settlement(0, 0, 2, True) == Statuses.ALL_GOOD
     assert g.add_road(0, [0, 2], [0, 1], True) == Statuses.ALL_GOOD
     assert g.add_road(0, [0, 0], [0, 1], True) == Statuses.ALL_GOOD
     res = g.add_settlement(0, 0, 0)
     assert res == Statuses.ALL_GOOD
     assert g.board.points[0][0].building != None
     assert g.board.points[0][0].building.type == Building.BUILDING_SETTLEMENT
Exemple #2
0
 def test_adding_starting_roads(self):
     # Create game
     g = Game()
     # Add starting settlement
     g.add_settlement(0, g.board.points[0][0], True)
     # Try adding a road
     res = g.add_road(0, g.board.points[0][0], g.board.points[0][1], True)
     assert res == Statuses.ALL_GOOD
     res = g.add_road(0, g.board.points[1][1], g.board.points[0][0], True)
     assert res == Statuses.ALL_GOOD
     # Try adding a disconnected road
     res = g.add_road(0, g.board.points[2][0], g.board.points[2][1], True)
     assert res == Statuses.ERR_ISOLATED
     # Try adding a road whose point's are not connected
     res = g.add_road(0, g.board.points[0][0], g.board.points[5][5], True)
     assert res == Statuses.ERR_NOT_CON
     # Try adding a road connected to another player's settlement
     g.add_settlement(1, g.board.points[2][2], True)
     res = g.add_road(0, g.board.points[2][2], g.board.points[2][3], True)
     assert res == Statuses.ERR_ISOLATED
 def test_adding_starting_roads(self):
     # Create game
     game = Game()
     # Add starting settlement
     game.add_settlement(0, 0, 0, True)
     # Try adding a road
     res = game.add_road(0, [0, 0], [0, 1], True)
     assert res == Statuses.ALL_GOOD
     res = game.add_road(0, [1, 1], [0, 0], True)
     assert res == Statuses.ALL_GOOD
     # Try adding a disconnected road
     res = game.add_road(0, [2, 0], [2, 1], True)
     assert res == Statuses.ERR_ISOLATED
     # Try adding a road whose point's are not connected
     res = game.add_road(0, [0, 0], [5, 5], True)
     assert res == Statuses.ERR_NOT_CON
     # Try adding a road connected to another player's settlement
     game.add_settlement(1, 2, 2, True)
     res = game.add_road(0, [2, 2], [2, 3], True)
     assert res == Statuses.ERR_ISOLATED
Exemple #4
0
 def test_add_settlement(self):
     g = Game()
     # Try to add a settlement without the cards
     g.add_settlement(0, g.board.points[0][0])
     # Add cards to build a settlement
     g.players[0].add_cards(
         [ResCard.Wood, ResCard.Brick, ResCard.Sheep, ResCard.Wheat])
     # Try adding an isolated settlement
     res = g.add_settlement(0, g.board.points[0][0])
     assert res == Statuses.ERR_ISOLATED
     assert g.board.points[0][0].building == None
     # Add starting settlement and two roads to ensure there is an available position
     assert g.add_settlement(0, g.board.points[0][2],
                             True) == Statuses.ALL_GOOD
     assert g.add_road(0, g.board.points[0][2], g.board.points[0][1],
                       True) == Statuses.ALL_GOOD
     assert g.add_road(0, g.board.points[0][0], g.board.points[0][1],
                       True) == Statuses.ALL_GOOD
     res = g.add_settlement(0, g.board.points[0][0])
     assert res == Statuses.ALL_GOOD
     assert g.board.points[0][0].building != None
     assert g.board.points[0][
         0].building.type == Building.BUILDING_SETTLEMENT
                # Loop while road input is invalid
                while True:
                    with terminal.location(0, terminal.height - 1):
                        print("Please choose from one of the following points to build your road to:")
                        # Go through valid points
                        for i in range(len(points)):
                            # Print each point as an option
                            print("%s. %s" % (i, points[i].position))
                        # Prompt user to chose a point
                        choice = integer_input("Which point do you want to build your road to? ")
                        # Ensure choice is valid
                        if choice < 0 or choice > len(points) - 1:
                            print("Please choose a valid option")
                        else:
                            # Add the road
                            res = game.add_road(player=p.num, start=[row, index], end=points[choice].position, is_starting=True)
                            # If successful, break the loop and go to the next player
                            if res == Statuses.ALL_GOOD:
                                break
                # Break from outer loop, so that the next player is prompted:w
                break

    # While the game is not won
        # Roll the die
        # Hand out appropriate resources
        # Let this turn's player trade
        # Let this turn's player build

    # Announce winner
    pass
        if hex_type == HexType.HILLS:
            return "H"
        elif hex_type == HexType.MOUNTAINS:
            return "M"
        elif hex_type == HexType.PASTURE:
            return "P"
        elif hex_type == HexType.FOREST:
            return "F"
        elif hex_type == HexType.FIELDS:
            # Since F is already used, use W for "wheat"
            return "W"
        elif hex_type == HexType.DESERT:
            return "D"
        else:
            raise Exception(
                "Unknown HexType %s passed to get_hex_type_string" % hex_type)


if __name__ == "__main__":
    g = Game()
    br = BoardRenderer(g.board, [50, 10])
    # Add some settlements
    g.add_settlement(player=0, r=0, i=0, is_starting=True)
    g.add_settlement(player=1, r=2, i=3, is_starting=True)
    g.add_settlement(player=2, r=4, i=1, is_starting=True)
    # Add some roads
    g.add_road(player=0, start=[0, 0], end=[0, 1], is_starting=True)
    g.add_road(player=1, start=[2, 3], end=[2, 2], is_starting=True)
    g.add_road(player=2, start=[4, 1], end=[4, 0], is_starting=True)
    br.render()