protected void play() throws Exception {

        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));

        tick = 0;

        printConfig();
        printStep();

        for (tick = 1; tick <= MAX_TICKS; tick++) {
            // step by step trace
            if (trace) {
                try {
                    System.err.print("$");
                    buffer.readLine();
                } catch (Exception e) {}
            }

            // Make a copy of current status
            Parking[] lcopy = copyList(left);
            Parking[] rcopy = copyList(right);
            MovingCar[] movingcopy = movingCars.toArray(new MovingCar[0]);
            // Let the player set the lights
            player.setLights(movingcopy, lcopy, rcopy, llights, rlights);
            
            printLights(llights, rlights);

            // simulate one step
            boolean success = playStep(llights, rlights, tick);
            // does simulation succeed?
            if (!success)
                break;

            printStep();

            // does game end?
            if (deliveredCars == cars.size())
                break;
        }

        if (cars.size() != deliveredCars)
            System.err.println("Player fails to deliver all the cars.");
        else
            System.err.println("Player finishes with penalty: " + penalty);
    }