Saint Louis University |
Computer Science 150
|
Dept. of Math & Computer Science |
For this assignment, you must work individually in regard to the design and implementation of your project.
Please make sure you adhere to the policies on academic integrity in this regard.
The goal of this assignment is to create an image of a backgammon board, patterned carefully after the following model (click on image to zoom):
Backgammon is a two-player game played on a board with 24 triangles known as points. Each player starts with 15 checkers, with an initial configuration as shown above. The points alternate in color as you go around the board, and there is a clear top-to-bottom symmetry to the placement of the checkers.
We have chosen this assignment as a way to exercise your use of control structures. Although the board is fixed and finite, and you could presumably create the image above by manually configuring the geometry for 24 different triangles, 30 circles, 24 text labels, and so on, you will only receive significant credit if you use control structures to express these patterns. As a general rule, if you ever find yourself "copying-and-pasting" code from one part of a program to another, there should be a more elegant way to express the repetition and variation.
As we have done with other graphics programs, you should presume that there is some size variable that determines the width of each of those grid cells, so that you can do all other geometry computations based on the concept of such a width. You will notice that the points themself are labeled from 1 to 24 in a clockwise fashion starting at the bottom-right. Each triangle has a width of precisely one cell and a height of 5 cells. There is a vertical separation of one cell width between the top and bottom points, as well as the horizontal separation between the left-half and right-half of the board.
The only place that we deviate from the unit grid size measure is for the checkers. Although they appear to have a diameter of one cell width, they are actually slightly smaller. In particular, we have given each a diameter of 0.9 relative to the cell width, and we have stacked them against each other based on their actual size; this makes a better appearance as more of the underlying point shows. But this means that the checker centers are not aligned precisely with the center of the grid cells.
The other issue with the checkers is that we would like you to use control structures rather than to draw 30 different checkers, but the "pattern" of the initial checkers is not regular. What is needed to code this cleanly is to understand what aspects of the checkers change. There are three such aspects:
for num,pt,whiteOnTop in [(2,1,True), (5,6,False), (3,8,False), (5,12,True)]:This is a bit new, in that we are using a for loop to set a triple of variables rather than just one. That is, we're used to seeing something like
for x in sequence:But if the sequence is a sequence of tuples, you are allowed to set multiple variables to the values in those tuples. That is, we could do something like
for x,y in [ (1,2), (7,5), (4,8), (3,13), (2,15)]:as a way to describe a loop with five passes, such that in the first pass x=1 and y=2, and in the second pass x=7 and y=5, and so on.
Going back to our backgammon applications, we have four different repetiions we need, where each one is defined by a triple designating the number of checkers, the point for those checkers, and whether white checkers are at the top of the board (rather than the bottom).
Your program must start out by asking the user for the value of the number of pixels per grid-cell. Then, pick the appropriate canvas size and lay out the board with such a scale.
You should create a new file, backgammon.py, which contains all of your own code. This file must be submitted electronically.
You should also submit a separate 'readme' text file, as outlined in the general webpage on programming assignments.
Please see details regarding the submission process from the general programming web page, as well as a discussion of the late policy.
The assignment is worth 10 points.