Nim Project
From Huben's Wiki
(→Graphical Nim) |
|||
Line 2: | Line 2: | ||
This project will use several things we've encountered in other assignments in the past. | This project will use several things we've encountered in other assignments in the past. | ||
− | To get a grade, you must complete the bulleted items following it. | + | You may get any help you want, as long as you DOCUMENT it. Put the provenance of the help in your code as a comment at the top. For example: |
+ | <pre> | ||
+ | // Fred helped me with the toString() method. | ||
+ | // I found code for a nim sum online at xxxx and adapted it for my program. | ||
+ | </pre> | ||
+ | This will prevent problems of plagiarism. Please don't give each other code: write your own when you understand what is involved. Ask me if you are unsure or stuck: nobody needs to suffer for being stuck. | ||
+ | |||
+ | To get a grade, you must complete the bulleted items following it. Please make sure I give you a D before you go on to do more and get a higher grade. I should grade your program at least twice as you progress. | ||
===D:=== | ===D:=== | ||
Line 16: | Line 23: | ||
* The main() should create an instance of Nim and display the stones using the toString() method without directly calling toString(). | * The main() should create an instance of Nim and display the stones using the toString() method without directly calling toString(). | ||
===C-:=== | ===C-:=== | ||
− | * Use a Scanner in a loop to input a row | + | * Use a Scanner in a loop to input a row LETTER (either upper or lower case) and number of stones to remove. (Page 26 of text.) |
* The loop should only exit when a valid move has been selected. | * The loop should only exit when a valid move has been selected. | ||
− | * | + | * When a move is invalid, the loop should tell you why it is invalid. |
− | ** | + | * When a move is valid, the loop should tell you "Removing x from pile Y." |
− | ** not empty row | + | * Use Scanner.nextLine() instead of nextInt(): it is more robust. |
− | ** | + | * the easy way is to just look at the first character, if it exists, for row or stones |
− | ** | + | * it would be nicer if we could type b2 at one input to take two from row B. |
− | ** | + | * tests for valid row should reject: |
− | + | ** a simple return without typing anything | |
+ | ** characters that are not row names | ||
+ | ** empty row names | ||
+ | * tests for valid number of stones should reject: | ||
+ | ** a simple return without typing anything | ||
+ | ** zero | ||
+ | ** negative numbers | ||
+ | ** really large numbers such as 12345678901234567890 | ||
+ | ** more stones than in the row | ||
+ | ** anything not a number | ||
+ | |||
===C+=== | ===C+=== | ||
Line 40: | Line 57: | ||
== Graphical Nim == | == Graphical Nim == | ||
+ | ===D=== | ||
# Ch. 15 (Graphics) | # Ch. 15 (Graphics) | ||
− | ## | + | ## start with the box from studentdisk/Ch15/Exercises/Drawings.java |
+ | ## change the box to a filled circle | ||
+ | ===C+=== | ||
+ | # Read "Creating the graphical Nim board." | ||
# Build a pyramid of circles with height and base of 4 circles. | # Build a pyramid of circles with height and base of 4 circles. | ||
## start with a right triangle | ## start with a right triangle | ||
Line 48: | Line 69: | ||
## adjust coords to allow pyramid to resize with window | ## adjust coords to allow pyramid to resize with window | ||
### use min of width and height | ### use min of width and height | ||
+ | ### you ought to be able to have pyramids of other sizes too | ||
+ | ===B+=== | ||
# Use pyramid to display board instead of text | # Use pyramid to display board instead of text | ||
− | + | ===A+=== | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
# Read next two chapters, build with point and click interface. | # Read next two chapters, build with point and click interface. |