<commit_before>export const PLAY_TILE = 'PLAY_TILE';
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER';

export function playTile(position) {
    return {
        type: PLAY_TILE,
        position
    };
}

//export function playTile(position: number) {
//    return (dispatch, getState) => {
//        const { tiles } = getState();
//
//        if (counter % 2 === 0) {
//            return;
//        }
//
//        dispatch(increment());
//    };
//}<commit_msg>Implemented proper playTile with check if it's a neighbor of the empty tile<commit_after>import { COLS } from '../constants/Board'
export const PLAY_TILE = 'PLAY_TILE'
export const DECREMENT_COUNTER = 'DECREMENT_COUNTER'

export function playTile(position: number) {
    return (dispatch, getState) => {
        const { tiles } = getState()
        const emptyTile = tiles.find(tile => tile.type === -1)
        const emptyPos = tiles.indexOf(emptyTile)
        const delta = Math.abs(position - emptyPos)

        if (delta === 1 || delta === COLS) {
            if (emptyPos % COLS === 0 && position === (emptyPos - 1)) {
                return // Empty is in last row. Next tile can not be played
            }  else if ((emptyPos + 1) % COLS === 0 && position === (emptyPos + 1)) {
                return // Empty is in first row. Previous tile can not be played
            }
            dispatch({
                type: PLAY_TILE,
                position
            });
        }

        return
    };
}
{'fraction_non_alphanumeric': 0.12905405405405404, 'fraction_numerical': 0.006081081081081081, 'mean_word_length': 1.9858870967741935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '2717524', 'n_tokens_mistral': 445, 'n_tokens_neox': 422, 'n_words': 127}