Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860
Nim Project - Huben's Wiki

Nim Project

From Huben's Wiki
Jump to: navigation, search
(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 letter and number of stones to remove.
+
===C-:===
* The loop should only exit when a valid move has been selected.test for valid moves
+
* 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.)
** legal row name
+
* 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.
** at least one stone
+
* When a move is valid, the loop should tell you "Removing x from pile Y."
** no more stones than in the row
+
* Use Scanner.nextLine() instead of nextInt(): it is more robust.
** ignore case
+
* the easy way is to just look at the first character, if it exists, for row or stones
** ignore anything extra
+
* 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 ==
* to be formatted soon....
+
===D===
I Ch. 15 (Graphics)
+
# Ch. 15 (Graphics)
get some text in the box from the Display project
+
## start with the box from studentdisk/Ch15/Exercises/Drawings.java
II Build a pyramid of circles with height and base of 4 circles.
+
## change the box to a filled circle
start with a right triangle
+
===C+===
adjust x coords to make pyramid
+
# Read "Creating the graphical Nim board."
adjust coords to center pyramid
+
# Build a pyramid of circles with height and base of 4 circles.
adjust coords to allow pyramid to resize with window
+
## start with a right triangle
use min of width and height
+
## adjust x coords to make pyramid
IV Use pyramid to display board instead of text
+
## adjust coords to center pyramid
V Optional: add computer player misere version (lose if take last)
+
## adjust coords to allow pyramid to resize with window
if (all rows 2 or less) // endgame
+
### use min of width and height
maintain odd number of rows with one
+
### you ought to be able to have pyramids of other sizes too
else // midgame
+
===B+===
// nimsum = binary exclusive or of all row counts
+
# Use pyramid to display board instead of text
if nimsum == 0 // no forced win
+
===A+===
make any move
+
# Read next two chapters, build with point and click interface.
else // forced win
+
remove nimsum pieces from any row
+
VI Read next two chapters, build with point and click interface.
+

Latest revision as of 12:25, 11 June 2013

Personal tools
translate