(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o=0;i=i- 2){choosenCells.push(cells[i]);} for(var a=0;a-1)return true;}}} return false;} function randomCell(cells){if(cells.indexOf(4)===-1)return 4;if(cells.length===3){for(var i=0;i<9;i++){if(cells.indexOf(i)>-1)continue;var combination=[cells[0],cells[2],i].join('-');if(winningCombinations.indexOf(combination)>-1){return i;}}} var randomIndex=Math.floor(Math.random()*8);if(cells.indexOf(randomIndex)===-1){return randomIndex;}else{return randomCell(cells);}} function reducer(currenState,action,dispatch,callback){var state=Object.assign({},currenState);switch(action.type){case'PLAYER_CHOOSES_CELL':var cellIsFree=state.cells.indexOf(action.index)===-1;if(cellIsFree&&state.isMyTurn){state.cells.push(action.index);state.isMyTurn=false;setTimeout(function(){dispatch({type:'IS_COMPUTER_TURN'});},1000);} break;case'IS_COMPUTER_TURN':var gameOver=state.cells.length===9;if(gameOver||isTris(state.cells)){callback();}else{state.cells.push(randomCell(state.cells));state.isMyTurn=true;if(isTris(state.cells))callback();} break;} return state;} module.exports=reducer;},{}]},{},[1]);