CIS501 Assignment 2

10 points; due Wednesday, February 11

You will rebuild Assignment 1 so that it implements the class diagrams that I have posted with this assignment sheet. The diagrams show that the Blackjack card game will use a Dealer object and Human and Android (computer-player) objects to simulate the game. The game is structured so that Humans and Androids can be "guest players", and the "house player" (who competes against each of the guest players) can itself be either a Human or an Android. The program is a "virtual reality" of the Blackjack game, a simulation.

We will move slowly into using graphics for input/output: At this time, the User Interface will use dialogs and "passive output forms": Message-box dialogs will ask the human player(s) if she/he want more cards. A passive output Form for each player (see the VS Notes) will display the cards in the player's hand, the hand's score, the number of rounds played so far, and the total number of wins so far for the player. Every Player (including the house player), owns a separate passive output Form. I've included a demo VS Forms Solution that shows how to use passive output forms in this way.

Once the game is starts, it never ends (in true Las-Vegas style), so there is no button that "stops" the game.

Implementation and Testing

This assignment is an exercise in implementing correctly a class diagram, which is a basic skill that a software engineer must master. Your coding must follow the diagram exactly, even if you are not completely happy with the design. (This is like real life: you start out as a software engineer and later move up to software architect.)

So, first study the class diagram and visualize in your mind what you must code to implement the system. I have added comments to the class diagrams to help you understand the abilities and responsibilities of the components.

When the class diagram omits details about a class, you may supply these. (E.g., the diagram says almost nothing about the format of the OutputForm you will implement.)

Reuse and modify ClassConcepts as the diagram indicates. (A hint: to implement the methods, surrenderHand and acceptDiscards, use some of the list operations documented at www.dotnetperls.com.)

Make a new, separate VS Forms Solution, Blackjack2, to hold the classes for the dealer, the players, and the forms. The game's Main function also lives here, in class Program.

You must include a UnitTest Project in Solution Blackjack2. The unit-test project must hold useful unit tests for the Human, Android, and Dealer classes. (You are not required to write unit tests for the OutputForm, since it will be tested when we integrate the components into a complete system.)

I've drawn a package diagram, which shows how you should organize your two VS Projects and VS Solutions. The package diagram is included in the folder that contains this assignment sheet, the class diagrams, and the starter code.

As stated above, the game can be configured so that there is a mix of Humans and Androids. Here is how Blackjack2's Main function looks when the game is configured with one Android Guest Player, one Human Guest Player, and an Android that serves as the House Player. This is how you must code Main when you submit your work:

static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        //Application.Run(new Form1());  // instead, we use Form1  as
        //  a passive output form that each Player constructs for its own

        // assemble the system and call the Dealer, who "controls" the game:        
        Player housePlayer = new Android("House");
        List<Player> guestPlayers = new List<Player>();
        players.Add(new Android("Robo"));
        players.Add(new Human("You"));
        Dealer d = new Dealer(guestPlayers, housePlayer);
        while (true) { d.playRound() };
}
Now, it is easy to modify the simulation to have all Androids or all Humans or a mix.

Assignment 2 is a simulation-style system, where the Dealer controls execution and the human is a participant. The Dealer and Androids play quickly, and the output data flashes by too quickly for you to read.

Here is something simple you can do to "pause" the simulation so that you can see how the round ended for everyone: Within the method, outcomeOfRound for class Human, insert a message box, like this:

===================================================

class Human : Player {
   private Hand h;  // a human's hand of cards
   // perhaps I remember the number of rounds and the wins so far:
   private int rounds;
   private int wins; 
   
   ...
   
   // records the  result  of the round and displays it to the human:
   public void outcomeOfRound(Outcome result) {
       rounds = rounds + 1;
       if result == Outcome.Win) {
           wins = wins + 1;
       }
       // place this as the last line:
       MessageBox.Show("The result is " + result + "!\nClick to play another round.");
   }
}

===================================================
This lets you see your score (and the others') before the next round of play.

Documentation

When you build a system, you must document it so that other developers can understand your work. C# has a standardized, XML format for documenting classes and methods; it's used to generate on-line web-page documentation. I will not require that you use the XML format (it is verbose), but I do demand that each class and public method is documented with at least a one-sentence comment that explains the item.

The comment should explain the purpose ("ability"/"responsibility") of the item, the uses of its parameter names (if any), and the result (if any) that is returned.

Important fields and important constructor methods must also be documented with one-line comments. That is, you are required to make your documentation look like what I inserted into class library CardConcepts.

Also, you must draw an object diagram that shows the object layout in the Heap after the program has already played several rounds of Blackjack and the dealer has dealt the players more cards to start yet another round. Convert the diagram into either a .pdf, .jpg, or .txt file with the name, ob.XXX, where XXX is the correct extension. (Note: If you draw the diagram clearly on paper and use a cell-phone camera to take a decent photo, then I will accept the photo as a .jpg file.)

Once you complete your work, play the game with one android player, one human player, and an android house player for 3-4 rounds and then take a screen capture at the end of the last round. The screen capture must show the game's Forms, which themselves show the hands, announce the winner, and show the totals for all players. Save the screen capture as the jpg file, screen.jpg.

(If you don't know how to make and save a screen capture as a .jpg file, ask me)

Submission

Make a folder with the name, MyLastName.MyFirstName.Assn2, and copy into it Zip the folder into a .zip file and submit the .zip file to the CIS501 site on K-State Online. (See the package diagram for the correct nesting of folders!)

The teaching assistant will study your work and apply some tests. Then, you and I will meet to discuss your work on this assignment as well as on Assigment 1. The meetings will be scheduled soon. When we meet, be prepared to explain in detail your work. I can give you credit for your work only if you did your own work, you understand what you have done, and you can explain your work to me clearly. Communication is critical to modern software development, because large systems are designed and developed by teams. The teams mostly talk about the design, not about the code.

This is individual work

You must do this exercise solo. This is because I must assess the skills you have acquired so far in your studies. If you have difficulties, we can discuss what can be done to improve your abilities. If I determine that you had unauthorized aid, I will award no points for your work and you get into trouble.