Write a program to play the game of Three Musketeers--human against computer.
You have probably never heard of this game. That's okay, the rules are simple--that's why I chose it. The link above is to a Wikipedia article that explains the game, and I can answer questions if necessary. It also happens to be a pretty good game.
git is a "Version Control System." That is, it keeps track of the current and all previous versions of a program, supports multiple current versions, and provides excellent support for teams in which multiple people contribute to the development of a program. GitHub is a web site which holds the programs being developed with git.
At your earliest convenience, download and install git on your own computer (if it isn't there already). We won't actually be using it on this assignment, however, because it's too easy to get tangled up in it if you don't know what you are doing. I will lecture on git later, in some detail. For this assignment, just go to https://github.com/DavidMatuszek/ThreeMusketeers and copy the two .py files you find there into your own directory.
According to the dictates of agile programming, it is better to write the tests before writing the code to be tested. Since in this assignment I'm providing stubs for both methods and their tests, this is an easy time to try doing things the agile way.
I have an entire writeup on Test-Driven Design (TDD), but here's the capsule version:
pick a method that doesn't depend on other, untested methods
while the method isn't complete:
write a test for the desired feature
run all tests and make sure the new one fails
while any test fails:
add/fix just enough code to try to pass the tests
refactor the code to make it cleaner
See the Wikipedia article for the rules of the game.
The "board" is represented as a list of five lists; each of these lists represents a row, and each list contains five elements. The first list represents the first row; the first element in each list represents the first column. The values in the list must each be one of three things: an 'M', representing a Musketeer, an 'R', representing one of Cardinal Richelieu's men; and a '-', representing an empty space. board is the one and only global variable in this program.
Directions are given as one of the four strings 'left', 'right', 'up', and 'down'.
Starter code, both three_musketeers.py and three_musketeers_test.py, can be found on GitHub at https://github.com/DavidMatuszek/ThreeMusketeers. Your job is to complete the program, writing both the tests and the code.
three_musketeers_test.py,
setUp(self) function is called before each and every test, and gives you a fresh new board (in three_musketeers.py, not here in the test file). This is done so that the result of one test does not depend on what other tests may have done. (You can use a different initial test board if you like.)set_board method (in three_musketeers.py) can be called when you want to perform tests on some other board that the one in setUp.self.fail() command causes the test to fail. You should replace each such command with real tests.three_musketeers.py,
assert condition at the beginning of a function, that means you can assume the condition holds as you write the function. It also means you should only call the function with parameters that satisfy the condition.pass statement does nothing. You should replace every pass statement with actual working code.Here are some Python things to remember:
location is a two-tuple, all of the following work:
(row, column) = locationlocation = (row, column)column = location[1][1, 2] + [3, 4] gives [1, 2, 3, 4].append adds an element to a sequence. For example, if a = [1, 2], a.append(3) changes a to [1, 2, 3].b is a list of lists, b[0] is the first list, and b[0][0] is the first element in the first list. For example, if c is [[1, 2], [3, 4, 5]] , then c[1][2] is 5.The computer does not have to play a great game--it does have to play legally. However, if the computer plays stupidly, it won't be much fun. If you would like to implement a simple strategy, here's a start:
Don't spend any more time than necessary on strategy until after the program is working!
Turn your assignment in to Blackboard before 6am Friday, September 19. This is a pair programming assignment, so you should decide which of you will turn it in (we don't want to grade two copies of the same program). Be sure to put both of your names in a comment right at the top of the program.