Java Reference
In-Depth Information
7.32 (Project: Card Shuffling and Dealing) Modify the application developed in Exercise 7.31
so that it can simulate the dealer. The dealer's five-card hand is dealt “face down,” so the player can-
not see it. The application should then evaluate the dealer's hand, and, based on the quality of the
hand, the dealer should draw one, two or three more cards to replace the corresponding number of
unneeded cards in the original hand. The application should then reevaluate the dealer's hand.
[ Caution: This is a difficult problem!]
7.33 (Project: Card Shuffling and Dealing) Modify the application developed in Exercise 7.32
so that it can handle the dealer's hand automatically, but the player is allowed to decide which cards
of the player's hand to replace. The application should then evaluate both hands and determine who
wins. Now use this new application to play 20 games against the computer. Who wins more games,
you or the computer? Have a friend play 20 games against the computer. Who wins more games?
Based on the results of these games, refine your poker-playing application. (This, too, is a difficult
problem.) Play 20 more games. Does your modified application play a better game?
7.34 (Project: Card Shuffling and Dealing) Modify the application of Figs. 7.9-7.11 to use Face
and Suit enum types to represent the faces and suits of the cards. Declare each of these enum types as
a public type in its own source-code file. Each Card should have a Face and a Suit instance variable.
These should be initialized by the Card constructor. In class DeckOfCards , create an array of Face s
that's initialized with the names of the constants in the Face enum type and an array of Suit s that's
initialized with the names of the constants in the Suit enum type. [ Note: When you output an enum
constant as a String , the name of the constant is displayed.]
7.35 (Fisher-Yates Shuffling Algorithm) Research the Fisher-Yates shuffling algorithm online,
then use it to reimplement the shuffle method in Fig. 7.10.
Special Section: Building Your Own Computer
In the next several problems, we take a temporary diversion from the world of high-level language
programming to “peel open” a computer and look at its internal structure. We introduce machine-
language programming and write several machine-language programs. To make this an especially
valuable experience, we then build a computer (through the technique of software-based simula-
tion ) on which you can execute your machine-language programs.
7.36 (Machine-Language Programming) Let's create a computer called the Simpletron. As its
name implies, it's a simple machine, but powerful. The Simpletron runs programs written in the
only language it directly understands: Simpletron Machine Language (SML).
The Simpletron contains an accumulator —a special register in which information is put
before the Simpletron uses that information in calculations or examines it in various ways. All the
information in the Simpletron is handled in terms of words. A word is a signed four-digit decimal
number, such as +3364 , -1293 , +0007 and -0001 . The Simpletron is equipped with a 100-word
memory, and these words are referenced by their location numbers 00 , 01 , , 99 .
Before running an SML program, we must load , or place, the program into memory. The first
instruction (or statement) of every SML program is always placed in location 00 . The simulator
will start executing at this location.
Each instruction written in SML occupies one word of the Simpletron's memory (so instructions
are signed four-digit decimal numbers). We shall assume that the sign of an SML instruction is always
plus, but the sign of a data word may be either plus or minus. Each location in the Simpletron's mem-
ory may contain an instruction, a data value used by a program or an unused (and so undefined) area
of memory. The first two digits of each SML instruction are the operation code specifying the opera-
tion to be performed. SML operation codes are summarized in Fig. 7.33.
The last two digits of an SML instruction are the operand— the address of the memory location
containing the word to which the operation applies. Let's consider several simple SML programs.
 
Search WWH ::




Custom Search