This is a Simple AI which can be used as the base for an entry into the Shoreditch AI Competition.
You should only need to edit logic.py, though you are welcome to modify others (or write your own from scratch).
Get it running
Follow the instructions at https://github.com/Wazoku/Shoreditch-Gamerunner to set up a local environment for developing your AI. You can also look at My bot as an example of some of the changes which can be made. Mine isn't very good though, I'm sure you can do better!
When a game is started, the
start_game method will be called.
When it's your turn to take a turn, the
start_turn method will be called. the
actions parameter includes a list of actions taken by other players since your last turn. All turn actions should be taken in this method, and the method should end with game.end_turn().
If the turn runs out the
time_up method will be called. When this is called it also sets game.turn to be False, which can be checked in the
end_game will be called when a game is over. Error will be set if there was a problem (e.g. another player doesn't exist), otherwise it will be None. This method can be used to clean up temporary data from the game.
incoming_trade will be called when a trade is offered from another player.
player is the ID of the player offering the trade,
offering is resource -> number of what is being offered for trade,
requestings is resource -> number of what the other person wants for trade. Return True to accept the offer and False to reject.
The object "game" is passed in all calls, and it represents the game in progress.
a Game has the following attributes:
gamewhich is the unique id of the game
resourceswhich is resource -> number for every resource the player has
generatorswhich is resource -> number for every basic generator the player has
improved_generatorswhich is resource -> number for every improved generator the player has
prwhich is the amount of PR the player has
customerswhich is the amount of customers the player has
turnwhich indicates if it's the player's turn or not
and the following methods:
can_purchase_prreturns True if the player has enough resources to purchase PR
can_purchase_generatorreturns true if the player has enough resources to purchase a generator and doesn't have more than the maximum limit
can_upgrade_generatorreturns true if the player has enough resources to upgrade a generator, doesn't have more than the maximum limit, and has at least one generator to be upgraded
purchase_prwill purchase 1 PR, returning True if the player now has the most PR in the game (and a 2 customer bonus), and false if they do not.
purchase_generatorwill purchase 1 random generator, returning the generator type purchased. If you cannot purchase a generator it will return False
upgrade_generatorwill upgrade either the generator type passed as the first parameter, or a random generator. If it is able to upgrade the generator it will return the type of the generator upgraded, otherwise it will return False.
tradeshould be called with
requestingas resource -> number indicating what is being offered/requested. This will return the id of the user who accepted, if it is accepted (or "bank" if accepted by the bank), and False if it is rejected.
end_turnwill end then turn.
The object "db" is passed in all calls, and it can be used to store information across requests. It supports the following calls:
- db.save(doc) - Save a document to the store (with a unique 'id' key) - if no id is present in the document, one is generated and returned.
- db.get(id) - Get a doc from the store by its id
- db.exists(id) - Does a document with the given id exist?
- db.get_by_keys([keys]) - Get a number of documents by keys
Remember that more than one game can be ongoing at a single time, so it's possible for database to be shared amongst games. You should ensure you use unique ids when storing things in the database (e.g. by prefixing keys with the game id)