Example #1
0
    def position ( self, info ):
        """ Positions a dialog-based user interface on the display.

            Parameters
            ----------
            info : UIInfo object
                The UIInfo object associated with the window

            Returns
            -------
            Nothing.

            Description
            -----------
            This method is called after the user interface is initialized (by
            calling init()), but before the user interface is displayed.
            Override this method to position the window on the display device.
            The default implementation calls the position() method of the
            current toolkit.

            Usually, you do not need to override this method, because you can
            control the window's placement using the **x** and **y** attributes
            of the View object.
        """
        position( info.ui )
Example #2
0
def AICode():
    import random
    print "Now in python mode!"
    global rulesystem

    helper.printAboutMe()
    planets = []

    fleetsWithoutOrders = [x for x in helper.myFleets() if not helper.hasOrder(x)]
    #attack or colonise with all fleets without orders
    for fleet in fleetsWithoutOrders:
        if helper.name(fleet) == "Battleship Fleet":
            planet = helper.nearestEnemyPlanet(fleet)
            if planet:
                orderMove(fleet, helper.position(planet))
        else:
            closest = helper.nearestNeutralPlanet(fleet)
            if closest is None:
                print "Colonised 'em all!"
            else:
                if helper.position(fleet) != helper.position(closest):
                    planet = random.choice(helper.neutralPlanets() + [closest] * 5)
                    print "moving", helper.name(fleet)
                    orderMove(fleet, helper.position(planet))
                else:
                    print "colonising", helper.name(fleet)
                    orderColonise(fleet)

    #build one frigate or one battleship on every planet
    for myPlanet in helper.myPlanets():
        if not helper.hasOrder(myPlanet):
            if random.random() < 0.5:
                buildFrigate(myPlanet)
            else:
                buildBattleship(myPlanet)
    return