Computer Science Teacher
Computer Science Teacher - Thoughts and Information from Alfred Thompson

March, 2012

  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Why College?

    • 0 Comments

    Clark School Technology LabYesterday Edwin Guarin and I represented Microsoft at the formal opening of a computer lab at the Clark Elementary and Middle school in Hartford CT. The lab was donated by Ray Allen (UConn and Boston Celtics basketball star) and his Ray of Hope Foundation. Microsoft was pleased to donate software to support the lab. As part of the day’s events Ray spoke to the students where he emphasized the importance of school studying hard getting good grades and going to college. He said that college was important even for those who thought they were going to be professional athletes. When he asked how many students wanted to be professional athletes most of the student body raised their hands. Not unexpected for middle school students. Ray shed some light on that subject pointing out that it was a very long shot for any of them to make it. But today’s post was inspired by a question and answer that came at the end of his talk. One student pointed out a number of famous athletes who jumped into the NBA right from high school and said that college wasn’t necessary for them.

    Ray replied with a number of pieces of information. One is that doing this is very rare but secondly there were many more who jumped in early who disappeared quickly either into limited roles or out of the NBA and no one remembered them. What he pointed out was that playing college ball was an important part of learning the game as well as growing up. Players who skipped college often had only their natural talent which while it might be significant limited them at the professional level.

    Presenting an "I'm a PC" t-shirt to Ray Allen of the Boston CelticsI had a chance to talk to Ray and his business manager about this later. They told me that a lot of times they will be watching a game and see someone make an error that they really wouldn’t expect from a professional and realize that was a missing skill that they may well have gotten if they had played college ball before the NBA. Ray’s observation is that many who jump to the NBA early would have been better off in the long run (even financially) had they stayed in college to polish their skills more. Ray pointed out that the media loves to play up the exceptions while ignoring the players who didn’t make it. This is a common problem in other fields I realized. For example in computer science and software development.

    The software industry has its stars who either skipped college completely or didn’t complete it (Bill Gates in the latter category) who do really well. Many young people think that they can do likewise. In fact some who do make it convince themselves and others that skipping college was/is a better way of doing it. I have to say though that my experience (writing software for 40 years now) is that such stars are rare indeed. In proportion as rare as the LeBron James’ of the NBA. A college education is a better way to ensure a longer and more productive (and lucrative) career. The extra training not just in the core technology but in learning to learn and grow are tremendously helpful for a long productive career.

    I also talked to Scott Burrell, one of the coaches of the Quinnipiac men's basketball team and a veteran of the NBA himself. He talked about his role as a coach being more than just making his players better basketball players but better men. He talks about helping with their maturity and their attitudes towards things as basic as how they interact in public and with their teammates. And succeeding in school. Scott went back and completed his degree not two years ago which certainly shows how much he values education.

    As part of the CS 2013 curriculum committee that has been asking the question or what should a graduate in computer science look like we have talked a lot about soft skills and things like ethical behavior. While you don’t have to learn those things in college a good college education can go a long way towards helping people mature and become responsible adults.

    Can you learn a lot of computer science and software development on your own? Sure. Is that the way to bet? Not in my experience. There is so much more that can be learned and really needs to be learned to be a real professional. Going to school is the short cut and in the long run seems to pay off a lot better than going it alone. I’ve seen a lot of people over the years self teach the current technology but not have the background to keep growing as the technology changes and grows. Just how it looks from where I stand.



  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Dr Z’s Windows 8 How Tos

    • 1 Comments

    If you have downloaded and installed the new Windows 8 Consumer Preview you have noticed that is is different. In many ways very different from previous versions of Windows. Zhiming Xue aka Dr. Z has created a series of posts just for you. No matter if you are a beginner or a power user his posts will help you get started quickly with how to do the most common tasks in Windows 8. The series (to date) has 30 posts and I have listed them here with links to make it easy for you to find them.

    Windows 8 How To: 1. Switch Between Metro UI and Desktop Mode
    Windows 8 How To: 2. Switch Between Apps or Snap Apps
    Windows 8 How To: 3. How to Power Off Your Device
    Windows 8 How To: 4. Show and Access the Control Panel
    Windows 8 How To: 5. Show and Access Administrative Tools
    Windows 8 How To: 6. Show All Apps
    Windows 8 How To: 7. Switch Between Windows Accounts and Local Accounts
    Windows 8 How To: 8. Set up a Picture Password
    Windows 8 How To: 9. Set Up a Printer
    Windows 8 How To: 10. Customize Metro UI – App Tiles and Groups
    Windows 8 How To: 11. Install Language Packs for Multilingual Support
    Windows 8 How To: 12. Show and Use “Run” Command
    Windows 8 How To: 13. Show and Use cmd Prompt (DOS Mode)
    Windows 8 How To: 14. Show and Use PowerShell
    Windows 8 How To: 15. Show and Use Desktop Applications
    Windows 8 How To: 16. Install .NET 3.5 and Windows Live Essentials
    Windows 8 How To: 17. Add New Tab or New InPrivate Tab in Metro Style IE Browser
    Windows 8 How To: 18. Configure Wi-Fi Connection and Airplane Mode
    Windows 8 How To: 19. Show Hidden Files, Folders and Drives
    Windows 8 How To: 20. How to Start Windows 8 in Safe Mode
    Windows 8 How To: 21. Install and Uninstall Metro Style Apps
    Windows 8 How To: 22. Enable or Disable Sharing Between PCs Using Home Group
    Windows 8 How To: 23. Find and Use Windows Help and Support
    Windows 8 How To: 24. Show and Configure Free Anti-Virus App (Windows Defender)
    Windows 8 How To: 25. Show and Enable Split Touch Keyboard (On-Screen)
    Windows 8 How To: 26. Set up Remote Desktop Connection
    Windows 8 How To: 27. Backup your Files Using File History
    Windows 8 How To: 28. Restore Files Using File History
    Windows 8 How To: 29. Restore System to a Previous State Using Restore Point
    Windows 8 How To: 30. Restore your Device using Refresh and Reset



  • Computer Science Teacher - Thoughts and Information from Alfred Thompson

    Tic Tac Toe for Windows Phone

    • 6 Comments

    Introduction

    imageWe are going to create a simple Tic Tac Toe game for Windows Phone. We’ll be using Visual Studio as our development environment and C# for our programming language. All the resources you need are listed below and all are free.

     

    Resources:

    Windows Phone Development SDK

    VISUAL STUDIO 2010 EXPRESS FOR WINDOWS PHONE http://www.microsoft.com/visualstudio/en-us/products/2010-editions/windows-phone-developer-tools  or http://bit.ly/ymbC9Q  

    Windows Phone for Absolute Beginners video series http://channel9.msdn.com/Series/Windows-Phone-7-Development-for-Absolute-Beginners  or http://bit.ly/x72NnV  

    Alfred Thompson’s blog http://blogs.msdn.com/b/alfredth/  or http://bit.ly/AlfredTh 

    For a copy of this post in Word format, the images for the project, and code snippets used to create this lab download the PhoneTTT.zip file from https://skydrive.live.com/?cid=9a87f3a86cb0aa3e&id=9A87F3A86CB0AA3E%215413

    Open Visual Studio

    Find Visual Studio on the Start menu and open it up. It should look something like this.

    Next we will open a new project. From the File menu select New Project. From the New Project form select Visual C# as the language Silverlight for Windows Phone under that and Windows Phone Application as the application type. Make sure you give your project a name. Something like TicTacToe followed by your initials will do nicely (TicTacToeACT)

     

    image

    image

    We’ll be using the latest Windows Phone Version which is 7.1.

    image

    Our initial screen will look something like this.

    image

    We’ll come back to this in a minute.

    Add Image Resources

    We need to add some image files to the project. We will be adding images for an empty box , the letter O and the letter X.   Right click on the Solution in the Solution viewer and select Add > Existing Item. You can download them from here if you like.

    imageimageempty

     

     

    image

    Browse to where the files for the project are (should be on the Desktop) and select the three files we need and click on add.

    image

    Design Our Form

    Now let’s go back to designing our form on the mock up of the phone.  Left  click on where it says “page name” and select properties. The properties window will open up and we will change the Text property to Tic Tac Toe.

    imageimage

    Next we will use the Tool box and drag an Image onto the form.

    imageimage

    Using the properties form set the Height to 69, the width to 93 and the Source to the image file of the empty box. Use copy and paste to make a series of identical image boxes on the form. The results should look something like the image above.

    Add a tenth copy below the ninth copy. Next to that draw a Text Block. Change the Text property of the Text Block  to read “Next Move.” You may want to play with the font size property as well. The result will look something like this.

    image

    We’ll come back to this but now let us enter some code.

    Declare some variables

    Under MainPage.xaml on the Solution Explorer you will find MainPage.xaml.cs which hold our programming code. Double click on that to open the code editing window.

    image

    Above the constructor declare some variables that we will use to manage the game throughout the program.

    public partial class MainPage : PhoneApplicationPage
     {
     
     
         // Boolean variables to track whose move it is and if the game is over
         Boolean isX, GameOver;
         // An array to track the contents of each box (0 = empty 1 = X 2 = O)
         int[] boxValue;
         // Helpful images
         Image myXImage, myOimage, myEmptyImage;
         // Counting moves
         int MoveCount;
                 
         // Constructor
         public MainPage()

    Initialize Variables

    Inside the constructor we will set the initial values of our variables.

    Note that the resetBoxes method has not been created yet so the IDE gives us a warning. (The same sort of red squiggly live we are used to from Microsoft Word) Let’s correct that now. Also note that a common cause of problems is the wrong location in the Uri section. Change the “TicTacToe” in this sample code to match your project name.

    // Constructor
    public MainPage()
    {
        InitializeComponent();
     
     
        boxValue = new int[10];
        // STore the images for use in the game
        myXImage = new Image();
        myXImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/PhoneApp3;component/x.jpg", UriKind.RelativeOrAbsolute));
        myOimage = new Image();
        myOimage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/PhoneApp3;component/o.jpg", UriKind.RelativeOrAbsolute));
        myEmptyImage = new Image();
        myEmptyImage.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/PhoneApp3;component/empty.jpg", UriKind.RelativeOrAbsolute));
        // Set the initial state of the game board
        resetBoxes();
            
    }

    Create a Method to Set the Game Board

    Our method here will have to initialize some additional variables. We do it here so that we can reset them all in just one place when we start new games.

     
            // Set the initial state of the game board
            void resetBoxes()
            {
     
                GameOver = false;
                MoveCount = 0;
     
                isX = true;
                // Set all boxes to empty
                for (int i = 0; i < 10; i++)
                    boxValue[i] = 0;
                // Display empty images in all boxes on screen
                image1.Source = myEmptyImage.Source;
                image2.Source = myEmptyImage.Source;
                image3.Source = myEmptyImage.Source;
                image4.Source = myEmptyImage.Source;
                image5.Source = myEmptyImage.Source;
                image6.Source = myEmptyImage.Source;
                image7.Source = myEmptyImage.Source;
                image8.Source = myEmptyImage.Source;
                image9.Source = myEmptyImage.Source;
                GameOver = false;
                MoveCount = 0;
                textBlock1.Text = "Next Move ";
                image10.Source = myXImage.Source;
     
            }

    Respond to Taps

    We’ll play the game by tapping on individual boxes. For each tap we have to make sure it is a valid move (nothing in the box already), store and display the right symbol and check for a win or a tie. We’ll need a tab routine for each box but I’m only going to show one of them here. The rest is left as an exercise for the student. J

    As you can see this method calls several of the methods we have not yet created. Let’s get on that.

    // Respond to taps on all boxes.
    // For each box:
    // Check that it is empty and only act if it is
    // Call UpdateBox to record move and return which symbol to display
    // Check for a winner
    private void image9_Tap(System.Object sender, System.Windows.Input.GestureEventArgs e)
    {
        if (boxValue[9] == 0)
        {
            boxValue[9] = updateBox();
            if (boxValue[9] == 1)
            {
                image9.Source = myXImage.Source;
            }
            else
            {
                image9.Source = myOimage.Source;
            }
            if (IsWinner())
                endGame();
        }
    }

    Updating a Box

    // Count move and determine which player made the move.
    // Display the symbol for the next player to move
    public int updateBox()
    {
        if (GameOver)
            return 0;
        MoveCount = MoveCount + 1;
     
        if (isX)
        {
            isX = !isX;
            image10.Source = myOimage.Source;
            return 1;
        }
        else
        {
            isX = !isX;
            image10.Source = myXImage.Source;
            return 2;
        }
     
    }

    Checking for a Winner

    Checking for a winner means looking for three boxes in a row, column or diagonal that have the same value. Oh and it has to be the same not empty box value.

    Getting close now. Notice the call to TieGame? Let’s create that routine after we create the winning end of a game.

    // Determine if there is a winner by checking possible winning combinations
        private bool IsWinner()
        {
            bool HaveWinner = false;
            HaveWinner = false;
            if (boxValue[1] != 0 & boxValue[1] == boxValue[2] & boxValue[1] == boxValue[3])
                HaveWinner = true;
            if (boxValue[4] != 0 & boxValue[4] == boxValue[5] & boxValue[4] == boxValue[6])
                HaveWinner = true;
            if (boxValue[7] != 0 & boxValue[8] == boxValue[7] & boxValue[7] == boxValue[9])
                HaveWinner = true;
            if (boxValue[1] != 0 & boxValue[1] == boxValue[4] & boxValue[4] == boxValue[7])
                HaveWinner = true;
            if (boxValue[2] != 0 & boxValue[2] == boxValue[5] & boxValue[5] == boxValue[8])
                HaveWinner = true;
            if (boxValue[3] != 0 & boxValue[6] == boxValue[3] & boxValue[6] == boxValue[9])
                HaveWinner = true;
            if (boxValue[1] != 0 & boxValue[1] == boxValue[5] & boxValue[5] == boxValue[9])
                HaveWinner = true;
            if (boxValue[3] != 0 & boxValue[3] == boxValue[5] & boxValue[5] == boxValue[7])
                HaveWinner = true;
     
            if (HaveWinner == true)
                GameOver = true;
            // if there is no winner but we have taken 9 moves declare a draw (tie)
            if (MoveCount >= 9)
                TieGame();
            return HaveWinner;
        }

    Handling the End of a Game

    Here we have the two routines that show the end of a game. One for a winning game and one for a tie game.

    // Announce the winner
          public void endGame()
          {
              textBlock1.Text = "The Winner is";
              if (isX)
              {
                  image10.Source = myOimage.Source;
              }
              else
              {
                  image10.Source = myXImage.Source;
              }
          }
                  
     
          // Display tie game information
          public void TieGame()
          {
              image10.Source = myEmptyImage.Source;
              textBlock1.Text = "Tie Game";
     
          }

    We just have two more things to do. The first of those is that we have to “tell” the image boxes to call the tap routines when they are tapped. For this we go back to the design window.

    Assigning Tap Handlers

     

    Back on the property window you will find the Events tab. Selecting that and moving down we find an option for Tap.  Selecting each image one by one we can use the drop down list to set the right handler for each image box.

    image

    Starting a New Game

    All we need now is a way to start a new game. I suggest we tap on the Text Block to do that. Select the Text Block and in the properties window option for Tap enter New Game and press the enter key. This will open up the code window with a chance for use to call the ResetBoxes method we created.

    private void NewGame(object sender, GestureEventArgs e)
    {
        resetBoxes();
    }

    Testing

    Ok let’s run it and see how we did.



Page 1 of 8 (22 items) 12345»