ECE 225B: Universal Probability and Applications @UCSD¶
Homework 4: Rock-Paper-Scissors competition¶
Due: June 15, 2018, 11:59 PM
Late homework will never be accepted.
The homework will be collected through Gradescope. Please follow the submission instruction on Piazza.
Please read the following problems carefully, and write down your code as clearly as possible and add suitable comments.
NAME:
PID:
In this homework, we implement a rock-paper-scissors agent. We will use the platform on the website http://www.rpscontest.com/ to test the performance of the codes, so please implement your code with the format.
The attached files inculde:
- rpsrunner.py: The match runner provided by rpscontest.com (http://www.rpscontest.com/rpsrunner.py). This version is adapted to Python 3, and few minor I/O formats have been adjusted from the original code.
- 'rpsbots': This folder contains the currently top-ranked 20 bots on rpscontest.com. Excluding few apparent duplicates, there are total 16 bots. 'ref.xlsx' file contains the snapshot of the leaderboard at the time of cropping.
- mybot.py: This is a sample code which plays uniformly at random among (R,P,S).
You can learn how to use 'rpsrunner.py' in the following. The %run command allows us to run a python code in a notebook cell.
For the details, see https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-run.
%run -i rpsrunner -h
Rock-Paper-Scissors Runner v1.0.1 (http://www.rpscontest.com/)
rpsrunner.py [options] <POOL1> [POOL2]
rpsrunner.py [options] bot1.py bot2.py bot3.py
Options:
-h|--help Print this usage output
-l|--low Run the process at a lower priority to keep the
system responsive.
-m|--matches <N> How many matches to play for each pairing [def: 10]
-t|--threads <N> How many execution threads to use [def: 4]
The multiprocessing module must be available to use more than one
execution thread. On this host, multiprocessing is: AVAILABLE
Additional arguments:
Pool format: bot1.py,bot2.py[,bot3.py,...]
or : "bot*.py"
You must specify at least two bot files in one or two pools. If one
pool is specified, all bots in that pool will play against every other
bot for the number of matches specified.
If two pools are specified, all the bots in each pool will play all the
bots in the other pool.
Example:
rpsrunner.py -t 4 -m 100 mybot.py "rpsbots/*.py"
rpsrunner.py mybot1.py,mybot2.py "rpsbots/*.py"
NOTE: Bots run through this script have full access to the Python
interpreter, so they could use it to do all sorts of nasty things to your
computer. You must review the code for any bot you want to run, and if
you're not sure what the bot does, then you shouldn't run it.
For example, you can run matches between your bot and all the opponents in the rpsbots/ folder as follows.
As one may expect, no agent can beat the random player consistently.
%run -it rpsrunner -t 1 -m 100 mybot.py "rpsbots/*.py"
Pool 1: 1 bots loaded
Pool 2: 16 bots loaded
Playing 100 matches per pairing.
Running matches in 1 threads
1600 matches run
total run time: 308.61 seconds
rpsbots\bot10.py: won 55.0% of matches (55 of 100)
won 33.2% of rounds (33249 of 100000)
avg score 1.2, net score 121.0
rpsbots\bot20.py: won 54.0% of matches (54 of 100)
won 33.4% of rounds (33357 of 100000)
avg score 1.8, net score 180.0
rpsbots\bot16.py: won 51.0% of matches (51 of 100)
won 33.3% of rounds (33299 of 100000)
avg score -1.1, net score -115.0
rpsbots\bot4.py: won 51.0% of matches (51 of 100)
won 33.4% of rounds (33371 of 100000)
avg score 2.3, net score 228.0
mybot.py: won 50.4% of matches (806 of 1600)
won 33.3% of rounds (532844 of 1600000)
avg score 0.5, net score 725.0
rpsbots\bot18.py: won 50.0% of matches (50 of 100)
won 33.4% of rounds (33405 of 100000)
avg score 1.8, net score 175.0
rpsbots\bot8.py: won 50.0% of matches (50 of 100)
won 33.4% of rounds (33371 of 100000)
avg score 0.1, net score 10.0
rpsbots\bot1.py: won 49.0% of matches (49 of 100)
won 33.3% of rounds (33270 of 100000)
avg score -0.7, net score -69.0
rpsbots\bot13.py: won 49.0% of matches (49 of 100)
won 33.0% of rounds (33048 of 100000)
avg score -1.9, net score -194.0
rpsbots\bot5.py: won 48.0% of matches (48 of 100)
won 33.2% of rounds (33207 of 100000)
avg score -0.3, net score -31.0
rpsbots\bot15.py: won 47.0% of matches (47 of 100)
won 33.2% of rounds (33209 of 100000)
avg score -0.1, net score -6.0
rpsbots\bot19.py: won 47.0% of matches (47 of 100)
won 33.2% of rounds (33188 of 100000)
avg score -2.5, net score -249.0
rpsbots\bot6.py: won 46.0% of matches (46 of 100)
won 33.3% of rounds (33264 of 100000)
avg score -1.4, net score -136.0
rpsbots\bot12.py: won 45.0% of matches (45 of 100)
won 33.4% of rounds (33397 of 100000)
avg score 1.5, net score 154.0
rpsbots\bot17.py: won 45.0% of matches (45 of 100)
won 33.3% of rounds (33310 of 100000)
avg score -1.4, net score -139.0
rpsbots\bot14.py: won 44.0% of matches (44 of 100)
won 33.1% of rounds (33110 of 100000)
avg score -3.0, net score -302.0
rpsbots\bot3.py: won 40.0% of matches (40 of 100)
won 33.1% of rounds (33064 of 100000)
avg score -3.5, net score -352.0
IPython CPU timings (estimated):
User : 308.62 s.
System : 0.00 s.
Wall time: 308.62 s.
In this homework, what you have to do is to implement your own bot and report the match result obatined from
%run -it rpsrunner -t 1 -m 100 mybot.py "rpsbots/*.py"
Please explain the idea of your algorithm and why you think that the idea would work well against other agents.
For the detailed implementation instruction, see http://www.rpscontest.com/submit.