public boolean canMove(int player, Point position) throws
            IllegalMoveException,
            CorruptedBoardException,
            GameEndedException,
            DrawGameEndedException{
        //previousBoard.print("PRZED RUCHEM (S)");
        //checking if boards are equal
        try{
            areBoardsEqual();                   
        }catch(CorruptedBoardException e){
            throw e;
        }
        
        //checking if there is any empty field
        if(!Gomoku.game.board.any(GomokuBoardState.EMPTY)){
            throw new DrawGameEndedException(position);
        }
        
        // checking if move is not outside the board
        if((position.x >= 0) && (position.x < rules.getSizeRectangle().width) && (position.y >= 0) && (position.y < rules.getSizeRectangle().height)){
            
            //checking if field is empty
            if(Gomoku.game.board.get(position) == GomokuBoardState.EMPTY){
                
                //checking if it is first move
                if(history.empty()){
                    previousBoard.clean();
                }
                
                //state of a field depends on which of players takes turn
                previousBoard.set(position, GomokuBoardState.values()[player]);
                
                history.push((Point) position.clone());
                
                //previousBoard.print("PO RUCHU (S)");
                //checking if one of players won
                ArrayList<Point> tempListOfPoints = puttedMInRow(position, rules.getInRowToWin(), player);
                if(!tempListOfPoints.isEmpty()){
                    throw new GameEndedException(position, tempListOfPoints);
                }
                return true;
            }
        }
        throw new IllegalMoveException(position);
    }