<commit_before>import compact from 'lodash/array/compact';
import curry from 'lodash/function/curry';
import flow from 'lodash/function/flow';

import clamp from 'utils/clamp';

import level from 'state/models/level';
import player from 'state/models/player';

import die from 'state/utils/die';

import {
  canBlock,
  canCollect,
  canDestroy,
  canDie,
  canKill,
  canWin
} from 'state/definitions/abilities';

const xOffsets = Object.freeze({
  left:  -1,
  right:  1,
});

const yOffsets = Object.freeze({
  up:   -1,
  down:  1,
});

export const type = 'MOVE';

const { minCol, maxCol, minRow, maxRow } = level;
const clampToWorld = curry((state, col, row) => {
  return [
    clamp(minCol(state), maxCol(state), col),
    clamp(minRow(state), maxRow(state), row)
  ];
});

export function reduce(state, { direction }) {

  const dir = direction;
  const newDir = (dir in xOffsets) ? dir : player.getDirection(state);

  const xOffset = xOffsets[dir] || 0;
  const yOffset = yOffsets[dir] || 0;

  const row = player.getRow(state);
  const col = player.getCol(state);

  const [newCol, newRow] = clampToWorld(
    state,
    col + xOffset,
    row + yOffset
  );

  const entity = level.entityAt(newCol, newRow, state);
  const esOccupado = !!entity;
  const type = esOccupado && entity.get('type');

  const move           = (s) => player.setCoords(newCol, newRow, s);
  const moveBack       = (s) => player.setCoords(col, row, s);
  const orient         = (s) => player.setDirection(newDir, s);
  const win            = (s) => s.set('hasWon', true);
  const removeEntity   = (s) => level.deleteEntityAt(col, row, s);
  const incrementTapes = (s) => s.update('numTapes', (num) => num + 1);
  const addPowerup     = (s) => s.update('powerups', (ps) => ps.push(type));
  const ghostify       = (s) => level.setEntityPropAt(col, row, 'type', 'ghost', s);
  const collect        = (s) => (type === 'tape') ? incrementTapes(s) : addPowerup(s);
  const hurt           = (s) => s.update('health', (h) => h - 1);
  const dieIfUnhealthy = (s) => (s.get('health') <= 0) ? die(s) : s;

  const whenEntity = curry((condition, update, s) => {
    return (esOccupado && condition(s, entity)) ? update(s) : s;
  });

  return flow(
    move,
    orient,
    whenEntity(canWin, win),
    whenEntity(canDestroy, removeEntity),<commit_msg>Remove entity at newCol, newRow on move<commit_after>import compact from 'lodash/array/compact';
import curry from 'lodash/function/curry';
import flow from 'lodash/function/flow';

import clamp from 'utils/clamp';

import level from 'state/models/level';
import player from 'state/models/player';

import die from 'state/utils/die';

import {
  canBlock,
  canCollect,
  canDestroy,
  canDie,
  canKill,
  canWin
} from 'state/definitions/abilities';

const xOffsets = Object.freeze({
  left:  -1,
  right:  1,
});

const yOffsets = Object.freeze({
  up:   -1,
  down:  1,
});

export const type = 'MOVE';

const { minCol, maxCol, minRow, maxRow } = level;
const clampToWorld = curry((state, col, row) => {
  return [
    clamp(minCol(state), maxCol(state), col),
    clamp(minRow(state), maxRow(state), row)
  ];
});

export function reduce(state, { direction }) {

  const dir = direction;
  const newDir = (dir in xOffsets) ? dir : player.getDirection(state);

  const xOffset = xOffsets[dir] || 0;
  const yOffset = yOffsets[dir] || 0;

  const row = player.getRow(state);
  const col = player.getCol(state);

  const [newCol, newRow] = clampToWorld(
    state,
    col + xOffset,
    row + yOffset
  );

  const entity = level.entityAt(newCol, newRow, state);
  const esOccupado = !!entity;
  const type = esOccupado && entity.get('type');

  const move           = (s) => player.setCoords(newCol, newRow, s);
  const moveBack       = (s) => player.setCoords(col, row, s);
  const orient         = (s) => player.setDirection(newDir, s);
  const win            = (s) => s.set('hasWon', true);
  const removeEntity   = (s) => level.deleteEntityAt(newCol, newRow, s);
  const incrementTapes = (s) => s.update('numTapes', (num) => num + 1);
  const addPowerup     = (s) => s.update('powerups', (ps) => ps.push(type));
  const ghostify       = (s) => level.setEntityPropAt(col, row, 'type', 'ghost', s);
  const collect        = (s) => (type === 'tape') ? incrementTapes(s) : addPowerup(s);
  const hurt           = (s) => s.update('health', (h) => h - 1);
  const dieIfUnhealthy = (s) => (s.get('health') <= 0) ? die(s) : s;

  const whenEntity = curry((condition, update, s) => {
    return (esOccupado && condition(s, entity)) ? update(s) : s;
  });

  return flow(
    move,
    orient,
    whenEntity(canWin, win),
    whenEntity(canDestroy, removeEntity),
{'fraction_non_alphanumeric': 0.16389599317988066, 'fraction_numerical': 0.0038363171355498722, 'mean_word_length': 3.45679012345679, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4791750', 'n_tokens_mistral': 1688, 'n_tokens_neox': 1639, 'n_words': 427}