[Commit] RRbot Board.java,1.1.1.1,1.2 Col.java,1.1.1.1,1.2 Node.java,1.2,1.3 RicochetRecursive.java,1.8,1.9 Robot.java,1.1.1.1,1.2 Row.java,1.1.1.1,1.2 SolutionChecker.java,1.1,1.2 TranspositionTable.java,1.1.1.1,1.2

Christian L. Platt commit at keithp.com
Thu Jun 12 16:25:26 PDT 2003


Committed by: plattc

Update of /local/src/CVS/RRbot
In directory home.keithp.com:/tmp/cvs-serv19403

Modified Files:
	Board.java Col.java Node.java RicochetRecursive.java 
	Robot.java Row.java SolutionChecker.java 
	TranspositionTable.java 
Log Message:
Last minute cleaning up.


Index: Board.java
===================================================================
RCS file: /local/src/CVS/RRbot/Board.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- Board.java	9 Jun 2003 02:43:58 -0000	1.1.1.1
+++ Board.java	12 Jun 2003 22:25:23 -0000	1.2
@@ -1,13 +1,8 @@
 /* Board.java
 **
-** Christian Platt
-** CS543 - HW2
-** 4/15/03
-**
+** Christian Platt, Adam Ingram-Goble
+** CS543 - Ricochet Robots Player
 **
-** uses: Row.java
-**       Col.java
-**       Robot.java
 **
 */
 
@@ -21,7 +16,9 @@
 public class Board {
   Row rows[];
   Col cols[];
-  char [][] squares;
+  char [][] squares;    // this array is only used for displaying the board
+                        // we can get rid of all the code that involves them
+                        // if we don't want to output the board.
   int goalRow;
   int goalCol;
 
@@ -73,8 +70,9 @@
   }
 
 
