C代写:COMP1511 Trader Bot

代写一个交易机器人,根据不同的随机场景,编写算法完成最大化交易。

Introduction

Your task is to write a bot in C. Your bot must successfully buy, transport and sell items in a virtual world. The details of the Trader Bot world are randomly generated for each game. Here is an example:

Name            Type            Commodity   Quantity    Price
CSE             Start
Harvey-Norman   Buyer           Televisions      541     1307
MSY             Buyer           Computers        333     3033
Caltex          Petrol station  Fuel             684      215
Dump            Dump
Coles           Buyer           Mars Bars       1401      348
O'Reilly        Seller          Books           9830      166
4 Pines         Seller          Beer            8050       90
LG              Seller          Televisions     2628      677
Lenovo          Seller          Computers        307     1666
Aldi            Buyer           Mars Bars       3994      343
Quadrangle      Other
BP              Petrol station  Fuel             388      111
Mars            Seller          Mars Bars       5396      142
J&B Hifi        Buyer           Computers        305     3231
Physics Lawn    Other
Apple           Seller          Computers        906     1640
Dell            Seller          Computers        711     2087
Good Guys       Buyer           Televisions      916      950
James Squires   Seller          Beer            9584      105
Regent Hotel    Buyer           Beer           10345      159
Sony            Seller          Televisions      360     1025
Batch Brewing   Seller          Beer            8298       85
Addison-Wesley  Seller          Books           6441      121
UNSW Bookshop   Buyer           Books           2890      342
Umart           Buyer           Computers        215     3395
Racecourse      Other
IGA UNSW        Buyer           Mars Bars       4403      302
Prentice-Hall   Seller          Books           7337      127
Whitehouse      Buyer           Beer            6531      165

Your bot has a fixed number of turns in the Trader Bot world. Its only goal is to have as much cash as possible after the last turn.

Each turn, a bot is given a description of the world and asked to make a single action.

There are four types of actions: Move, Buy, Sell and Dump.

A bot makes money by buying a commodity from one location and selling to another location at a higher price.

For example, it might buy Computers from Dell at $2089 each at sell them to MSY at $3033 each.

A bot must move to a location before it can buy or sell from that location.

A bot making a Move action specifies the number of locations they wish to move. A bot can move backwards by specifying a negative number of locations. The Trader Bot world is circular so you can move from the last location to the first location and vice-versa.

For example, in the world above a bot at MSY which makes a Move 3 action would go to Coles. If instead a bot at MSY a made Move -5 action they world go to IGA UNSW.

There is also limit on the maximum number of locations a bot can move in one turn. This limit does not change during the game.

Each location a bot moves will use up 1 unit of fuel. A bot without fuel cannot move (it can perform other actions). A good bot will likely need to purchase fuel.

A bot attempting to make a move that would use up more than its available fuel or exceed the move limit is not penalized. It is moved the maximum possible distance.

Each location buys or sells at most one type of commodity. No location both buys and sells a commodity. Some locations do not buy or sell any commodity.

A bot making a Buy action must specify the number of items they wish to buy. A bot may receive less items than it requests. This will occur if:

  • the quantity exceeds the number of items the seller has
  • the bot has insufficient money
  • the items would exceed the bot’s weight
  • the items would exceed the bot’s volume limits.

A bot’s cash is reduced by the price of the items it receives in a Buy action.

A bot will usually then use one or more Move actions to go to a location which buys this commodity. A bot may however choose to buy more items either of the same type or of another type.

A bot making a Sell indicates the number of items they wish to sell. A bot making a Sell action must be on a location which buys this type of item. The amount that is actually sold may be limited by the amount the buyer wishes to buy. This and the price the buyer will pay is indicated in the location’s description.

A bot’s cash will be increased by the total price of the items it sells in a Sell action.

Bot’s are not penalised for attempting to buy or sell more items than is possible. The transaction will be carried out as much as is possible. For example, if a bot attempts to buy 10000 items from a location which only has 25 items, they will be sold 25 items (other restrictions permitting).

Trader Bot worlds will always contain one or more locations of type LOCATION_DUMP. At these locations, a bot can make a Dump action and all the items it has on board will be removed. The bot receives no cash for these items. A Dump action is only useful if a bot has items that can’t be sold and wishes to make room for other items.

Trader Bot worlds will always contain one or more locations of type LOCATION_PETROL_STATION which sell fuel. Fuel is placed in a bot’s fuel tank, it is not included in the bot’s cargo. Fuel does not affect a bot’s weight and volume limit - there is a separate limit on the amount of fuel a bot can carry. Fuel cannot be sold by a bot. Bots always start with the maximum amount of fuel they can carry.

