首页 > > 详细

MBUSA90500 Programming

MBUSA90500 Programming, Module 2 2020
Assignment
Final submission before 9am 30 April 2020.
1 Updates
Updates will go here as the Assignment evolves.
2 Objectives
This project is designed to give your syndicate experience in software engineering, Python programming and simple
optimisation problems. In particular, you should experience the following.
• Python programming - every member of the syndicate must contribute code to the final solution.
• Software design - the process of breaking a task into pieces and assigning each piece to a programmer in such a
way that the pieces can be easily assembled.
• Software testing - each piece should be tested prior to integration, and then the whole tested once integrated.
3 Market Royale
You are to write a virtual player for a multiplayer game: Market Royale (based loosely on the Battle Royale genre of
games). You will submit your player to a tournament server and it will play against other syndicates.
The rules of the game are as follows.
1. The game begins with a map that has various markets connected by roads. At each market you can buy and
sell products. You begin at a random market with a purse full of gold and must traverse the map buying and
selling products in an attempt to reach your goal before time runs out.
2. The goal is given randomly to you at the start of the game. It is a lower bound/limit on the number of each
product you must obtain.
3. Prices at all markets vary for each game, but do not change in one game. When you arrive at a market, you
gain knowledge on prices at other markets from any player that is already at the site and has researched other
sites.
4. Before you can buy or sell at a market for the first time you must Research the market, even if you know the
prices from other players.
5. You may not buy at a market if you have zero or less gold.
6. For every turn you are in debt (less than zero gold) you pay 10% interest on the overdrawn amount.
7. Over time some markets become Black. Buying and selling at Black Markets is allowed, but you must pay a fee
of 100 gold for every turn you are in a Black Market. The turn before a market goes Black it goes Grey, giving
you one turn to leave the market before incurring the Black penalty if you wish.
8. Your final score is computed as the sum of 10000 for each product where you have at least your goal amount
plus any gold balance you have (including negative balances).
9. On each turn, your player can make the following moves.
(a) MOVE to a neighbouring market (ie one connected by a road to your current location).
(b) RESEARCH a market.
(c) BUY some amount of one product.
1
(d) SELL some amount of one product.
(e) PASS to do nothing.
10. There are 50 turns in a game. There are 7 players per game.
4 Your player
Your player must be Python3 code that defines a class called Player that subclasses BasePlayer (provided). You
may not change BasePlayer in any way.
The workhorse of Player is the method take turn which takes 5 parameters.
1. A string name of your current market location.
2. A dictionary with values (price, amount) tuples at this market with product names as keys ({} if you have not
researched this market): product:(price, amount).
3. a dictionary of information from other players located at this market with keys as market names (strings) and
values a dictionary with keys as product names and values as prices: market:product:price.
4. a list of market names (strings) that are Black.
5. a list of market names (strings) that are Grey.
The function take turn should return a two-element tuple where the first element is an attribute of the Command
class and the second is relevant data for the command (either None or a (product name, amount) tuple.
Note that your starting map, goal and gold are put into your Player object as attributes map, goal and gold
respectively at the start of the game, so you can assume they exist. It is probably best not to change the map and
goal attributes in your code, but you should keep track of your gold level. The Game does not change self.gold
once it has started.
You can access markets connected to another by a road in the map using the following methods.
self.map.get_neighbours(node_name)}
"""@param node_name str name of node/location in map
@return List of string names of markets connected to node_name by a road.
"""
self.map.is_road(n1, n2)
"""@param n1 str name of node/location in map
@param n2 str name of node/location in map
@return True if n2 is connected to n1 by a road.
"""
\end{itemize}
Here is a minimal player that you could submit to the tournament.
class Player:
"""Minimal player."""
def take_turn(self, location, prices, info, bm, gm):
return (Command.PASS, None)
Your class can contain anything else you like, just as long as take turn exists in the correct format. You might like
a repr function. There is no way to pass arguments to the constructor of your Player object in this tournament,
so if you define an init function it should not take arguments.
There will be a time limit on the take turn function of 5 seconds. If your function takes longer than 5 seconds to
return, you will miss that turn (Command.PASS).
2
5 Submitting to the tournament
The tournament will run as a server expecting you to send commands to add and delete players as JSON objects.
You can ADD (and DEL) as many players as you like to the tournament, so a syndicate could have multiple players
in the tournament at any one time.
The server is located at IP address 128.250.106.25 and port 5002.
You should use the following code (or similar) to send your JSON object to the server.
def send_to_server(js):
"""Open socket and send the json string js to server with EOM appended, and wait
for \n terminated reply.
js - json object to send to server
"""
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect((’128.250.106.25’, 5002))
clientsocket.send("""{}EOM""".format(js).encode(’utf-8’))
data = ’’
while data == ’’ or data[-1] != "\n":
data += clientsocket.recv(1024).decode(’utf-8’)
print(data)
clientsocket.close()
The JSON object you send should contain four key:value pairs as follows.
• Key "cmd" which has the value of either "ADD", "DEL" or "TEST".
• Key "syn" which has the value of your syndicate number.
• Key "name" which has the value of a team name for the leader board.
• Key "data" which has the value of string that is your python code.
Please delete your old players otherwise the system might grind to a halt.
You can view the leader board at http://codemasters.eng.unimelb.edu.au/mbusa_2020_assignment/lb.html.
If your player throws an exception, it is deleted from the tournament. You can view the exceptions at
http://codemasters.eng.unimelb.edu.au/mbusa_2020_assignment/e.html.
6 Local Testing
Before submitting to the server you should test your code othwerwise you might crash the server. Also there is not
much feedback from the server if your code goes wrong. To test locally, you can run a game containing just your
players like this.
from Game import Game
p1 = Player()
p2 = Player()
g = Game([p1,p2], verbose=True)
res = g.run_game()
print(res)
7 Assessment
7.1 Within-syndicate responsibilities
It is expected that you will structure the Python code so that it is split into parts, and different members of the
syndicate will write different parts of the code. Naturally you can collaborate, but it is in the best interests of the
3
weak coders that they be given a coding task to complete. The temptation for the strong coders to do the lot is
high, but there will be coding questions about this assignment on the exam that each individual must answer. I
suggest the strong coders concentrate on the design, and splitting the tasks up amongst the syndicate, aiming to
allot the tasks based on syndicate member’s abilities. If strong coders are looking for a challenge, then there is graph
traversal and optimisation algorithms to extend you.
It is expected that at least one function is attributed (in comments) to each member of the syndicate.
7.2 Submission
The highest ranked player on the server from each syndicate as at 20 April 9am will be assessed. I will get the code
from the server, and run it through a beautifier to format it and get a single file of Python. Please include
comments, etc in your submission, and feel free to include large comments on your approach to defeating other
players, and other strategic points, within the code.
7.3 Marking Rubric for a Syndicate
Component Property Mark
Submissions to server (socket + JSON) At least one working player added /3
(5 marks) Several players added and deleted /2
Basic approach to meeting goals at one market Accounting for goals and gold /2
(5 marks) Making choices at a market /3
Approach to moving Visited more than one market /1
Accounted for Black markets /2
(6 marks) Optimisation based on other player info /3
Final position in tournament (3 marks) 3 − bposition/4c /3
Code readability Variable names /2
(13 marks) Major comments (eg functions) /5
Minor/in-line comments when required /2
Modular design, no repeated code /2
Attribution of functions to particular authors /2
Total /32
AHT April 16, 2020
联系我们 - QQ: 99515681 微信:codinghelp2
© 2014 www.7daixie.com
程序代写网!