Nim Project
From Huben's Wiki
(Created page with "== Text based Nim game == This project will use several things we've encountered in other assignments in the past. * [http://en.wikipedia.org/wiki/Nim Read the wikipedia article ...") |
|||
Line 1: | Line 1: | ||
== Text based Nim game == | == Text based Nim game == | ||
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. | ||
+ | |||
+ | 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:=== | ||
* [http://en.wikipedia.org/wiki/Nim Read the wikipedia article on Nim], and find a version to play. | * [http://en.wikipedia.org/wiki/Nim Read the wikipedia article on Nim], and find a version to play. | ||
* Create a class Nim, with a main(). | * Create a class Nim, with a main(). | ||
Line 11: | Line 22: | ||
</pre> | </pre> | ||
* 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(). | ||
− | * Use a Scanner in a loop to input a row | + | ===C-:=== |
− | * The loop should only exit when a valid move has been selected. | + | * 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. |
− | ** not empty row | + | * 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." |
− | ** | + | * 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+=== | ||
* Create and use a method to make the valid move. | * Create and use a method to make the valid move. | ||
+ | ===B-:=== | ||
* Create and use a method to detect a win. | * Create and use a method to detect a win. | ||
+ | ===B:=== | ||
* Get names of players, and alternate players. | * Get names of players, and alternate players. | ||
+ | ===A-:=== | ||
* Allow a computer player that makes random moves. | * Allow a computer player that makes random moves. | ||
+ | ===A:=== | ||
* Create a computer player that plays a perfect game. | * Create a computer player that plays a perfect game. | ||
+ | ===A+:=== | ||
* Allow users to select misere or regular version. | * Allow users to select misere or regular version. | ||
+ | |||
== Graphical Nim == | == Graphical Nim == | ||
− | + | ===D=== | |
− | + | # 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. | |
− | + | ## start with a right triangle | |
− | + | ## adjust x coords to make pyramid | |
− | + | ## adjust coords to center pyramid | |
− | + | ## adjust coords to allow pyramid to resize with window | |
− | + | ### 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 | |
− | + | ===A+=== | |
− | + | # Read next two chapters, build with point and click interface. | |
− | + | ||
− | + | ||
− | + |