<commit_before>package ru.job4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.ReentrantLock;

import static java.util.concurrent.TimeUnit.MILLISECONDS;

/**.
 * Task 7.6.2.
 * Create game Bomberman
 *
 * @author <NAME> on 04.09.2017
 * @version 1.0.
 */

public class Board {

    /**.
     * @SIZEBOARD is max size the board
     */
    private static final int SIZEBOARD = 10;

    /**.
     * @board is link for our board
     */
    private final ReentrantLock[][] board;

    /**.
     * @bomber is our main figure
     */
    private final Player bomber;

    /**.
     * @endGame is flag for end game
     */
    private boolean endGame = true;

    /**.
     * Constructor for this class
     */
    public Board() {
        board = new ReentrantLock[SIZEBOARD][SIZEBOARD];
        for(int i = 0; i < SIZEBOARD; i++) {
            for (int j = 0; j < SIZEBOARD; j++) {
                board[i][j] = new ReentrantLock();
            }
        }
        bomber = new Player("Gosha", 1, SIZEBOARD);
    }

    /**.
     * Main action for this game
     */
    public void action() {
        ExecutorService exec = Executors.newFixedThreadPool(1);
        exec.submit(new Runnable() {
            @Override
            public void run() {
                boolean flag;
                int[] oldPlace;
                while (endGame) {
                    flag = false;
                    while (!flag) {
                        int[] step = bomber.step();
                        try {
                            if (board[step[0]][step[1]].tryLock(500, MILLISECONDS)) {
                                flag = true;
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } finally {
                            oldPlace = bomber.getPlace();
                            board[oldPlace[0]][oldPlace[1]].unlock();
                        }
                        bomber.newPlace(step[0], step[1]);
                        System.out.println(bomber);
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

    /**.
     * Set flag endGame
     */
    public void setEndGame() {
        this.endGame = true;
    }
}<commit_msg>add file for chapter_004_7.6.2<commit_after>package ru.job4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.ReentrantLock;

import static java.util.concurrent.TimeUnit.MILLISECONDS;

/**.
 * Task 7.6.2.
 * Create game Bomberman
 *
 * @author <NAME> on 04.09.2017
 * @version 1.0.
 */

public class Board {

    /**.
     * @SIZEBOARD is max size the board
     */
    private static final int SIZEBOARD = 10;

    /**.
     * @board is link for our board
     */
    private final ReentrantLock[][] board;

    /**.
     * @bomber is our main figure
     */
    private final Player bomber;

    /**.
     * @endGame is flag for end game
     */
    private boolean endGame = true;

    /**.
     * Constructor for this class
     */
    public Board() {
        board = new ReentrantLock[SIZEBOARD][SIZEBOARD];
        for(int i = 0; i < SIZEBOARD; i++) {
            for (int j = 0; j < SIZEBOARD; j++) {
                board[i][j] = new ReentrantLock();
            }
        }
        bomber = new Player("Gosha", 1, SIZEBOARD);
    }

    /**.
     * Main action for this game
     */
    public void action() {
        ExecutorService exec = Executors.newFixedThreadPool(1);
        exec.submit(new Runnable() {
            @Override
            public void run() {
                boolean flag;
                int[] oldPlace;
                while (endGame) {
                    flag = false;
                    while (!flag) {
                        int[] step = bomber.step();
                        try {
                            if (board[step[0]][step[1]].tryLock(500, MILLISECONDS)) {
                                flag = true;
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } finally {
                            oldPlace = bomber.getPlace();
                            board[oldPlace[0]][oldPlace[1]].unlock();
                        }
                        bomber.newPlace(step[0], step[1]);
                        System.out.println(bomber);
                    }
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }

    /**.
     * Set flag endGame
     */
    public void setEndGame() {
        this.endGame = false;
    }
}
{'fraction_non_alphanumeric': 0.11190193752471332, 'fraction_numerical': 0.014234875444839857, 'mean_word_length': 1.180603448275862, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '132977', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1356, 'n_words': 317}