import { combineReducers } from 'redux';

function board(state, action) {
  // initial state
  if (state === undefined) {
    return(
      [
        ['l', 'n', 's', 'g', 'k', 'g', 's', 'n', 'l'],
        ['*', 'b', '*', '*', '*', '*', '*', 'r', '*'],
        ['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'],
        ['*', '*', '*', '*', '*', '*', '*', '*', '*'],
        ['*', '*', '*', '*', '*', '*', '*', '*', '*'],
        ['*', '*', '*', '*', '*', '*', '*', '*', '*'],
        ['P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'],
        ['*', 'B', '*', '*', '*', '*', '*', 'R', '*'],
        ['L', 'N', 'S', 'G', 'K', 'G', 'S', 'N', 'L']
      ]
    );
  }
  return state;
}

function turn(state, action) {
  console.log(state);

  // TODO: fix Object.assign, return
  switch (state) {
  case 'black':
    return 'white';
  case 'white':
    return 'black';
  default:
    return 'black';
  }
}

function isHolded(state, action) {
  console.log(state);

  switch (state) {
  case true:
    // no return new state
  case false:
    return true;
  default:
    return false;
  }
}

const Shogi = combineReducers({
  board,
  turn,
  isHolded
});

export default Shogi;

import { combineReducers } from 'redux';

function board(state, action) {
  // initial state
  if (state === undefined) {
    return(
      [
        ['l', 'n', 's', 'g', 'k', 'g', 's', 'n', 'l'],
        ['*', 'b', '*', '*', '*', '*', '*', 'r', '*'],
        ['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'],
        ['*', '*', '*', '*', '*', '*', '*', '*', '*'],
        ['*', '*', '*', '*', '*', '*', '*', '*', '*'],
        ['*', '*', '*', '*', '*', '*', '*', '*', '*'],
        ['P', 'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'],
        ['*', 'B', '*', '*', '*', '*', '*', 'R', '*'],
        ['L', 'N', 'S', 'G', 'K', 'G', 'S', 'N', 'L']
      ]
    );
  }
  return state;
}

function turn(state, action) {
  console.log(state);

  switch (state) {
  case 'black':
    return 'white';
  case 'white':
    return 'black';
  default:
    return 'black';
  }
}

function isHolded(state, action) {
  console.log(state);

  switch (state) {
  case true:
    // no return new state
  case false:
    return true;
  default:
    return false;
  }
}

const Shogi = combineReducers({
  board,
  turn,
  isHolded
});

export default Shogi;

Remove comment