Trader Bot worlds will always contain one location of type LOCATION_START. Bots start at this location.

The initial state of the world is randomly determined at the beginning of each game. The details of the world including prices do not change during the game. The only exception is that the amount of items buyers and sellers are willing to trade reduces as bots buy and sell items.

Multi-bot Worlds

Your bot will be tested in Trader Bot worlds where it is the only bot present.
It will also be tested in Trader Bot worlds where other bots are present.

All bots start at the same location, with the same amount of fuel & cash and have the same number of turns. All bots have the same limits on the amount of fuel they can carry, how far they can move and the maximum volume and weight they can carry.

When multiple bots are present in a world each turn all bots’ get_action functions are called to request an action. The actions then occur simultaneously.

Multiple bots may be present on one location. If multiple bots on the one location make buy or sell requests which cannot all be satisfied the trade is divided fairly between the bots. Items will be left unsold if it not possible to divide trade fairly.

If, for example, there are 7 items for sale at a location, and 3 bots simultaneously request to buy all 7 items each bot will be sold 2 items and 1 item will be left unsold.

Getting Started

The week 10 lab exercises take you through getting started.
You may submit multiple .c files containing your Trader Bot code.

You may use any name for the source files of your program except trader_bot_main.c.

Your sources files must not include a main function.

Your sources files must contain two functions with exactly these prototypes:

1
2
3
char *get_bot_name(void);

void get_action(struct bot *bot, int *action, int *n);

get_bot_name is called once at the start of every game to get your bot’s name. This may be any string you choose. Do not use offensive or obscene words. A suffix will be added to your name if necessary to make it unique.
get_action is called once every turn to get your bot’s move.

get_action is given a pointer to a struct describing the current state of your bot. A full description of the Trader Bot world can be obtained by following pointers starting with this struct. get_action should not change the structs representing the Trader Bot world.

get_action assigns appropriate values to *action and *n to indicate the move it wishes to make this turn.

A significant component of this assignment is understanding the representation of the Trader Bot world.

The constants and types used in this representation are described in this file: trader_bot.h

You will need to #include trader_bot.h in your code.

DO NOT CHANGE trader_bot.h.

It is not necessary to submit trader_bot.h. If you do submit trader_bot.h its contents will be replaced by this file.

You may submit other .h files.

You may submit data files with the suffix .txt to be used by your program.

Testing

The script ~cs1511/bin/bot_test will automatically test your program on a random world.

...
$ ~cs1511/bin/bot_test C_files
dcc ...
...
...

Trader Bot Tournaments

Tournaments will be run on all bots submitted with give, starting Tue May 16 with the results displayed on the class web page.
This will allow you to see how your bot performs in a world with many other bots present.

Submitted bots will be first tested in a single-bot-world. They will only be be added to the tournament if they recah a qualifying-level of performance in a single-bot world.

Hints

You should follow discussion about the assignment in the class forums. Questions about the assignment should be posted there so all students can see the answer.
Don’t panic!

Assumptions/Restrictions

You submitted code must be C only. You may not submit code in other languages. You may not use system or other C functions to run external programs.
You may call functions from the standard C library and the maths library. You may not use functions from other libraries. Your program must compile with dcc without the -l flag being used to specify an extra library. If you don’t understand this requirement don’t worry - as long as the bot_test scripts compiles your program you are fine.

Your get_action function must take at most 10 seconds to return a move on a CSE computer when compiled with dcc –valgrind.

There is no way for your bot to pass information from one turn to the next. Your bot is not permitted to create files.

Sellers do not generate more of the items they sell during the game. The number of items they have for sale is reduced when bots buy items from them. The number of items they have for sale does not otherwise change.

This is also true for buyers. The number of items a buyer is willing to buy reduces when bots sell items to them. The number of items they are willing to buy does not otherwise change during the game.

trader_bot.h will not be changed when your bot is compiled for marking.

Submission of Work

You are required to submit intermediate versions of your assignment.
Every time you work on the assignment you should copy your work to your CSE account and submit it using the give command below.

It is fine if intermediate versions do not compile or otherwise fail submission tests.

Only the final submitted version of your assignment will be marked.

This will allow you to retrieve earlier versions of your code if needed.

You submit your work like this:

$ give cs1511 ass2 C files

Blogging

You must blog every time you work on this assignment, recording how much time you spent working on the assignment and what this time was spent doing (reading, designing, coding, testing, debugging, …).

You must blog about all significant bugs in your assignment including what test found the bug, how the bug was tracked down and fixed, how long this took and any lessons learnt.

You may create one big blog post and edit each time, or multiple small blog posts for the assignment.