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 an initial checkerboard configuration, patterned carefully after the following model (click on image to zoom):
Your program must start out by asking the user for the desired width of the canvas window (which should be square). The rest of your code must be written with enough generality that it creates an appropriate result for the given window size.
Your end result should look precisely like our model image. In particular:
You are creating an 8x8 grid, with the alternating red and black pattern, as shown above, with red in the top-left corner.
You will also be adding 12 yellow and 12 green checkers, in the configuration as shown in the above figure. In particular, all checkers reside on black squares, with yellow ones in the top three rows, green ones in the bottom three rows and no checkers in the middle two rows.
The canvas itself has a tan background, and we have intentionally sized the checkerboard so that there is an implicit margin around the edge of the board, with the width of the margin being precisely the width of an individual square from the board.
Equally important in this assignment is your technique. You must make legitimate use of control structures to exploit the obvious patterns which exist in the board. Given that the end result is fixed, it would be possible for someone to write code which technically works by individually drawing each of the 64 squares and each of the 24 circles. But you will not receive full credit for such an approach.
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.
We recommend computing a 'unitSize' variable and basing all of your other geometric computations on that value. This should allow your program to work seemlessly for any canvas size.
Given the large number of objects being added to a Canvas, you may notice that the graphics software cannot do this instantaneously. In some sense, this may be helpful when developing your code, as it almost makes an animation of the board being created piece-by-piece. But if you wish to have a quicker result, please change the "auto refresh" mode of the Canvas. This is done with a command such as paper.setAutoRefresh(False), which can be followed by your code to add all the objects to the board, and then finally a paper.refresh() to render the resulting image.
You should create a new file, checkers.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.
If your program is well-designed, you should be able to use it, not only to create the standard 8x8 checkerboard, but to create an NxN checkerboard pattern for any (even) value of N. Let's presume that we wish to define the rules for an NxN game so that each player starts with three rows of checkers (namely the top three rows and the bottom three rows, respectively). For example, here is an image of a hypothetical 20x20 game of checkers.
To meet this goal, ask the user for the canvas size and then for the value of N.