+  //used to see if there is a straight path from pos1 to pos2.  If there
+  //is this function returns 1 otherwise returns INFINITY
   public int calcEdge ( int row1, int col1, int row2, int col2 ) {
-
     if ( row1 == row2 ) {
       // see if there is a blocker in between
       if ( col1 < col2 ) {
@@ -105,16 +103,11 @@
   }
 
 
-  // CAN GET RID OF ALL SQUARES STUFF FOR FINAL PRODUCT!!!
-  // MAYBE ADJUST THESE MOVES SO THAT WE ARE ONLY MODIFYING A ROW WHEN
-  // MOVING THE ROBOT LEFT OR RIGHT
-  // case 0,2 and 1,3 can be combined since they are the same
+  // Returns 1 if the move can be made otherwise it returns 0.
   public int makeMove ( Robot rbot, int dir ) {
     int newPos;
     char robNum;   // just used for displaying board
 
-    //System.out.println( rbot.rpos() + " " + rbot.cpos() + " " + dir  );
-
     switch ( dir ) {
       // Up
       case 0: if((newPos=cols[rbot.cpos()].newPosition(rbot.rpos(),dir)) != -1){
@@ -181,10 +174,8 @@
   public void takeBackMove ( Robot rbot, int oldRow, int oldCol
                                        , int curRow, int curCol ) {
     rbot.move ( oldRow, oldCol );    
-    // Just for debugging
     char tempRobNum = squares[curRow][curCol];
 
-
     cols[curCol].removeRobot( curRow );
     cols[oldCol].addRobot( oldRow );
     rows[curRow].removeRobot( curCol );
@@ -298,6 +289,4 @@
   }
   
 }
-
-
 

Index: Col.java
===================================================================
RCS file: /local/src/CVS/RRbot/Col.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- Col.java	9 Jun 2003 02:43:58 -0000	1.1.1.1
+++ Col.java	12 Jun 2003 22:25:23 -0000	1.2
@@ -1,10 +1,7 @@
 /* Col.java
 **
-** Christian Platt
-** CS543 
-**
-**
-** uses: 
+** Christian Platt, Adam Ingram-Goble
+** CS543 - Ricochet Robots Player
 **
 **
 ** positions 0 = empty
@@ -13,6 +10,9 @@
 **           3 = robot + blocker
 **           4 = robot + robot
 **           5 = robot + robot + blocker
+**
+** A col is made up of 17 edges (vs. 16 squares) where each position represents
+** what's on that edge.
 */
 
 
@@ -42,7 +42,6 @@
     switch ( dir ) {
 
       // Up
-      //case 0: for (i=oldPos-1; i >= 0; i-- ) {
       case 0: for (i=oldPos; i >= 0; i-- ) {
                 if ( positions[i] != 0 &&
                      positions[i] != 2 &&

Index: Node.java
===================================================================
RCS file: /local/src/CVS/RRbot/Node.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Node.java	10 Jun 2003 06:03:19 -0000	1.2
+++ Node.java	12 Jun 2003 22:25:23 -0000	1.3
@@ -1,13 +1,9 @@
 /* Node.java
 **
-** Christian Platt
-** CS543 - HW2
-** 4/15/03
-**
-**
-** uses: 
-**
+** Christian Platt, Adam Ingram-Goble
+** CS543 - Ricochet Robots Player
 **
+** Stores current game state.
 */
 
 
@@ -15,15 +11,13 @@
 import java.lang.*;
 import java.util.*;
 
-
+// stores robot positions
 class Rob {
   public int row;
   public int col;
 }
 
 
-//public class Node implements Comparable, Comparator {
-//public class Node implements Comparator {
 public class Node {
   public int g;
   public int h;
@@ -49,24 +43,20 @@
     }
   }
 
- 
   public void placeRobot ( int num, int r, int c ) {
-    //System.out.println( num + " " + r + " " + c );
     robotLocations[num].row =  r;
     robotLocations[num].col =  c;
-
-    //System.out.println( robotLocations[num].row + " " + robotLocations[num].col );
   }
 
-    public boolean equals( Node n ) {
-        for( int idx = 0; idx < 4; ++idx ) {
-            if( ! ( this.robotLocations[ idx ].row 
-                        == n.robotLocations[ idx ].row
-                    && this.robotLocations[ idx ].col 
-                        == n.robotLocations[ idx ].col ) ) {
-                return false;
-            }
-        }
-        return true;
+  public boolean equals( Node n ) {
+    for( int idx = 0; idx < 4; ++idx ) {
+      if( ! ( this.robotLocations[ idx ].row 
+                      == n.robotLocations[ idx ].row
+                 && this.robotLocations[ idx ].col 
+                      == n.robotLocations[ idx ].col ) ) {
+        return false;
+      }
     }
+    return true;
+  }
 }

Index: RicochetRecursive.java
===================================================================
RCS file: /local/src/CVS/RRbot/RicochetRecursive.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- RicochetRecursive.java	10 Jun 2003 18:56:44 -0000	1.8
+++ RicochetRecursive.java	12 Jun 2003 22:25:23 -0000	1.9
@@ -1,11 +1,9 @@
 /* RicochetRecursive.java
  **
  ** Christian Platt, Adam Ingram-Goble
- ** CS543 
- **
- **
- ** uses: 
+ ** CS543 - Ricochet Robots Player
  **
+ ** Recursive version of IDA*
  */
 
 
@@ -40,7 +38,8 @@
     public static long totalNodes = 0;
     public static long prunedNodes = 0;
     public static long removedNodes = 0;
-    
+   
+ 
     public static void main ( String args[] ) {
         board = new Board();
         robots = new Robot[4];
@@ -50,16 +49,11 @@
 
         int numArgs = args.length;
         if ( args.length != 0 ) {
-            //parseArgs ( args );
             readInBoard( args[0] );
         } else {
             getData();
         }
 
-        //readInBoard();
-        System.out.println( board.toString() );
-        //System.exit(1);
-
         calcAllPairsShortestPath();
 
         Node n = new Node( 0, 0, "" );
@@ -79,24 +73,30 @@
             n.placeRobot( i, robots[i].rposOrig, robots[i].cposOrig );
         }
 
+        //IDA*
         for( int idx = 1; idx < 12; ++idx ) {
             if( 0 != IDAstar( 0, idx, n ) ) {
                 break;
             }
+            /*
             System.out.println( "Nodes searched = " + totalNodes 
                     + "\tstopT size = " + stopT.size() 
                     + "\tprunedNodes = " + prunedNodes 
                     + "\tremovedNodes = " + removedNodes );
+            */
 
             prunedNodes = removedNodes = 0;
             stopT.clear();
         }
+            /*
             System.out.println( "Nodes searched = " + totalNodes 
                     + "\tstopT size = " + stopT.size() 
                     + "\tprunedNodes = " + prunedNodes 
                     + "\tremovedNodes = " + removedNodes );
+            */
     }
 
+
     // main search function
     public static int IDAstar ( int curDepth, int maxDepth, Node curNode ) {
 
@@ -106,6 +106,7 @@
         curDepth++;
         int g = curDepth + 1;
         int h = 0;
+
         //generate all possible moves
         for ( int i = 0; i < 4; i++ ) {
             for ( int j = 0; j < 4; j++ ) {
@@ -120,6 +121,7 @@
                 }
                 totalNodes++;
                 //add move to move string
+
                 String newMoves = new String( curNode.moves );
                 newMoves += i + "" +  j;
                 // convert grid coordinates to matrix coordinates
@@ -128,10 +130,10 @@
                 if ( robMatrixPos == goalMatrixPos ) {
                     solutionFound( newMoves );
                 }
+
                 //calculate h for new node
                 h = (int) (1.3 * distMatrix[robMatrixPos][goalMatrixPos]);
 
-
                 if ( g + h > maxDepth ) {
                     board.takeBackMove ( robots[i], oldRow, oldCol, robots[i].rpos()
                             , robots[i].cpos() );
@@ -179,6 +181,7 @@
         return 0;
     }
 
+
     public static void solutionFound( String newMoves ) {
         System.out.println( "SOLUTION" );
         String testString = "";
@@ -191,11 +194,13 @@
             testString += newMoves.charAt( c );
         }
         System.out.println();
+        /*
         System.out.println( "in " + newMoves.length() / 2 + " moves" );
             System.out.println( "Nodes searched = " + totalNodes 
                     + "\tstopT size = " + stopT.size() 
                     + "\tprunedNodes = " + prunedNodes 
                     + "\tremovedNodes = " + removedNodes );
+        */
         System.out.println( solToRRstr( newMoves ));
        /* 
            String[] chckArgs = { "game2.gm", testString };
@@ -204,6 +209,7 @@
         System.exit(1);
     }
 
+
     public static void calcAllPairsShortestPath ( ) {
         costMatrix = new int [256][256];
         distMatrix = new int [256][256];
@@ -423,20 +429,6 @@
 
         } catch ( IOException ioe ) {
             System.out.println( "Input Error" + ioe );
-        }
-
-        return;
-    }
-
-
-    // Parses the optional command line arguments
-    public static void parseArgs ( String args[] ) {
-        int numArgs = args.length;
-        boolean err = false;
-
-        if ( err ) {
-            System.out.println( "Invalid usage." );
-            System.exit(1);
         }
 
         return;

Index: Robot.java
===================================================================
RCS file: /local/src/CVS/RRbot/Robot.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- Robot.java	9 Jun 2003 02:43:58 -0000	1.1.1.1
+++ Robot.java	12 Jun 2003 22:25:23 -0000	1.2
@@ -1,10 +1,8 @@
 /* Robot.java
 **
-** Christian Platt
-** CS543 
-**
+** Christian Platt, Adam Ingram-Goble
+** CS543 - Ricochet Robots Player
 **
-** uses: 
 **
 */
 
@@ -23,13 +21,13 @@
   public String color;
 
   //Constructor
-  public Robot( int r, int c, char co ){
+  public Robot( int r, int c, char col ){
     rpos = r;
     cpos = c;
     rposOrig = r;
     cposOrig = c;
 
-    switch ( co ) {
+    switch ( col ) {
       case 'r':
       case 'R': color = "red";
                 break;
@@ -48,6 +46,8 @@
     }
         
   }
+
+  // Constructor
   public Robot( int r, int c ){
     rpos = r;
     cpos = c;
@@ -67,7 +67,4 @@
   public int cpos ( ){
     return cpos;
   }
-
-
-  
 }

Index: Row.java
===================================================================
RCS file: /local/src/CVS/RRbot/Row.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- Row.java	9 Jun 2003 02:43:58 -0000	1.1.1.1
+++ Row.java	12 Jun 2003 22:25:23 -0000	1.2
@@ -1,10 +1,8 @@
 /* Row.java
 **
-** Christian Platt
-** CS543 
-**
+** Christian Platt, Adam Ingram-Goble
+** CS543 - Ricochet Robots Player
 **
-** uses: 
 **
 **
 ** positions 0 = empty
@@ -13,6 +11,10 @@
 **           3 = robot + blocker
 **           4 = robot + robot
 **           5 = robot + robot + blocker
+**
+** A row is made up of 17 edges (vs. 16 squares) where each position represents
+** what's on that edge.
+** 
 */
 
 
@@ -59,7 +61,6 @@
               break;
 
       // Left
-      //case 3: for ( i=oldPos-1; i >= 0; i-- ) {
       case 3: for ( i=oldPos; i >= 0; i-- ) {
                 if ( positions[i] != 0 &&
                      positions[i] != 2 &&
@@ -103,7 +104,6 @@
               break;
 
       // Left
-      //case 3: for ( i=oldPos-1; i >= 0; i-- ) {
       case 3: for ( i=oldPos; i >= 0; i-- ) {
                 if ( positions[i] != 0 ) {
                   if ( i == oldPos && positions[i] == 2 ) {

Index: SolutionChecker.java
===================================================================
RCS file: /local/src/CVS/RRbot/SolutionChecker.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- SolutionChecker.java	9 Jun 2003 07:35:24 -0000	1.1
+++ SolutionChecker.java	12 Jun 2003 22:25:23 -0000	1.2
@@ -1,3 +1,16 @@
+/* SolutionChecker.java
+**
+** Christian Platt, Adam Ingram-Goble
+** CS543 - Ricochet Robots Player
+**
+** This program is used to verify a solution is valid.  It is fed a
+** game file and solution string
+** 
+*/
+
+
+
+
 
 import java.io.*;
 import java.util.*;

Index: TranspositionTable.java
===================================================================
RCS file: /local/src/CVS/RRbot/TranspositionTable.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- TranspositionTable.java	9 Jun 2003 02:43:58 -0000	1.1.1.1
+++ TranspositionTable.java	12 Jun 2003 22:25:23 -0000	1.2
@@ -1,3 +1,11 @@
+/* TranspositionTable.java
+**
+** Christian Platt, Adam Ingram-Goble
+** CS543 - Ricochet Robots Player
+**
+**
+*/
+
 
 import java.util.*;
 




More information about the Commit mailing list