<commit_before>import Shogi from '../src/shogi';
import * as CONST from '../constants/actionTypes';

const InitialState = {
  board: Shogi.Board,
  isHoldingPiece: undefined,
  blackPieceStand: [],
  whitePieceStand: []
};

const ShogiReducer = (state = InitialState, action) => {
  switch (action.type) {
  case CONST.HOLD_PIECE:
    if (action.piece.type == '*') {
      return state;
    } else {
      let newBoard = state.board.enhanceMovablePoint(action.piece);
      return Object.assign(
        {},
        {
          board: newBoard,
          blackPieceStand: state.blackPieceStand,
          whitePieceStand: state.whitePieceStand,
          isHoldingPiece: action.piece
        }
      );
    }
  case CONST.MOVE_PIECE:
    // if same piece click, release piece.
    if (state.isHoldingPiece) {
      let newBoard = state.board.movePiece(state.isHoldingPiece, action.piece);

      if (newBoard.takedPiece) {
        // TODO: Use constants. Refactor.
        switch (newBoard.takedPiece.team()) {
        case 'white':
          return Object.assign(
            {},
            { board: newBoard, whitePieceStand: state.whitePieceStand },
            {
              isHoldingPiece: undefined,
              blackPieceStand: state.blackPieceStand.concat([newBoard.takedPiece])
            }
          );
        case 'black':
          return Object.assign(
            {},
            { board: newBoard, blackPieceStand: state.blackPieceStand },
            {
              isHoldingPiece: undefined,
              whitePieceStand: state.whitePieceStand.concat([newBoard.takedPiece])
            }
          );
        }
      } else {
        return Object.assign(
          {},<commit_msg>Captured piece ownership is opponent team.<commit_after>import Shogi from '../src/shogi';
import * as CONST from '../constants/actionTypes';

const InitialState = {
  board: Shogi.Board,
  isHoldingPiece: undefined,
  blackPieceStand: [],
  whitePieceStand: []
};

const ShogiReducer = (state = InitialState, action) => {
  switch (action.type) {
  case CONST.HOLD_PIECE:
    if (action.piece.type == '*') {
      return state;
    } else {
      let newBoard = state.board.enhanceMovablePoint(action.piece);
      return Object.assign(
        {},
        {
          board: newBoard,
          blackPieceStand: state.blackPieceStand,
          whitePieceStand: state.whitePieceStand,
          isHoldingPiece: action.piece
        }
      );
    }
  case CONST.MOVE_PIECE:
    // if same piece click, release piece.
    if (state.isHoldingPiece) {
      let newBoard = state.board.movePiece(state.isHoldingPiece, action.piece);

      if (newBoard.takedPiece) {
        const opponentPiece = newBoard.takedPiece.toOpponentPiece();
        // TODO: Use constants. Refactor.
        switch (newBoard.takedPiece.team()) {
        case 'white':
          return Object.assign(
            {},
            { board: newBoard, whitePieceStand: state.whitePieceStand },
            {
              isHoldingPiece: undefined,
              blackPieceStand: state.blackPieceStand.concat([opponentPiece])
            }
          );
        case 'black':
          return Object.assign(
            {},
            { board: newBoard, blackPieceStand: state.blackPieceStand },
            {
              isHoldingPiece: undefined,
              whitePieceStand: state.whitePieceStand.concat([opponentPiece])
            }
          );
        }
      } else {
        return Object.assign(
          {},
{'fraction_non_alphanumeric': 0.10942857142857143, 'fraction_numerical': 0.0, 'mean_word_length': 1.9897523484201538, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1176053', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1031, 'n_words': 194}