S
S
Shugarsss2016-03-23 10:07:43
Algorithms
Shugarsss, 2016-03-23 10:07:43

How to iterate over all different moves in Tetris?

How can one efficiently iterate through all the moves in the Tetris of a particular piece? There is an input, all the final positions on the field that can be reached by turns and shifts.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
nirvimel, 2016-03-23
@nirvimel

The figure has 4 possible rotation positions. The number of different positions for each rotation is equal to the width of the field minus the width of the shape. For each different X position, there is only one Y end position. This Y value is the depth to which the shape falls, it is equal to the minimum of the depth values ​​that each point of the shape can fall to, and these values ​​are equal to the y(x) sums of the shape the bottom edge of the shape and y(x) the shape of the top edge of the "garbage" lying on the field.

Z
zorgrhrd, 2015-01-29
@zogrhrd

I'm sorry, I've been banging my head against the wall for two days in an attempt to understand why it doesn't work, it turns out I was looking in the wrong place, the fact is that the buffer first accumulated, and then after the stream closed, it immediately gave the output to the loop and the progressbar was lightning fast scored 100%. Those. there are no problems with updating the bar, it was in the buffer itself, I rewrote the method:

private void runCmdWithProgress(String... args) throws IOException {
        Process proc = Runtime.getRuntime().exec(args);
        InputStream inputStream = proc.getErrorStream();
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String s = null;

        while ((s = bufferedReader.readLine()) != null) {
                Double progress = Double.parseDouble(s.split("%")[0]) / 100;
                Platform.runLater(() -> tab_adb_progressbar.setProgress(progress));
        }
        try {
            proc.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

Plus to Alexander's answer, yes, this method from the GUI thread must be called in a separate one, I do the same as you:
new Thread(() -> {
                          try {
                              runCmdWithProgress(commands);
                              Platform.runLater(() ->  showDialogInformation(positive);
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      }).start();

Thanks to all!

A
Alexander Plotnikov, 2015-01-28
@alexplot

When your application has work that takes a long time to complete, like your loops, it stops the UI from updating in general. For your code to work, it needs to be run on a separate thread, and since JavaFX is not multi-threaded, operations like setProgress(double v) must be returned back to the application's main thread by the Platform.runLater() method.
And it seems to me that it is not correct to use Swing classes to work with JavaFX.

N
Nikolai Turnaviotov, 2015-01-28
@foxmuldercp

in c# I do it like this:
a background task in the background that does something for a long time, let's say in a loop.
in the loop there is a call to the function report.progress(int someint)
on the function report.progress(int bla) there is a code that can interact with the gui and update the progress bar counter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question