Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
Programming Challenge Archive

Shapes World
AlienChessman
 
 

 
  JavaApplication  -- Alien Chessman

   
   // General Information
   // ---------------------------------------------------
  
   // File:  AlienChessmanApp.java
   // Type:  java application file
   // Date:  Wed Oct 4, 2000
   // Name:  Byron Bahr
   // Line:  Calculate the Tour of the Alien Chessman
  
   // Application Description
   // ---------------------------------------------------
  
   /*
      This program calculates the tour path of an 
      alien Chessman on a Chessboard. 
   */
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
      import blue.math.*;
      import blue.shapes.*;
  
   // Application Class
   // ---------------------------------------------------
  
      class AlienChessmanApp
      {
         static public void main (String args[])
         {
         // Define the Given Information
             double boardSide = 19.6;
             int nrSquaresSide = 8;
             double squareSide = boardSide/8;
  
         // Model the Board Squares
             int squareA = 1;
             int squareB = 2;
             int squareC = 3;
             int squareD = 4;
             int squareE = 5;
             int squareF = 6;
             int squareG = 7;
             int squareH = 8;
             int square1 = 1;
             int square2 = 2;
             int square3 = 3;
             int square4 = 4;
             int square5 = 5;
             int square6 = 6;
             int square7 = 7;
             int square8 = 8;
      
         // Model Path Using Helper Rectangles 
         // Model Path A1 to E4  
             Rectangle rA1E4 = new Rectangle 
               (((squareE - squareA)*squareSide),
               ((square4 - square1)*squareSide));
             double pA1E4 = rA1E4.diagonal();
  
         // Model Path E4 to G3
             Rectangle rE4G3 = new Rectangle 
               ((squareG - squareE)*squareSide,
                (square4 - square3)*squareSide);
             double pE4G3 = rE4G3.diagonal();
  
         // Model Path G3 to H8  
             Rectangle rG3H8 = new Rectangle 
               ((squareH - squareG)* squareSide,
                (square8 - square3)* squareSide);
             double pG3H8 = rG3H8.diagonal();
  
         // Model Path H8 to B5  
             Rectangle rH8B5 = new Rectangle 
               ((squareH - squareB)* squareSide,
                (square8 - square5)* squareSide);
             double pH8B5 = rH8B5.diagonal();
  
         // Model Path B5 to A1  
             Rectangle rB5A1 = new Rectangle 
               ((squareB - squareA)* squareSide,
                (square5 - square1)* squareSide);
             double pB5A1 = rB5A1.diagonal();
  
         // Total the Path Steps of the Alien Chessman
             double pathLength = 
       (pA1E4 + pE4G3 + pG3H8 + pH8B5 + pB5A1);
  
         // Display the Path on the Alien Chessboard
             IO.print ("The distance traveled is ");
             IO.print (pathLength);
             IO.println (" inches");
         }
      }
  
   // Demo
   // ---------------------------------------------------
  
   /*
      The distance traveled is 56.75767277056354 inches
   */