<commit_before>import { createSelector } from 'reselect';

const getTiles = (state) => state.tiles;
const getTile = (state, props) => state.tiles[props.id];
const getTurn = (state) => state.turn;
const getMoveCount = (state) => state.moveCount;
const getDraggedTileId = (state) => state.draggedTileId;
const getX = (state, props) => props.x;
const getY = (state, props) => props.y;

const getUnusedColorTiles = (color) => createSelector(
  [getTiles],
  (tiles) => {
    let colorTiles = [];
    Object.keys(tiles).forEach((id) => {
      let tile = tiles[id];
      if (typeof tile.x !== 'number' || typeof tile.y !== 'number') {
        if (tile.color === color) {
          colorTiles.push(tile);
        }
      }
    });
    return colorTiles;
  }
);

function listAdjancentPositions(x, y) {
  let positions = [
    {x: x + 1, y: y},
    {x: x - 1, y: y},
    {x: x, y: y + 1},
    {x: x, y: y - 1}
  ];

  if (x % 2) {
    positions.push({x: x + 1, y: y + 1});
    positions.push({x: x - 1, y: y + 1});
  } else {
    positions.push({x: x + 1, y: y - 1});
    positions.push({x: x - 1, y: y - 1});
  }
  return positions;
}

export const canDropTile = createSelector(
  [getTiles, getMoveCount, getDraggedTileId, getX, getY],
  (tiles, moveCount, draggedTileId, x, y) => {
    if (moveCount === 0)
      return true;
    return listAdjancentPositions(x, y).some(pos => {
      return Object.keys(tiles).some(id => {
        let tile = tiles[id];
        if (tile.x === pos.x && tile.y === pos.y) {
          return true;
        }
      });
    });
  }
);

export const canDragTile = createSelector(
  [getTile, getTurn],
  (tile, turn) => tile.color === turn
);

export const getUsedTiles = createSelector(
  [getTiles],
  (tiles) => {
    let usedTiles = [];
    Object.keys(tiles).forEach((id) => {
      let tile = tiles[id];
      if (typeof tile.x === 'number' && typeof tile.y === 'number') {
        usedTiles.push(tile);
      }
    });
    return usedTiles;
  }
);

export const getUnusedWhiteTiles = getUnusedColorTiles('white');
export const getUnusedBlackTiles = getUnusedColorTiles('black');<commit_msg>Check better conditions during dragging<commit_after>import { createSelector } from 'reselect';

const getTiles = (state) => state.tiles;
const getTile = (state, props) => state.tiles[props.id];
const getTurn = (state) => state.turn;
const getMoveCount = (state) => state.moveCount;
const getDraggedTileId = (state) => state.draggedTileId;
const getX = (state, props) => props.x;
const getY = (state, props) => props.y;

function tileOnBoard(tile) {
  return (typeof tile.x === 'number' && typeof tile.y === 'number');
}

function listAdjancentPositions(x, y) {
  let positions = [
    {x: x + 1, y: y},
    {x: x - 1, y: y},
    {x: x, y: y + 1},
    {x: x, y: y - 1}
  ];

  if (x % 2) {
    positions.push({x: x + 1, y: y + 1});
    positions.push({x: x - 1, y: y + 1});
  } else {
    positions.push({x: x + 1, y: y - 1});
    positions.push({x: x - 1, y: y - 1});
  }
  return positions;
}

export const canDropTile = createSelector(
  [getTiles, getTurn, getMoveCount, getDraggedTileId, getX, getY],
  (tiles, turn, moveCount, draggedTileId, x, y) => {
    const draggedTile = tiles[draggedTileId];
    if (moveCount === 0)
      return true;
    return listAdjancentPositions(x, y).some(pos => {
      return Object.keys(tiles).some(id => {
        let tile = tiles[id];
        if (tile.x === pos.x && tile.y === pos.y) {
          if (!draggedTile) {
            return false;
          }
          if (moveCount === 1) {
            return true;
          }
          if (!tileOnBoard(draggedTile)) {
            return tile.color == turn;
          }
          return true; // Tile movement rules go here
        }
      });
    });
  }
);

export const canDragTile = createSelector(
  [getTile, getTurn],
  (tile, turn) => tile.color === turn
);

export const getUsedTiles = createSelector(
  [getTiles],
  (tiles) => {
    let usedTiles = [];
    Object.keys(tiles).forEach((id) => {
      let tile = tiles[id];
      if (tileOnBoard(tile)) {
        usedTiles.push(tile);
      }
    });
    return usedTiles;
  }
);

const getUnusedColorTiles = (color) => createSelector(
  [getTiles],
  (tiles) => {
    let colorTiles = [];
    Object.keys(tiles).forEach((id) => {
      let tile = tiles[id];
      if (!tileOnBoard(tile)) {
        if (tile.color === color) {
          colorTiles.push(tile);
        }
      }
    });
    return colorTiles;
  }
);

export const getUnusedWhiteTiles = getUnusedColorTiles('white');
export const getUnusedBlackTiles = getUnusedColorTiles('black');
{'fraction_non_alphanumeric': 0.16948051948051948, 'fraction_numerical': 0.006277056277056277, 'mean_word_length': 2.6471981057616416, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '1498771', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1628, 'n_words': 404}