[Commit] RRbot SolutionChecker.java,NONE,1.1 Ricochet.java,1.1.1.1,1.2

Adam Ingram-Goble commit at keithp.com
Mon Jun 9 01:35:26 PDT 2003


Committed by: adamaig

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

Modified Files:
	Ricochet.java 
Added Files:
	SolutionChecker.java 
Log Message:


--- NEW FILE: SolutionChecker.java ---

import java.io.*;
import java.util.*;

/** A solution checker for RRbot.Ricochet
 */
public class SolutionChecker {

    private static PrintStream out = System.out;

    public static void usage() {
        out.println( "java SolutionChecker <game file> <solution>" );
    }

    public static void main( String[] args ) {

        int goalRow = 0;
        int goalCol = 0;
        int goalRotation = 0;
        Board board = new Board();
        Robot[] robots = new Robot[4];

        if( args.length != 2 ) {
            usage();
            System.exit( 1 );
        }

        BufferedReader br = null;
        try {
            br = new BufferedReader( new FileReader( args[ 0 ] ) ); 

            StringTokenizer st;
            String lineStr;
            int row, col, rot;
            int numCommentLines = 0;
            int robotNum = 0;
            int sideBlockers = 0;
            boolean goalPlaced = false;

            while ( (lineStr = br.readLine()) != null ) {
                if ( lineStr.charAt( 0 )  != '#' ) {
                    st = new StringTokenizer( lineStr ); 
                    row = Integer.parseInt( st.nextToken() ); 
                    col = Integer.parseInt( st.nextToken() ); 

                    if ( numCommentLines >= 4 ) {
                        robots[robotNum] = new Robot ( row, col );
                        board.placeRobot( row, col, robotNum++ );
                    } else if ( numCommentLines >= 3 ) {
                        board.addBlocker( row, col, 0 );
                    } else if ( numCommentLines >= 2 ) {
                        rot = Integer.parseInt( st.nextToken() ); 
                        board.addBlocker( row, col, rot );
                        if ( goalPlaced == false ) {
                            board.placeGoal ( row, col );
                            goalPlaced = true;
                            goalRotation = rot;
                            goalRow = row;
                            goalCol = col;
                        }
                    }
                } else {
                    numCommentLines++;
                }
            } 
        } catch ( IOException ioe ) {
            System.out.println( "Input Error" + ioe );
        }


        out.println( board.toString() );
        out.println( "Performing moves : " + args[ 1 ] );
        for( int idx = 0; idx < args[ 1 ].length(); idx += 3 ) {
            if( board.makeMove( robots[ args[ 1 ].charAt( idx ) - '0' ],
                        Integer.parseInt( 
                            args[ 1 ].substring( idx + 1, idx + 2 ) ) ) != 1 ) {
                out.println( "Bad move: " + args[ 1 ].charAt( idx )
                        + args[ 1 ].charAt( idx + 1 ) );
                System.exit( 1 );
            }
            out.println( board.toString() );
        }

        if( robots[ 0 ].rpos() == goalRow && robots[ 0 ].cpos() == goalCol ) {
            out.println( "IS A SOLUTION" );
        }
    }
}


Index: Ricochet.java
===================================================================
RCS file: /local/src/CVS/RRbot/Ricochet.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- Ricochet.java	9 Jun 2003 02:43:58 -0000	1.1.1.1
+++ Ricochet.java	9 Jun 2003 07:35:24 -0000	1.2
@@ -94,7 +94,6 @@
       cprime = INFINITY;
 
       while ( IDAstar() == 1 );
-
     }
 
   }
@@ -190,6 +189,7 @@
           System.out.println();
           System.out.println( "in " + newMoves.length() / 2 + " moves" );
           System.out.println( solToRRstr( newMoves ));
+
           System.exit(1);
         }
 
@@ -233,14 +233,12 @@
             stopT.put( zkey, newNode );
         }
 
-
         if ( (g + h) <= c ) {
           nodeStack.push ( newNode );
         } else if ( cprime > (g + h) ) {
           cprime = g + h;
         }
  
-
         g--;
 
         // undo the move
@@ -328,10 +326,7 @@
                   break;
       }
       RRsolution += " ";
-
     }
-
-
     return RRsolution;
   }
 
@@ -481,6 +476,4 @@
 
     return;
   }
-
-
 }




More information about the Commit mailing list