Assignment 3  --  Double Auction


Description -

    In this assignment, you are to write several functions to implement an agent which will participate in a series of double auctions.  The agent will start with some quantity of food and some quantity of gold.  These quantities will change through the course of the auction as the agent exchanges gold for food ("buys") or food for gold ("sells").  In addition to these student speculators, the auction will also contain farmers, who are good at creating food; miners, who are good at creating gold; and some additional speculators.  As the auction progresses, the ability of miners to create gold will vary, thus adding a random element to the "true price," the ratio between gold and food production.  Generally, selling food for more than the true price or buying it for less will result in a net profit.  The hard part is figuring out what the true price is.
    In each round of the series, the agent submits a price, the quantity of food it wishes to trade, and whether it wishes to buy or to sell.  If the agent is buying, the price is interpreted as the maximum price at which it will trade.  If the agent is selling, the price is interpreted as a minimum.  This is not a progressive auction; each agent may only bid once in each round, and it will not know any of the other agents' bids.  After all bids have been submitted, a computer auctioneer then selects the price which maximizes the amount of gold changing hands.  All "sell" offers with lower prices and all "buy" offers with higher prices are then executed.  The auctioneer then informs each agent of the price at which the auction closed, as well as its current gold and food supplies.  This is the information that the agent will use in the following round of the series.
    Any bid in which an agent tries to spend more gold than it has or sell more food than it has will be reduced to match its actual resources.  It is not actually possible to go bankrupt, but one may get very close.  Student agents will be judged mainly on how well they perform.  You are welcome to enter into whatever conspiracies you want, but it is impossible to determine the identity of any agent or the amount being bid.  Also, because both food and gold are continually being produced, cornering either market may be difficult.  Last, it is not permissible for any student's agent to call any of the bidding functions of any other agent.  In addition, all functions other than the three required for bidding must be declared static, so that it is not possible to have any name conflicts.

Details -

    A sample solution that uses a very simple algorithm may be found here.  All submissions should be C source code in a single file named lastname.c, where lastname is your last name.  If special libraries or other such resources are needed, you may also submit a makefile.  Each submission must include the following three functions, which must not be declared static:     Each of these functions tells the agent its current food and gold supplies and passes a pointer to a pointer to a user-defined data structure.  Whatever information you wish the agent to retain from round to round should be stored in this structure, which you need to initialize and maintain.  Please be reasonable in the amount of storage space required for your agent's data.  You should not need to store much more than a list of all previous closing prices, if even that much.
    The initialize function should allocate memory for your data structure and initialize it based on the price provided.  This price is the ratio of total food production to total gold production at time 0.  This function is called once, before the first round of bidding.
    The buy_sell function should return a boolean where 0 indicates "buy" and nonzero indicates "sell."  Price and quantity will not contain useful data when passed, and the agent should use these variables to return the price and quantity of its bid.  This function is called once in each round of the auction series.
    The update function allows you to alter your agent's information with the results of each round of bidding.  The price which is passed is the closing price from the auction that just ended.  This function is called once after each round of the series.

Requirements -

    To complete this assignment, you must submit the file lastname.c, containing the three functions mentioned above, an optional makefile, and a readme file explaining why your algorithm should perform well.  Please try to avoid having your program generate segmentation faults, since they waste everybody's time.
    After a number of trial runs, to give you the chance to see how your agent performs in competition, there will be the competition on which your grade will be based.  Your agent's performance there, in combination with your readme explaining the algorithm, will determine your grade for this assignment.
    Good luck!