// Program Name:                 MOIRun.java
// Course:                       CSE 1302J
// Student Name:                 Bradley Shedd
// Assignment Number:            Project#2
// Due Date:                     10/04/2010
// Purpose:                      This program creates an island with two bridges
//     and a mouse shown. A view of the 10x10 board showing
//  the location of the mouse(1) is displayed before 
//  each round. The board represents an island with two
//   bridges (99) leading off the island. The island (0's) is
//     surrounded by water(-1).The mouse gets 20 random moves
//  and can only go up(1), down(2),left(3) or right(4). If he
//    hits (-1) he drowns and if the mouse wanders around, he  
//    starves. The only way to escape the island is to land on 
//   (99), but the mouse can't backtrack the previous move.
   import java.io.*;
  
import java.util.Scanner;
  
   
public class MOIRun
   {
      
public static void main(String[] args)throws IOException
      {
         System.setIn(
new FileInputStream("input.txt"));
         Scanner scan =
new Scanner(System.in);
       
int[][] rnd1 = new int[10][10];
        
int[][] rnd2 = new int[10][10];
        
int[][] rnd3 = new int[10][10];
        
int[][] rnd4 = new int[10][10];
         
int[][] rnd5 = new int[10][10];
           
        
for (int i = 0; i < rnd1.length; i++)
         {
           
for (int j = 0; j < rnd1[i].length; j++)
            {
               rnd1[i][j] = scan.nextInt();
               rnd2[i][j] = rnd1[i][j];
               rnd3[i][j] = rnd1[i][j];
               rnd4[i][j] = rnd1[i][j];
              rnd5[i][j] = rnd1[i][j];
            }
         }
     
         System.out.println(
"");
           
       
// System.out.println("_________________________________________________" +
         //                "\n>>>>>>>>>>>>>>>>>>>>[Round 1]<<<<<<<<<<<<<<<<<<<<");
         MouseOnIsland i1 = new MouseOnIsland(rnd1);
         i1.randomStart();
         i1.randomBridge();
         i1.printList();
         i1.MouseMov();
       
// System.out.println("_________________________________________________");
         i1.printList();
       
// System.out.println("_________________________________________________" +
        //                 "\n>>>>>>>>>>>>>>>>>>>>[Round 2]<<<<<<<<<<<<<<<<<<<<");
         MouseOnIsland i2 = new MouseOnIsland(rnd2);
         i2.randomStart();
         i2.randomBridge();
         i2.printList();
         i2.MouseMov();
       
// System.out.println("_________________________________________________");
         i2.printList();
      
//  System.out.println("_________________________________________________" +
       //                  "\n>>>>>>>>>>>>>>>>>>>>[Round 3]<<<<<<<<<<<<<<<<<<<<");
         MouseOnIsland i3 = new MouseOnIsland(rnd3);
         i3.randomStart();
         i3.randomBridge();
         i3.printList();
         i3.MouseMov();
      
//  System.out.println("_________________________________________________");
         i3.printList();
       
// System.out.println("_________________________________________________" +
        //                 "\n>>>>>>>>>>>>>>>>>>>>[Round 4]<<<<<<<<<<<<<<<<<<<<");
         MouseOnIsland i4 = new MouseOnIsland(rnd4);
         i4.randomStart();
         i4.randomBridge();
         i4.printList();
         i4.MouseMov();
       
// System.out.println("_________________________________________________");
         i4.printList();
       
// System.out.println("_________________________________________________" +
        //                 "\n>>>>>>>>>>>>>>>>>>>>[Round 5]<<<<<<<<<<<<<<<<<<<<");
         MouseOnIsland i5 = new MouseOnIsland(rnd5);
         i5.randomStart();
         i5.randomBridge();
         i5.printList();
         i5.MouseMov();
      
//  System.out.println("_________________________________________________");
         i5.printList();
     
//   System.out.println("_________________________________________________");
     
         System.out.print(
"The mouse drowned ");
         System.out.print(i1.getDC()+i2.getDC()+i3.getDC()+
            i4.getDC()+i5.getDC());
         System.out.print(
" time(s)\nThe mouse starved ");
         System.out.print(i1.getSC()+i2.getSC()+i3.getSC()+
            i4.getSC()+i5.getSC());
         System.out.print(
" time(s)\nThe mouse escaped ");
         System.out.print(i1.getEC()+i2.getEC()+i3.getEC()+i4.getEC()+
            i5.getEC()+
" time(s)\n\nProgram coded by Bradley J. Shedd");
      }
   }

Type the text below into a text file named input.txt Save it in the same location as the code.

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 0 0 0 0 0 0 0 0 -1
-1 0 0 0 0 0 0 0 0 -1
-1 0 0 0 0 0 0 0 0 -1
-1 0 0 0 0 0 0 0 0 -1
-1 0 0 0 0 0 0 0 0 -1
-1 0 0 0 0 0 0 0 0 -1
-1 0 0 0 0 0 0 0 0 -1
-1 0 0 0 0 0 0 0 0 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

 

Homepage